Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add role update functionality to acl token update #18532

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/18532.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
cli: Added support for updating the roles for an ACL token
```
38 changes: 33 additions & 5 deletions command/acl_token_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import (

type ACLTokenUpdateCommand struct {
Meta

roleNames []string
roleIDs []string
}

func (c *ACLTokenUpdateCommand) Help() string {
Expand All @@ -33,8 +36,19 @@ Update Options:
Sets the type of token. Must be one of "client" or "management".

-policy=""
Specifies a policy to associate with the token. Can be specified multiple times,
but only with client type tokens.
Specifies a policy to associate with the token. Can be specified multiple
times, but only with client type tokens. If any policies are specified, they
completely replace the policies on the existing token.

-role-id=""
ID of a role to use for this token. Can be specified multiple times, but
only with client type tokens. If any roles are specified, they completely
replace the roles on the existing token.

-role-name=""
Name of a role to use for this token. Can be specified multiple times, but
only with client type tokens. If any roles are specified, they completely
replace the roles on the existing token.
`

return strings.TrimSpace(helpText)
Expand All @@ -43,9 +57,11 @@ Update Options:
func (c *ACLTokenUpdateCommand) AutocompleteFlags() complete.Flags {
return mergeAutocompleteFlags(c.Meta.AutocompleteFlags(FlagSetClient),
complete.Flags{
"name": complete.PredictAnything,
"type": complete.PredictAnything,
"policy": complete.PredictAnything,
"name": complete.PredictAnything,
"type": complete.PredictAnything,
"policy": complete.PredictAnything,
"role-id": complete.PredictAnything,
"role-name": complete.PredictAnything,
})
}

Expand All @@ -70,6 +86,14 @@ func (c *ACLTokenUpdateCommand) Run(args []string) int {
policies = append(policies, s)
return nil
}), "policy", "")
flags.Var((funcVar)(func(s string) error {
c.roleNames = append(c.roleNames, s)
return nil
}), "role-name", "")
flags.Var((funcVar)(func(s string) error {
c.roleIDs = append(c.roleIDs, s)
return nil
}), "role-id", "")
if err := flags.Parse(args); err != nil {
return 1
}
Expand Down Expand Up @@ -111,6 +135,10 @@ func (c *ACLTokenUpdateCommand) Run(args []string) int {
token.Policies = policies
}

if len(c.roleNames) != 0 || len(c.roleIDs) != 0 {
token.Roles = generateACLTokenRoleLinks(c.roleNames, c.roleIDs)
}
tgross marked this conversation as resolved.
Show resolved Hide resolved

// Update the token
updatedToken, _, err := client.ACLTokens().Update(token, nil)
if err != nil {
Expand Down
11 changes: 10 additions & 1 deletion website/content/docs/commands/acl/token/update.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,16 @@ The `acl token update` command requires an existing token's accessor ID.
- `-type`: Sets the type of token. Must be one of "client" or "management".

- `-policy`: Specifies a policy to associate with the token. Can be specified
multiple times, but only with client type tokens.
multiple times, but only with client type tokens. If any policies are
specified, they completely replace the policies on the existing token.

- `-role-id`: ID of a role to use for this token. Can be specified multiple
times, but only with client type tokens. If any roles are specified, they
completely replace the roles on the existing token.

- `-role-name`: Name of a role to use for this token. Can be specified multiple
times, but only with client type tokens. If any roles are specified, they
completely replace the roles on the existing token.

## Examples

Expand Down