mirror of
https://github.com/coder/coder.git
synced 2026-09-22 05:05:20 +08:00
feat: add scoped token support to CLI (#19985)
<!-- If you have used AI to produce some or all of this PR, please ensure you have read our [AI Contribution guidelines](https://coder.com/docs/about/contributing/AI_CONTRIBUTING) before submitting. --> Add support for scoped API tokens in CLI This PR adds CLI support for creating and viewing API tokens with scopes and allow lists. It includes: - New `--scope` and `--allow` flags for the `tokens create` command - A new `tokens view` command to display detailed information about a token - Updated table columns in `tokens list` to show scopes and allow list entries - Updated help text and examples These changes enable users to create tokens with limited permissions through the CLI, similar to the existing functionality in the web UI.
This commit is contained in:
@@ -1798,6 +1798,11 @@
|
||||
"description": "Delete a token",
|
||||
"path": "reference/cli/tokens_remove.md"
|
||||
},
|
||||
{
|
||||
"title": "tokens view",
|
||||
"description": "Display detailed information about a token",
|
||||
"path": "reference/cli/tokens_view.md"
|
||||
},
|
||||
{
|
||||
"title": "unfavorite",
|
||||
"description": "Remove a workspace from your favorites",
|
||||
|
||||
Generated
+10
-5
@@ -25,6 +25,10 @@ Tokens are used to authenticate automated clients to Coder.
|
||||
|
||||
$ coder tokens ls
|
||||
|
||||
- Create a scoped token:
|
||||
|
||||
$ coder tokens create --scope workspace:read --allow workspace:<uuid>
|
||||
|
||||
- Remove a token by ID:
|
||||
|
||||
$ coder tokens rm WuoWs4ZsMX
|
||||
@@ -32,8 +36,9 @@ Tokens are used to authenticate automated clients to Coder.
|
||||
|
||||
## Subcommands
|
||||
|
||||
| Name | Purpose |
|
||||
|-------------------------------------------|----------------|
|
||||
| [<code>create</code>](./tokens_create.md) | Create a token |
|
||||
| [<code>list</code>](./tokens_list.md) | List tokens |
|
||||
| [<code>remove</code>](./tokens_remove.md) | Delete a token |
|
||||
| Name | Purpose |
|
||||
|-------------------------------------------|--------------------------------------------|
|
||||
| [<code>create</code>](./tokens_create.md) | Create a token |
|
||||
| [<code>list</code>](./tokens_list.md) | List tokens |
|
||||
| [<code>view</code>](./tokens_view.md) | Display detailed information about a token |
|
||||
| [<code>remove</code>](./tokens_remove.md) | Delete a token |
|
||||
|
||||
Generated
+16
@@ -37,3 +37,19 @@ Specify a human-readable name.
|
||||
| Environment | <code>$CODER_TOKEN_USER</code> |
|
||||
|
||||
Specify the user to create the token for (Only works if logged in user is admin).
|
||||
|
||||
### --scope
|
||||
|
||||
| | |
|
||||
|------|---------------------------|
|
||||
| Type | <code>string-array</code> |
|
||||
|
||||
Repeatable scope to attach to the token (e.g. workspace:read).
|
||||
|
||||
### --allow
|
||||
|
||||
| | |
|
||||
|------|-------------------------|
|
||||
| Type | <code>allow-list</code> |
|
||||
|
||||
Repeatable allow-list entry (<type>:<uuid>, e.g. workspace:1234-...).
|
||||
|
||||
Generated
+4
-4
@@ -25,10 +25,10 @@ Specifies whether all users' tokens will be listed or not (must have Owner role
|
||||
|
||||
### -c, --column
|
||||
|
||||
| | |
|
||||
|---------|-------------------------------------------------------------------|
|
||||
| Type | <code>[id\|name\|last used\|expires at\|created at\|owner]</code> |
|
||||
| Default | <code>id,name,last used,expires at,created at</code> |
|
||||
| | |
|
||||
|---------|---------------------------------------------------------------------------------------|
|
||||
| Type | <code>[id\|name\|scopes\|allow list\|last used\|expires at\|created at\|owner]</code> |
|
||||
| Default | <code>id,name,scopes,allow list,last used,expires at,created at</code> |
|
||||
|
||||
Columns to display in table output.
|
||||
|
||||
|
||||
Generated
+30
@@ -0,0 +1,30 @@
|
||||
<!-- DO NOT EDIT | GENERATED CONTENT -->
|
||||
# tokens view
|
||||
|
||||
Display detailed information about a token
|
||||
|
||||
## Usage
|
||||
|
||||
```console
|
||||
coder tokens view [flags] <name|id>
|
||||
```
|
||||
|
||||
## Options
|
||||
|
||||
### -c, --column
|
||||
|
||||
| | |
|
||||
|---------|---------------------------------------------------------------------------------------|
|
||||
| Type | <code>[id\|name\|scopes\|allow list\|last used\|expires at\|created at\|owner]</code> |
|
||||
| Default | <code>id,name,scopes,allow list,last used,expires at,created at,owner</code> |
|
||||
|
||||
Columns to display in table output.
|
||||
|
||||
### -o, --output
|
||||
|
||||
| | |
|
||||
|---------|--------------------------|
|
||||
| Type | <code>table\|json</code> |
|
||||
| Default | <code>table</code> |
|
||||
|
||||
Output format.
|
||||
Reference in New Issue
Block a user