From a28b7e4052aef2b342bac6ddef23fb3cb278aa4e Mon Sep 17 00:00:00 2001 From: Charlie Moog Date: Mon, 2 Nov 2020 20:09:04 -0600 Subject: [PATCH 1/8] Add new tokens command for managing API tokens --- coder-sdk/request.go | 2 +- coder-sdk/tokens.go | 60 ++++++++++++++++++++++ internal/cmd/auth.go | 26 +++++++--- internal/cmd/cmd.go | 1 + internal/cmd/tokens.go | 114 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 195 insertions(+), 8 deletions(-) create mode 100644 coder-sdk/tokens.go create mode 100644 internal/cmd/tokens.go diff --git a/coder-sdk/request.go b/coder-sdk/request.go index 4ae2bdf2..14a59b5e 100644 --- a/coder-sdk/request.go +++ b/coder-sdk/request.go @@ -51,7 +51,7 @@ func (c Client) requestBody(ctx context.Context, method, path string, in, out in // Responses in the 100 are handled by the http lib, in the 200 range, we have a success. // Consider anything at or above 300 to be an error. if resp.StatusCode > 299 { - return fmt.Errorf("unexpected status code: %w", bodyError(resp)) + return fmt.Errorf("unexpected status code %d: %w", resp.StatusCode, bodyError(resp)) } // If we expect a payload, process it as json. diff --git a/coder-sdk/tokens.go b/coder-sdk/tokens.go new file mode 100644 index 00000000..052b6911 --- /dev/null +++ b/coder-sdk/tokens.go @@ -0,0 +1,60 @@ +package coder + +import ( + "context" + "net/http" + "time" +) + +type APIToken struct { + ID string `json:"id"` + Name string `json:"name"` + Application bool `json:"application"` + UserID string `json:"user_id"` + LastUsed time.Time `json:"last_used"` +} + +type CreateAPITokenReq struct { + Name string `json:"name"` +} + +type createAPITokenResp struct { + Key string `json:"key"` +} + +func (c Client) CreateAPIToken(ctx context.Context, userID string, req CreateAPITokenReq) (token string, _ error) { + var resp createAPITokenResp + err := c.requestBody(ctx, http.MethodPost, "/api/api-keys/"+userID, req, &resp) + if err != nil { + return "", err + } + return resp.Key, nil +} + +func (c Client) APITokens(ctx context.Context, userID string) ([]APIToken, error) { + var tokens []APIToken + if err := c.requestBody(ctx, http.MethodGet, "/api/api-keys/"+userID, nil, &tokens); err != nil { + return nil, err + } + return tokens, nil +} + +func (c Client) APITokenByID(ctx context.Context, userID, tokenID string) (*APIToken, error) { + var token APIToken + if err := c.requestBody(ctx, http.MethodGet, "/api/api-keys/"+userID+"/"+tokenID, nil, &token); err != nil { + return nil, err + } + return &token, nil +} + +func (c Client) DeleteAPIToken(ctx context.Context, userID, tokenID string) error { + return c.requestBody(ctx, http.MethodDelete, "/api/api-keys/"+userID+"/"+tokenID, nil, nil) +} + +func (c Client) RegenerateAPIToken(ctx context.Context, userID, tokenID string) (token string, _ error) { + var resp createAPITokenResp + if err := c.requestBody(ctx, http.MethodPost, "/api/api-keys/"+userID+"/"+tokenID+"/regen", nil, &resp); err != nil { + return "", err + } + return resp.Key, nil +} diff --git a/internal/cmd/auth.go b/internal/cmd/auth.go index b517abc6..b4a9b1c8 100644 --- a/internal/cmd/auth.go +++ b/internal/cmd/auth.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" "net/url" + "os" "golang.org/x/xerrors" @@ -19,15 +20,26 @@ var errNeedLogin = clog.Fatal( clog.Hintf(`did you run "coder login [https://coder.domain.com]"?`), ) +const tokenEnv = "CODER_TOKEN" +const urlEnv = "CODER_URL" + func newClient(ctx context.Context) (*coder.Client, error) { - sessionToken, err := config.Session.Read() - if err != nil { - return nil, errNeedLogin - } + var ( + err error + sessionToken = os.Getenv(tokenEnv) + rawURL = os.Getenv(urlEnv) + ) - rawURL, err := config.URL.Read() - if err != nil { - return nil, errNeedLogin + if sessionToken == "" || rawURL == "" { + sessionToken, err = config.Session.Read() + if err != nil { + return nil, errNeedLogin + } + + rawURL, err = config.URL.Read() + if err != nil { + return nil, errNeedLogin + } } u, err := url.Parse(rawURL) diff --git a/internal/cmd/cmd.go b/internal/cmd/cmd.go index c629beb3..462c7c3a 100644 --- a/internal/cmd/cmd.go +++ b/internal/cmd/cmd.go @@ -30,6 +30,7 @@ func Make() *cobra.Command { envsCmd(), syncCmd(), urlCmd(), + tokensCmd(), resourceCmd(), completionCmd(), genDocsCmd(app), diff --git a/internal/cmd/tokens.go b/internal/cmd/tokens.go new file mode 100644 index 00000000..8a349c1e --- /dev/null +++ b/internal/cmd/tokens.go @@ -0,0 +1,114 @@ +package cmd + +import ( + "fmt" + + "cdr.dev/coder-cli/coder-sdk" + "cdr.dev/coder-cli/pkg/tablewriter" + "github.com/spf13/cobra" +) + +func tokensCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "tokens", + Short: "manage Coder API tokens for the active user", + } + cmd.AddCommand( + lsTokensCmd(), + createTokensCmd(), + rmTokenCmd(), + regenTokenCmd(), + ) + return cmd +} + +func lsTokensCmd() *cobra.Command { + return &cobra.Command{ + Use: "ls", + Short: "show the user's active API tokens", + RunE: func(cmd *cobra.Command, args []string) error { + ctx := cmd.Context() + client, err := newClient(ctx) + if err != nil { + return err + } + + tokens, err := client.APITokens(ctx, coder.Me) + if err != nil { + return err + } + + err = tablewriter.WriteTable(len(tokens), func(i int) interface{} { + return tokens[i] + }) + if err != nil { + return err + } + + return nil + }, + } +} + +func createTokensCmd() *cobra.Command { + return &cobra.Command{ + Use: "create [token_name]", + Short: "create generates a new API token and prints it to stdout", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + ctx := cmd.Context() + client, err := newClient(ctx) + if err != nil { + return err + } + token, err := client.CreateAPIToken(ctx, coder.Me, coder.CreateAPITokenReq{ + Name: args[0], + }) + if err != nil { + return err + } + fmt.Println(token) + return nil + }, + } +} + +func rmTokenCmd() *cobra.Command { + return &cobra.Command{ + Use: "rm [token_id]", + Short: "remove an API token by its unique ID", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + ctx := cmd.Context() + client, err := newClient(ctx) + if err != nil { + return err + } + if err = client.DeleteAPIToken(ctx, coder.Me, args[0]); err != nil { + return err + } + return nil + }, + } +} + +func regenTokenCmd() *cobra.Command { + return &cobra.Command{ + Use: "regen [token_id]", + Short: "regenerate an API token by its unique ID and print the new token to stdout", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + ctx := cmd.Context() + client, err := newClient(ctx) + if err != nil { + return err + } + token, err := client.RegenerateAPIToken(ctx, coder.Me, args[0]) + if err != nil { + return nil + } + fmt.Println(token) + return nil + }, + } +} From 933bfd06c8be228c742d21506466b3a0f61f9224 Mon Sep 17 00:00:00 2001 From: Charlie Moog Date: Mon, 2 Nov 2020 20:11:14 -0600 Subject: [PATCH 2/8] fixup! Add new tokens command for managing API tokens --- docs/coder.md | 1 + docs/coder_tokens.md | 24 ++++++++++++++++++++++++ docs/coder_tokens_create.md | 24 ++++++++++++++++++++++++ docs/coder_tokens_ls.md | 24 ++++++++++++++++++++++++ docs/coder_tokens_regen.md | 24 ++++++++++++++++++++++++ docs/coder_tokens_rm.md | 24 ++++++++++++++++++++++++ 6 files changed, 121 insertions(+) create mode 100644 docs/coder_tokens.md create mode 100644 docs/coder_tokens_create.md create mode 100644 docs/coder_tokens_ls.md create mode 100644 docs/coder_tokens_regen.md create mode 100644 docs/coder_tokens_rm.md diff --git a/docs/coder.md b/docs/coder.md index 5a20d80c..fe3c5cfe 100644 --- a/docs/coder.md +++ b/docs/coder.md @@ -19,6 +19,7 @@ coder provides a CLI for working with an existing Coder Enterprise installation * [coder secrets](coder_secrets.md) - Interact with Coder Secrets * [coder sh](coder_sh.md) - Open a shell and execute commands in a Coder environment * [coder sync](coder_sync.md) - Establish a one way directory sync to a Coder environment +* [coder tokens](coder_tokens.md) - manage Coder API tokens for the active user * [coder urls](coder_urls.md) - Interact with environment DevURLs * [coder users](coder_users.md) - Interact with Coder user accounts diff --git a/docs/coder_tokens.md b/docs/coder_tokens.md new file mode 100644 index 00000000..9da30b2a --- /dev/null +++ b/docs/coder_tokens.md @@ -0,0 +1,24 @@ +## coder tokens + +manage Coder API tokens for the active user + +### Options + +``` + -h, --help help for tokens +``` + +### Options inherited from parent commands + +``` + -v, --verbose show verbose output +``` + +### SEE ALSO + +* [coder](coder.md) - coder provides a CLI for working with an existing Coder Enterprise installation +* [coder tokens create](coder_tokens_create.md) - create generates a new API token and prints it to stdout +* [coder tokens ls](coder_tokens_ls.md) - show the user's active API tokens +* [coder tokens regen](coder_tokens_regen.md) - regenerate an API token by its unique ID and print the new token to stdout +* [coder tokens rm](coder_tokens_rm.md) - remove an API token by its unique ID + diff --git a/docs/coder_tokens_create.md b/docs/coder_tokens_create.md new file mode 100644 index 00000000..a7a89f54 --- /dev/null +++ b/docs/coder_tokens_create.md @@ -0,0 +1,24 @@ +## coder tokens create + +create generates a new API token and prints it to stdout + +``` +coder tokens create [token_name] [flags] +``` + +### Options + +``` + -h, --help help for create +``` + +### Options inherited from parent commands + +``` + -v, --verbose show verbose output +``` + +### SEE ALSO + +* [coder tokens](coder_tokens.md) - manage Coder API tokens for the active user + diff --git a/docs/coder_tokens_ls.md b/docs/coder_tokens_ls.md new file mode 100644 index 00000000..0164b852 --- /dev/null +++ b/docs/coder_tokens_ls.md @@ -0,0 +1,24 @@ +## coder tokens ls + +show the user's active API tokens + +``` +coder tokens ls [flags] +``` + +### Options + +``` + -h, --help help for ls +``` + +### Options inherited from parent commands + +``` + -v, --verbose show verbose output +``` + +### SEE ALSO + +* [coder tokens](coder_tokens.md) - manage Coder API tokens for the active user + diff --git a/docs/coder_tokens_regen.md b/docs/coder_tokens_regen.md new file mode 100644 index 00000000..26832102 --- /dev/null +++ b/docs/coder_tokens_regen.md @@ -0,0 +1,24 @@ +## coder tokens regen + +regenerate an API token by its unique ID and print the new token to stdout + +``` +coder tokens regen [token_id] [flags] +``` + +### Options + +``` + -h, --help help for regen +``` + +### Options inherited from parent commands + +``` + -v, --verbose show verbose output +``` + +### SEE ALSO + +* [coder tokens](coder_tokens.md) - manage Coder API tokens for the active user + diff --git a/docs/coder_tokens_rm.md b/docs/coder_tokens_rm.md new file mode 100644 index 00000000..ca95ee0e --- /dev/null +++ b/docs/coder_tokens_rm.md @@ -0,0 +1,24 @@ +## coder tokens rm + +remove an API token by its unique ID + +``` +coder tokens rm [token_id] [flags] +``` + +### Options + +``` + -h, --help help for rm +``` + +### Options inherited from parent commands + +``` + -v, --verbose show verbose output +``` + +### SEE ALSO + +* [coder tokens](coder_tokens.md) - manage Coder API tokens for the active user + From 9f4e472fdd9d4ce4d300835560e035d56372aade Mon Sep 17 00:00:00 2001 From: Charlie Moog Date: Mon, 2 Nov 2020 22:46:08 -0600 Subject: [PATCH 3/8] fixup! Add new tokens command for managing API tokens --- docs/coder_tokens.md | 5 +++++ internal/cmd/cmd.go | 4 ++-- internal/cmd/tokens.go | 16 ++++++++-------- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/docs/coder_tokens.md b/docs/coder_tokens.md index 9da30b2a..9f347277 100644 --- a/docs/coder_tokens.md +++ b/docs/coder_tokens.md @@ -2,6 +2,11 @@ manage Coder API tokens for the active user +### Synopsis + +Create and manage API Tokens for authenticating the CLI. +Statically authenticate using the token value with the `CODER_TOKEN` and `CODER_URL` environment variables. + ### Options ``` diff --git a/internal/cmd/cmd.go b/internal/cmd/cmd.go index 462c7c3a..e2f92fdb 100644 --- a/internal/cmd/cmd.go +++ b/internal/cmd/cmd.go @@ -13,8 +13,8 @@ var verbose bool = false // Make constructs the "coder" root command func Make() *cobra.Command { app := &cobra.Command{ - Use: "coder", - Short: "coder provides a CLI for working with an existing Coder Enterprise installation", + Use: "coder", + Short: "coder provides a CLI for working with an existing Coder Enterprise installation", SilenceErrors: true, SilenceUsage: true, DisableAutoGenTag: true, diff --git a/internal/cmd/tokens.go b/internal/cmd/tokens.go index 8a349c1e..3b677359 100644 --- a/internal/cmd/tokens.go +++ b/internal/cmd/tokens.go @@ -10,8 +10,10 @@ import ( func tokensCmd() *cobra.Command { cmd := &cobra.Command{ - Use: "tokens", + Use: "tokens", Short: "manage Coder API tokens for the active user", + Long: "Create and manage API Tokens for authenticating the CLI.\n" + + "Statically authenticate using the token value with the " + "`" + "CODER_TOKEN" + "`" + " and " + "`" + "CODER_URL" + "`" + " environment variables.", } cmd.AddCommand( lsTokensCmd(), @@ -38,9 +40,7 @@ func lsTokensCmd() *cobra.Command { return err } - err = tablewriter.WriteTable(len(tokens), func(i int) interface{} { - return tokens[i] - }) + err = tablewriter.WriteTable(len(tokens), func(i int) interface{} { return tokens[i] }) if err != nil { return err } @@ -75,9 +75,9 @@ func createTokensCmd() *cobra.Command { func rmTokenCmd() *cobra.Command { return &cobra.Command{ - Use: "rm [token_id]", + Use: "rm [token_id]", Short: "remove an API token by its unique ID", - Args: cobra.ExactArgs(1), + Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { ctx := cmd.Context() client, err := newClient(ctx) @@ -94,9 +94,9 @@ func rmTokenCmd() *cobra.Command { func regenTokenCmd() *cobra.Command { return &cobra.Command{ - Use: "regen [token_id]", + Use: "regen [token_id]", Short: "regenerate an API token by its unique ID and print the new token to stdout", - Args: cobra.ExactArgs(1), + Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { ctx := cmd.Context() client, err := newClient(ctx) From e98dfae1e42a5a9594e63828fed450c8fe4b8a1b Mon Sep 17 00:00:00 2001 From: Charlie Moog Date: Mon, 2 Nov 2020 22:47:29 -0600 Subject: [PATCH 4/8] fixup! Add new tokens command for managing API tokens --- internal/cmd/cmd.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/cmd/cmd.go b/internal/cmd/cmd.go index e2f92fdb..462c7c3a 100644 --- a/internal/cmd/cmd.go +++ b/internal/cmd/cmd.go @@ -13,8 +13,8 @@ var verbose bool = false // Make constructs the "coder" root command func Make() *cobra.Command { app := &cobra.Command{ - Use: "coder", - Short: "coder provides a CLI for working with an existing Coder Enterprise installation", + Use: "coder", + Short: "coder provides a CLI for working with an existing Coder Enterprise installation", SilenceErrors: true, SilenceUsage: true, DisableAutoGenTag: true, From 7bf7d014ae4d3a81b19e00b46c86e8c549b6e163 Mon Sep 17 00:00:00 2001 From: Charlie Moog Date: Mon, 2 Nov 2020 22:47:42 -0600 Subject: [PATCH 5/8] fixup! Add new tokens command for managing API tokens --- coder-sdk/tokens.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coder-sdk/tokens.go b/coder-sdk/tokens.go index 052b6911..946979c0 100644 --- a/coder-sdk/tokens.go +++ b/coder-sdk/tokens.go @@ -24,7 +24,7 @@ type createAPITokenResp struct { func (c Client) CreateAPIToken(ctx context.Context, userID string, req CreateAPITokenReq) (token string, _ error) { var resp createAPITokenResp - err := c.requestBody(ctx, http.MethodPost, "/api/api-keys/"+userID, req, &resp) + err := c.requestBody(ctx, http.MethodPost, "/api/api-keys/"+userID, req, &resp) if err != nil { return "", err } From 6a8c9f20a09704618f941fe241cf00018fb1088e Mon Sep 17 00:00:00 2001 From: Charlie Moog Date: Mon, 2 Nov 2020 23:07:26 -0600 Subject: [PATCH 6/8] Add integration test for CODER_TOKEN static auth --- ci/integration/statictokens_test.go | 42 +++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 ci/integration/statictokens_test.go diff --git a/ci/integration/statictokens_test.go b/ci/integration/statictokens_test.go new file mode 100644 index 00000000..ddee8831 --- /dev/null +++ b/ci/integration/statictokens_test.go @@ -0,0 +1,42 @@ +package integration + +import ( + "context" + "fmt" + "os" + "os/exec" + "strings" + "testing" + + "cdr.dev/coder-cli/pkg/tcli" +) + +func TestStaticAuth(t *testing.T) { + t.Parallel() + run(t, "static-auth-test", func(t *testing.T, ctx context.Context, c *tcli.ContainerRunner) { + headlessLogin(ctx, t, c) + + c.Run(ctx, "coder tokens ls").Assert(t, + tcli.Success(), + ) + + var result *tcli.CommandResult + tokenName := randString(5) + c.Run(ctx, "coder tokens create "+tokenName).Assert(t, + tcli.Success(), + tcli.GetResult(&result), + ) + + c.Run(ctx, "rm -rf ~/.config/coder") + + cmd := exec.CommandContext(ctx, "sh", "-c", fmt.Sprintf("export CODER_URL=%s && export CODER_TOKEN=$(cat) && coder envs ls", os.Getenv("CODER_URL"))) + cmd.Stdin = strings.NewReader(string(result.Stdout)) + c.RunCmd(cmd).Assert(t, + tcli.Success(), + ) + + c.Run(ctx, "coder envs ls").Assert(t, + tcli.Success(), + ) + }) +} From ccf38931906702168775b9bfc6319e32c991e96e Mon Sep 17 00:00:00 2001 From: Charlie Moog Date: Tue, 3 Nov 2020 09:45:34 -0600 Subject: [PATCH 7/8] fixup! Add integration test for CODER_TOKEN static auth --- ci/integration/statictokens_test.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/ci/integration/statictokens_test.go b/ci/integration/statictokens_test.go index ddee8831..5a181ece 100644 --- a/ci/integration/statictokens_test.go +++ b/ci/integration/statictokens_test.go @@ -27,16 +27,23 @@ func TestStaticAuth(t *testing.T) { tcli.GetResult(&result), ) - c.Run(ctx, "rm -rf ~/.config/coder") + // remove loging credentials + c.Run(ctx, "rm -rf ~/.config/coder").Assert(t, + tcli.Success(), + ) - cmd := exec.CommandContext(ctx, "sh", "-c", fmt.Sprintf("export CODER_URL=%s && export CODER_TOKEN=$(cat) && coder envs ls", os.Getenv("CODER_URL"))) + // make requests with token environment variable authentication + cmd := exec.CommandContext(ctx, "sh", "-c", + fmt.Sprintf("export CODER_URL=%s && export CODER_TOKEN=$(cat) && coder envs ls", os.Getenv("CODER_URL")), + ) cmd.Stdin = strings.NewReader(string(result.Stdout)) c.RunCmd(cmd).Assert(t, tcli.Success(), ) + // should error when the environment variabels aren't set c.Run(ctx, "coder envs ls").Assert(t, - tcli.Success(), + tcli.Error(), ) }) } From 3b1f2f809d31d89f4acaccd6284bb500bdb82a04 Mon Sep 17 00:00:00 2001 From: Charlie Moog Date: Tue, 3 Nov 2020 11:06:43 -0600 Subject: [PATCH 8/8] fixup! Add integration test for CODER_TOKEN static auth --- ci/integration/statictokens_test.go | 1 + docs/coder.md | 1 - docs/coder_tokens.md | 29 ----------------------------- docs/coder_tokens_create.md | 24 ------------------------ docs/coder_tokens_ls.md | 24 ------------------------ docs/coder_tokens_regen.md | 24 ------------------------ docs/coder_tokens_rm.md | 24 ------------------------ internal/cmd/tokens.go | 5 +++-- 8 files changed, 4 insertions(+), 128 deletions(-) delete mode 100644 docs/coder_tokens.md delete mode 100644 docs/coder_tokens_create.md delete mode 100644 docs/coder_tokens_ls.md delete mode 100644 docs/coder_tokens_regen.md delete mode 100644 docs/coder_tokens_rm.md diff --git a/ci/integration/statictokens_test.go b/ci/integration/statictokens_test.go index 5a181ece..d38dcd99 100644 --- a/ci/integration/statictokens_test.go +++ b/ci/integration/statictokens_test.go @@ -13,6 +13,7 @@ import ( func TestStaticAuth(t *testing.T) { t.Parallel() + t.Skip() run(t, "static-auth-test", func(t *testing.T, ctx context.Context, c *tcli.ContainerRunner) { headlessLogin(ctx, t, c) diff --git a/docs/coder.md b/docs/coder.md index fe3c5cfe..5a20d80c 100644 --- a/docs/coder.md +++ b/docs/coder.md @@ -19,7 +19,6 @@ coder provides a CLI for working with an existing Coder Enterprise installation * [coder secrets](coder_secrets.md) - Interact with Coder Secrets * [coder sh](coder_sh.md) - Open a shell and execute commands in a Coder environment * [coder sync](coder_sync.md) - Establish a one way directory sync to a Coder environment -* [coder tokens](coder_tokens.md) - manage Coder API tokens for the active user * [coder urls](coder_urls.md) - Interact with environment DevURLs * [coder users](coder_users.md) - Interact with Coder user accounts diff --git a/docs/coder_tokens.md b/docs/coder_tokens.md deleted file mode 100644 index 9f347277..00000000 --- a/docs/coder_tokens.md +++ /dev/null @@ -1,29 +0,0 @@ -## coder tokens - -manage Coder API tokens for the active user - -### Synopsis - -Create and manage API Tokens for authenticating the CLI. -Statically authenticate using the token value with the `CODER_TOKEN` and `CODER_URL` environment variables. - -### Options - -``` - -h, --help help for tokens -``` - -### Options inherited from parent commands - -``` - -v, --verbose show verbose output -``` - -### SEE ALSO - -* [coder](coder.md) - coder provides a CLI for working with an existing Coder Enterprise installation -* [coder tokens create](coder_tokens_create.md) - create generates a new API token and prints it to stdout -* [coder tokens ls](coder_tokens_ls.md) - show the user's active API tokens -* [coder tokens regen](coder_tokens_regen.md) - regenerate an API token by its unique ID and print the new token to stdout -* [coder tokens rm](coder_tokens_rm.md) - remove an API token by its unique ID - diff --git a/docs/coder_tokens_create.md b/docs/coder_tokens_create.md deleted file mode 100644 index a7a89f54..00000000 --- a/docs/coder_tokens_create.md +++ /dev/null @@ -1,24 +0,0 @@ -## coder tokens create - -create generates a new API token and prints it to stdout - -``` -coder tokens create [token_name] [flags] -``` - -### Options - -``` - -h, --help help for create -``` - -### Options inherited from parent commands - -``` - -v, --verbose show verbose output -``` - -### SEE ALSO - -* [coder tokens](coder_tokens.md) - manage Coder API tokens for the active user - diff --git a/docs/coder_tokens_ls.md b/docs/coder_tokens_ls.md deleted file mode 100644 index 0164b852..00000000 --- a/docs/coder_tokens_ls.md +++ /dev/null @@ -1,24 +0,0 @@ -## coder tokens ls - -show the user's active API tokens - -``` -coder tokens ls [flags] -``` - -### Options - -``` - -h, --help help for ls -``` - -### Options inherited from parent commands - -``` - -v, --verbose show verbose output -``` - -### SEE ALSO - -* [coder tokens](coder_tokens.md) - manage Coder API tokens for the active user - diff --git a/docs/coder_tokens_regen.md b/docs/coder_tokens_regen.md deleted file mode 100644 index 26832102..00000000 --- a/docs/coder_tokens_regen.md +++ /dev/null @@ -1,24 +0,0 @@ -## coder tokens regen - -regenerate an API token by its unique ID and print the new token to stdout - -``` -coder tokens regen [token_id] [flags] -``` - -### Options - -``` - -h, --help help for regen -``` - -### Options inherited from parent commands - -``` - -v, --verbose show verbose output -``` - -### SEE ALSO - -* [coder tokens](coder_tokens.md) - manage Coder API tokens for the active user - diff --git a/docs/coder_tokens_rm.md b/docs/coder_tokens_rm.md deleted file mode 100644 index ca95ee0e..00000000 --- a/docs/coder_tokens_rm.md +++ /dev/null @@ -1,24 +0,0 @@ -## coder tokens rm - -remove an API token by its unique ID - -``` -coder tokens rm [token_id] [flags] -``` - -### Options - -``` - -h, --help help for rm -``` - -### Options inherited from parent commands - -``` - -v, --verbose show verbose output -``` - -### SEE ALSO - -* [coder tokens](coder_tokens.md) - manage Coder API tokens for the active user - diff --git a/internal/cmd/tokens.go b/internal/cmd/tokens.go index 3b677359..36709d75 100644 --- a/internal/cmd/tokens.go +++ b/internal/cmd/tokens.go @@ -10,8 +10,9 @@ import ( func tokensCmd() *cobra.Command { cmd := &cobra.Command{ - Use: "tokens", - Short: "manage Coder API tokens for the active user", + Use: "tokens", + Short: "manage Coder API tokens for the active user", + Hidden: true, Long: "Create and manage API Tokens for authenticating the CLI.\n" + "Statically authenticate using the token value with the " + "`" + "CODER_TOKEN" + "`" + " and " + "`" + "CODER_URL" + "`" + " environment variables.", }