cli: Show node identities in acl token list output (#11926)

Fix the pretty CLI output of `consul acl token list` so that it
properly displays node identities that are associated with a token.
This commit is contained in:
Blake Covarrubias 2022-01-04 12:44:43 -08:00 committed by GitHub
parent 696ba5725f
commit 4a36e4ee24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 20 additions and 19 deletions

3
.changelog/11926.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:bug
cli: Display assigned node identities in output of `consul acl token list`.
```

View File

@ -173,13 +173,9 @@ func (f *prettyFormatter) formatTokenListEntry(token *api.ACLTokenListEntry) str
} }
} }
if len(token.NodeIdentities) > 0 { if len(token.NodeIdentities) > 0 {
buffer.WriteString(fmt.Sprintln("Service Identities:")) buffer.WriteString(fmt.Sprintln("Node Identities:"))
for _, svcid := range token.ServiceIdentities { for _, nodeid := range token.NodeIdentities {
if len(svcid.Datacenters) > 0 { buffer.WriteString(fmt.Sprintf(" %s (Datacenter: %s)\n", nodeid.NodeName, nodeid.Datacenter))
buffer.WriteString(fmt.Sprintf(" %s (Datacenters: %s)\n", svcid.ServiceName, strings.Join(svcid.Datacenters, ", ")))
} else {
buffer.WriteString(fmt.Sprintf(" %s (Datacenters: all)\n", svcid.ServiceName))
}
} }
} }
return buffer.String() return buffer.String()

View File

@ -18,5 +18,5 @@ Roles:
6c9d1e1d-34bc-4d55-80f3-add0890ad791 - west-farthing 6c9d1e1d-34bc-4d55-80f3-add0890ad791 - west-farthing
Service Identities: Service Identities:
gardener (Datacenters: middleearth-northwest) gardener (Datacenters: middleearth-northwest)
Service Identities: Node Identities:
gardener (Datacenters: middleearth-northwest) bagend (Datacenter: middleearth-northwest)

View File

@ -15,5 +15,5 @@ Roles:
6c9d1e1d-34bc-4d55-80f3-add0890ad791 - west-farthing 6c9d1e1d-34bc-4d55-80f3-add0890ad791 - west-farthing
Service Identities: Service Identities:
gardener (Datacenters: middleearth-northwest) gardener (Datacenters: middleearth-northwest)
Service Identities: Node Identities:
gardener (Datacenters: middleearth-northwest) bagend (Datacenter: middleearth-northwest)

View File

@ -46,14 +46,6 @@ Legacy: false
Policies: Policies:
00000000-0000-0000-0000-000000000001 - global-management 00000000-0000-0000-0000-000000000001 - global-management
AccessorID: 59f86a9b-d3b6-166c-32a0-be4ab3f94caa
Description: Super User
Local: false
Create Time: 2018-10-22 15:35:28.787003 -0400 EDT
Legacy: false
Policies:
00000000-0000-0000-0000-000000000001 - global-management
AccessorID: 00000000-0000-0000-0000-000000000002 AccessorID: 00000000-0000-0000-0000-000000000002
Description: Anonymous Token Description: Anonymous Token
Local: false Local: false
@ -69,4 +61,14 @@ Create Time: 2018-10-22 15:33:39.01789 -0400 EDT
Legacy: false Legacy: false
Policies: Policies:
06acc965-df4b-5a99-58cb-3250930c6324 - node-services-read 06acc965-df4b-5a99-58cb-3250930c6324 - node-services-read
Service Identities:
wonderservice (Datacenters: all)
AccessorID: def4895d-eeb9-f78a-fbb9-2a15a568af31
Description: Node 1 agent token
Local: false
Create Time: 2020-12-22 04:19:30.552528733 +0000 UTC
Legacy: false
Node Identities:
node1 (Datacenter: dc1)
``` ```