MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / newAPITokenListCmd

Function newAPITokenListCmd

app/cli/cmd/organization_apitoken_list.go:28–88  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

26)
27
28func newAPITokenListCmd() *cobra.Command {
29 var (
30 includeRevoked bool
31 statusFilter string
32 project string
33 scope string
34 )
35
36 var availableScopes = []string{
37 "project",
38 "global",
39 }
40
41 var availableStatusFilters = []string{
42 "active",
43 "revoked",
44 "all",
45 }
46
47 cmd := &cobra.Command{
48 Use: "list",
49 Aliases: []string{"ls"},
50 Short: "List API tokens in this organization",
51 PreRunE: func(_ *cobra.Command, _ []string) error {
52 if scope != "" && !slices.Contains(availableScopes, scope) {
53 return fmt.Errorf("invalid scope %q, please chose one of: %v", scope, availableScopes)
54 }
55
56 if statusFilter != "" && !slices.Contains(availableStatusFilters, statusFilter) {
57 return fmt.Errorf("invalid status %q, please choose one of: %v", statusFilter, availableStatusFilters)
58 }
59
60 return nil
61 },
62 RunE: func(cmd *cobra.Command, args []string) error {
63 // --all is deprecated: map it to --status all
64 if includeRevoked {
65 cmd.PrintErr("Warning: --all is deprecated, use --status all instead\n")
66 if statusFilter == "" {
67 statusFilter = "all"
68 }
69 }
70
71 res, err := action.NewAPITokenList(ActionOpts).Run(context.Background(), statusFilter, project, scope)
72 if err != nil {
73 return fmt.Errorf("listing API tokens: %w", err)
74 }
75
76 return output.EncodeOutput(flagOutputFormat, res, apiTokenListTableOutput)
77 },
78 }
79
80 cmd.Flags().BoolVarP(&includeRevoked, "all", "a", false, "Deprecated: use --status all instead")
81 if err := cmd.Flags().MarkDeprecated("all", "use --status all instead"); err != nil {
82 panic(err)
83 }
84 cmd.Flags().StringVar(&statusFilter, "status", "", fmt.Sprintf("filter by token status, available values: %v", availableStatusFilters))
85 cmd.Flags().StringVarP(&project, "project", "p", "", "filter by project name")

Callers 1

Calls 3

NewAPITokenListFunction · 0.92
EncodeOutputFunction · 0.92
RunMethod · 0.45

Tested by

no test coverage detected