Skip to content
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
1 change: 1 addition & 0 deletions app/cli/cmd/organization_apitoken_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func newAPITokenListCmd() *cobra.Command {
var availableScopes = []string{
"project",
"global",
"product",
}

var availableStatusFilters = []string{
Expand Down
2 changes: 1 addition & 1 deletion app/cli/documentation/cli-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -2112,7 +2112,7 @@ Options
```
-h, --help[=true|false] help for list
-p, --project string filter by project name
-s, --scope string filter by scope, available scopes: [project global]
-s, --scope string filter by scope, available scopes: [project global product]
--status string filter by token status, available values: [active revoked all]
```

Expand Down
2 changes: 2 additions & 0 deletions app/cli/pkg/action/apitoken_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ func mapScope(scope string) pb.APITokenServiceListRequest_Scope {
return pb.APITokenServiceListRequest_SCOPE_PROJECT
case "global":
return pb.APITokenServiceListRequest_SCOPE_GLOBAL
case "product":
return pb.APITokenServiceListRequest_SCOPE_PRODUCT
default:
return pb.APITokenServiceListRequest_SCOPE_UNSPECIFIED
}
Expand Down
11 changes: 8 additions & 3 deletions app/controlplane/api/controlplane/v1/api_token.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions app/controlplane/api/controlplane/v1/api_token.proto
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ message APITokenServiceListRequest {
SCOPE_UNSPECIFIED = 0;
SCOPE_PROJECT = 1;
SCOPE_GLOBAL = 2;
// Tokens confined to the projects of a product.
SCOPE_PRODUCT = 3;
}

// filter by the scope of the token
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions app/controlplane/internal/service/apitoken.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ func mapTokenScope(scope pb.APITokenServiceListRequest_Scope) authz.ResourceType
return authz.ResourceTypeProject
case pb.APITokenServiceListRequest_SCOPE_GLOBAL:
return authz.ResourceTypeOrganization
case pb.APITokenServiceListRequest_SCOPE_PRODUCT:
return authz.ResourceTypeProduct
}

return ""
Expand Down
12 changes: 12 additions & 0 deletions app/controlplane/internal/service/apitoken_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ func TestAPITokenServiceListForcesProjectScopeForOrgTokens(t *testing.T) {
requested: pb.APITokenServiceListRequest_SCOPE_GLOBAL,
wantScope: authz.ResourceTypeProject,
},
{
name: "an organization token asking for product tokens is still forced",
caller: &entities.APIToken{ID: uuid.NewString(), Scope: biz.ToPtr(authz.ResourceTypeOrganization), ScopeID: &orgID},
requested: pb.APITokenServiceListRequest_SCOPE_PRODUCT,
wantScope: authz.ResourceTypeProject,
},
{
// Not organization-wide either, and confined to nothing: narrowed to no project.
name: "a token recording no scope is narrowed to no project",
Expand Down Expand Up @@ -110,6 +116,11 @@ func TestAPITokenServiceListForcesProjectScopeForOrgTokens(t *testing.T) {
requested: pb.APITokenServiceListRequest_SCOPE_GLOBAL,
wantScope: authz.ResourceTypeOrganization,
},
{
name: "a user asking for product tokens gets them",
requested: pb.APITokenServiceListRequest_SCOPE_PRODUCT,
wantScope: authz.ResourceTypeProduct,
},
{
name: "a user asking for no scope gets none",
wantScope: "",
Expand Down Expand Up @@ -254,6 +265,7 @@ func TestMapTokenScope(t *testing.T) {
{in: pb.APITokenServiceListRequest_SCOPE_UNSPECIFIED, want: ""},
{in: pb.APITokenServiceListRequest_SCOPE_PROJECT, want: authz.ResourceTypeProject},
{in: pb.APITokenServiceListRequest_SCOPE_GLOBAL, want: authz.ResourceTypeOrganization},
{in: pb.APITokenServiceListRequest_SCOPE_PRODUCT, want: authz.ResourceTypeProduct},
}

for _, tc := range testCases {
Expand Down
Loading