mirror of
https://github.com/argoproj/argo-cd
synced 2026-04-21 17:07:16 +00:00
feat: Add 'proj role list-tokens' command (#4674)
Signed-off-by: Tim Etchells <tetchell@redhat.com>
This commit is contained in:
parent
6ddd98c4f8
commit
764ea07fc0
4 changed files with 109 additions and 4 deletions
7
.gitignore
vendored
7
.gitignore
vendored
|
|
@ -13,3 +13,10 @@ test-results
|
|||
.scannerwork
|
||||
.scratch
|
||||
node_modules/
|
||||
|
||||
# ignore built binaries
|
||||
cmd/argocd/argocd
|
||||
cmd/argocd-application-controller/argocd-application-controller
|
||||
cmd/argocd-repo-server/argocd-repo-server
|
||||
cmd/argocd-server/argocd-server
|
||||
cmd/argocd-util/argocd-util
|
||||
|
|
@ -38,6 +38,7 @@ func NewProjectRoleCommand(clientOpts *argocdclient.ClientOptions) *cobra.Comman
|
|||
roleCommand.AddCommand(NewProjectRoleCreateCommand(clientOpts))
|
||||
roleCommand.AddCommand(NewProjectRoleDeleteCommand(clientOpts))
|
||||
roleCommand.AddCommand(NewProjectRoleCreateTokenCommand(clientOpts))
|
||||
roleCommand.AddCommand(NewProjectRoleListTokensCommand(clientOpts))
|
||||
roleCommand.AddCommand(NewProjectRoleDeleteTokenCommand(clientOpts))
|
||||
roleCommand.AddCommand(NewProjectRoleAddPolicyCommand(clientOpts))
|
||||
roleCommand.AddCommand(NewProjectRoleRemovePolicyCommand(clientOpts))
|
||||
|
|
@ -213,8 +214,9 @@ func NewProjectRoleCreateTokenCommand(clientOpts *argocdclient.ClientOptions) *c
|
|||
tokenID string
|
||||
)
|
||||
var command = &cobra.Command{
|
||||
Use: "create-token PROJECT ROLE-NAME",
|
||||
Short: "Create a project token",
|
||||
Use: "create-token PROJECT ROLE-NAME",
|
||||
Short: "Create a project token",
|
||||
Aliases: []string{"token-create"},
|
||||
Run: func(c *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
c.HelpFunc()(c, args)
|
||||
|
|
@ -273,11 +275,63 @@ func NewProjectRoleCreateTokenCommand(clientOpts *argocdclient.ClientOptions) *c
|
|||
return command
|
||||
}
|
||||
|
||||
func NewProjectRoleListTokensCommand(clientOpts *argocdclient.ClientOptions) *cobra.Command {
|
||||
var (
|
||||
useUnixTime bool
|
||||
)
|
||||
var command = &cobra.Command{
|
||||
Use: "list-tokens PROJECT ROLE-NAME",
|
||||
Short: "List tokens for a given role.",
|
||||
Aliases: []string{"list-token", "token-list"},
|
||||
Run: func(c *cobra.Command, args []string) {
|
||||
if len(args) != 2 {
|
||||
c.HelpFunc()(c, args)
|
||||
os.Exit(1)
|
||||
}
|
||||
projName := args[0]
|
||||
roleName := args[1]
|
||||
|
||||
conn, projIf := argocdclient.NewClientOrDie(clientOpts).NewProjectClientOrDie()
|
||||
defer io.Close(conn)
|
||||
|
||||
proj, err := projIf.Get(context.Background(), &projectpkg.ProjectQuery{Name: projName})
|
||||
errors.CheckError(err)
|
||||
role, _, err := proj.GetRoleByName(roleName)
|
||||
errors.CheckError(err)
|
||||
|
||||
if len(role.JWTTokens) == 0 {
|
||||
fmt.Printf("No tokens for %s.%s\n", projName, roleName)
|
||||
return
|
||||
}
|
||||
|
||||
writer := tabwriter.NewWriter(os.Stdout, 0, 0, 4, ' ', 0)
|
||||
_, err = fmt.Fprintf(writer, "ID\tISSUED AT\tEXPIRES AT\n")
|
||||
errors.CheckError(err)
|
||||
|
||||
tokenRowFormat := "%s\t%v\t%v\n"
|
||||
for _, token := range role.JWTTokens {
|
||||
if useUnixTime {
|
||||
_, _ = fmt.Fprintf(writer, tokenRowFormat, token.ID, token.IssuedAt, token.ExpiresAt)
|
||||
} else {
|
||||
_, _ = fmt.Fprintf(writer, tokenRowFormat, token.ID, tokenTimeToString(token.IssuedAt), tokenTimeToString(token.ExpiresAt))
|
||||
}
|
||||
}
|
||||
err = writer.Flush()
|
||||
errors.CheckError(err)
|
||||
},
|
||||
}
|
||||
command.Flags().BoolVarP(&useUnixTime, "unixtime", "u", false,
|
||||
"Print timestamps as Unix time instead of converting. Useful for piping into delete-token.",
|
||||
)
|
||||
return command
|
||||
}
|
||||
|
||||
// NewProjectRoleDeleteTokenCommand returns a new instance of an `argocd proj role delete-token` command
|
||||
func NewProjectRoleDeleteTokenCommand(clientOpts *argocdclient.ClientOptions) *cobra.Command {
|
||||
var command = &cobra.Command{
|
||||
Use: "delete-token PROJECT ROLE-NAME ISSUED-AT",
|
||||
Short: "Delete a project token",
|
||||
Use: "delete-token PROJECT ROLE-NAME ISSUED-AT",
|
||||
Short: "Delete a project token",
|
||||
Aliases: []string{"token-delete", "remove-token"},
|
||||
Run: func(c *cobra.Command, args []string) {
|
||||
if len(args) != 3 {
|
||||
c.HelpFunc()(c, args)
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ argocd proj role [flags]
|
|||
* [argocd proj role delete-token](argocd_proj_role_delete-token.md) - Delete a project token
|
||||
* [argocd proj role get](argocd_proj_role_get.md) - Get the details of a specific role
|
||||
* [argocd proj role list](argocd_proj_role_list.md) - List all the roles in a project
|
||||
* [argocd proj role list-tokens](argocd_proj_role_list-tokens.md) - List tokens for a given role.
|
||||
* [argocd proj role remove-group](argocd_proj_role_remove-group.md) - Remove a group claim from a role within a project
|
||||
* [argocd proj role remove-policy](argocd_proj_role_remove-policy.md) - Remove a policy from a role within a project
|
||||
|
||||
|
|
|
|||
43
docs/user-guide/commands/argocd_proj_role_list-tokens.md
Normal file
43
docs/user-guide/commands/argocd_proj_role_list-tokens.md
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
## argocd proj role list-tokens
|
||||
|
||||
List tokens for a given role.
|
||||
|
||||
### Synopsis
|
||||
|
||||
List tokens for a given role.
|
||||
|
||||
```
|
||||
argocd proj role list-tokens PROJECT ROLE-NAME [flags]
|
||||
```
|
||||
|
||||
### Options
|
||||
|
||||
```
|
||||
-h, --help help for list-tokens
|
||||
-u, --unixtime Print timestamps as Unix time instead of converting. Useful for piping into delete-token.
|
||||
```
|
||||
|
||||
### Options inherited from parent commands
|
||||
|
||||
```
|
||||
--auth-token string Authentication token
|
||||
--client-crt string Client certificate file
|
||||
--client-crt-key string Client certificate key file
|
||||
--config string Path to Argo CD config (default "/home/user/.argocd/config")
|
||||
--grpc-web Enables gRPC-web protocol. Useful if Argo CD server is behind proxy which does not support HTTP2.
|
||||
--grpc-web-root-path string Enables gRPC-web protocol. Useful if Argo CD server is behind proxy which does not support HTTP2. Set web root.
|
||||
-H, --header strings Sets additional header to all requests made by Argo CD CLI. (Can be repeated multiple times to add multiple headers, also supports comma separated headers)
|
||||
--insecure Skip server certificate and domain verification
|
||||
--logformat string Set the logging format. One of: text|json (default "text")
|
||||
--loglevel string Set the logging level. One of: debug|info|warn|error (default "info")
|
||||
--plaintext Disable TLS
|
||||
--port-forward Connect to a random argocd-server port using port forwarding
|
||||
--port-forward-namespace string Namespace name which should be used for port forwarding
|
||||
--server string Argo CD server address
|
||||
--server-crt string Server certificate file
|
||||
```
|
||||
|
||||
### SEE ALSO
|
||||
|
||||
* [argocd proj role](argocd_proj_role.md) - Manage a project's roles
|
||||
|
||||
Loading…
Reference in a new issue