cli: show Owner column in preauthkeys list

Replace the Tags column with an Owner column that displays:
- Tags (newline-separated) if the key has ACL tags
- User name if the key is associated with a user
- Dash (-) if neither is present

This aligns the CLI output with the tags-as-identity model where
preauthkeys can be created with either tags or user ownership.
This commit is contained in:
Kristoffer Dalby 2026-01-20 09:42:23 +00:00
parent b8f3e09046
commit 951fd5a8e7

View file

@ -78,7 +78,7 @@ var listPreAuthKeys = &cobra.Command{
"Used", "Used",
"Expiration", "Expiration",
"Created", "Created",
"Tags", "Owner",
}, },
} }
for _, key := range response.GetPreAuthKeys() { for _, key := range response.GetPreAuthKeys() {
@ -87,14 +87,15 @@ var listPreAuthKeys = &cobra.Command{
expiration = ColourTime(key.GetExpiration().AsTime()) expiration = ColourTime(key.GetExpiration().AsTime())
} }
aclTags := "" var owner string
if len(key.GetAclTags()) > 0 {
for _, tag := range key.GetAclTags() { owner = strings.Join(key.GetAclTags(), "\n")
aclTags += "\n" + tag } else if key.GetUser() != nil {
owner = key.GetUser().GetName()
} else {
owner = "-"
} }
aclTags = strings.TrimLeft(aclTags, "\n")
tableData = append(tableData, []string{ tableData = append(tableData, []string{
strconv.FormatUint(key.GetId(), 10), strconv.FormatUint(key.GetId(), 10),
key.GetKey(), key.GetKey(),
@ -103,7 +104,7 @@ var listPreAuthKeys = &cobra.Command{
strconv.FormatBool(key.GetUsed()), strconv.FormatBool(key.GetUsed()),
expiration, expiration,
key.GetCreatedAt().AsTime().Format("2006-01-02 15:04:05"), key.GetCreatedAt().AsTime().Format("2006-01-02 15:04:05"),
aclTags, owner,
}) })
} }