-
Notifications
You must be signed in to change notification settings - Fork 26
[IDENTITY-6269] Add CLI support for SCIM token management #3349
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Amelia Dong (ameliadong97)
wants to merge
6
commits into
main
Choose a base branch
from
adong/identity-6269
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
33cb13f
Add CLI support for SCIM token management
ameliadong97 c868fac
Merge branch 'main' into adong/identity-6269
ameliadong97 66ab2cf
Use public SCIM token endpoints
ameliadong97 adb93af
fix validation
ameliadong97 f5d600f
Merge branch 'main' into adong/identity-6269
ameliadong97 0920c90
Fix SCIM test issues: update misleading comment and mark as workflow
ameliadong97 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -295,3 +295,4 @@ require ( | |
| sigs.k8s.io/yaml v1.3.0 // indirect | ||
| ) | ||
|
|
||
| replace github.com/confluentinc/ccloud-sdk-go-v2/org => github.com/confluentinc/ccloud-sdk-go-v2-internal/org v0.2.0 | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Trying to follow the guidance here: https://confluent.slack.com/archives/C04PBPC4H1T/p1776729951342679?thread_ts=1776702872.357189&cid=C04PBPC4H1T But CI is failing with
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| package organization | ||
|
|
||
| import ( | ||
| "time" | ||
|
|
||
| "github.com/spf13/cobra" | ||
|
|
||
| pcmd "github.com/confluentinc/cli/v4/pkg/cmd" | ||
| ) | ||
|
|
||
| type scimTokenCommand struct { | ||
| *pcmd.AuthenticatedCLICommand | ||
| } | ||
|
|
||
| func (c *command) newScimTokenCommand() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "scim-token", | ||
| Short: "Manage SCIM tokens.", | ||
| Long: "Manage SCIM tokens for the current organization.", | ||
| } | ||
|
|
||
| scimCmd := &scimTokenCommand{c.AuthenticatedCLICommand} | ||
|
|
||
| cmd.AddCommand(scimCmd.newCreateCommand()) | ||
| cmd.AddCommand(scimCmd.newListCommand()) | ||
| cmd.AddCommand(scimCmd.newDeleteCommand()) | ||
|
|
||
| return cmd | ||
| } | ||
|
|
||
| func formatTimestamp(ts *time.Time) string { | ||
| if ts == nil { | ||
| return "" | ||
| } | ||
| return ts.UTC().Format(time.RFC3339) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| package organization | ||
|
|
||
| import ( | ||
| "github.com/spf13/cobra" | ||
|
|
||
| orgv2 "github.com/confluentinc/ccloud-sdk-go-v2/org/v2" | ||
|
|
||
| pcmd "github.com/confluentinc/cli/v4/pkg/cmd" | ||
| "github.com/confluentinc/cli/v4/pkg/output" | ||
| ) | ||
|
|
||
| type scimTokenCreateOut struct { | ||
| Id string `human:"ID" serialized:"id"` | ||
| Token string `human:"Token" serialized:"token"` | ||
| CreatedAt string `human:"Created At" serialized:"created_at"` | ||
| ExpiresAt string `human:"Expires At" serialized:"expires_at"` | ||
| } | ||
|
|
||
| func (c *scimTokenCommand) newCreateCommand() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "create", | ||
| Short: "Create a SCIM token.", | ||
| Long: "Create a SCIM token for the current organization.\n\nSave the token as it is not retrievable later.", | ||
| Args: cobra.NoArgs, | ||
| RunE: c.create, | ||
| } | ||
|
|
||
| cmd.Flags().Int32("expire-duration-mins", 0, "Token expiration duration in minutes. Defaults to 6 months if not specified.") | ||
| pcmd.AddOutputFlag(cmd) | ||
|
|
||
| return cmd | ||
| } | ||
|
|
||
| func (c *scimTokenCommand) create(cmd *cobra.Command, _ []string) error { | ||
| token := orgv2.InlineObject{} | ||
|
|
||
| // Only set expiration duration if explicitly provided | ||
| if cmd.Flags().Changed("expire-duration-mins") { | ||
| expireDurationMins, err := cmd.Flags().GetInt32("expire-duration-mins") | ||
| if err != nil { | ||
| return err | ||
| } | ||
| token.ExpireDurationMins = orgv2.PtrInt32(expireDurationMins) | ||
| } | ||
|
ameliadong97 marked this conversation as resolved.
|
||
|
|
||
| createdToken, err := c.V2Client.CreateScimToken(token) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| output.Println(c.Config.EnableColor, "Save the token as it is not retrievable later.") | ||
|
|
||
| table := output.NewTable(cmd) | ||
| table.Add(&scimTokenCreateOut{ | ||
| Id: createdToken.GetId(), | ||
| Token: createdToken.GetToken(), | ||
| CreatedAt: formatTimestamp(createdToken.CreatedAt), | ||
| ExpiresAt: formatTimestamp(createdToken.ExpiresAt), | ||
| }) | ||
| return table.Print() | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package organization | ||
|
|
||
| import ( | ||
| "github.com/spf13/cobra" | ||
|
|
||
| pcmd "github.com/confluentinc/cli/v4/pkg/cmd" | ||
| "github.com/confluentinc/cli/v4/pkg/deletion" | ||
| "github.com/confluentinc/cli/v4/pkg/resource" | ||
| ) | ||
|
|
||
| func (c *scimTokenCommand) newDeleteCommand() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "delete <id>", | ||
| Short: "Delete a SCIM token.", | ||
| Long: "Delete a SCIM token for the current organization.", | ||
| Args: cobra.ExactArgs(1), | ||
| RunE: c.delete, | ||
| } | ||
|
|
||
| pcmd.AddForceFlag(cmd) | ||
|
|
||
| return cmd | ||
| } | ||
|
|
||
| func (c *scimTokenCommand) delete(cmd *cobra.Command, args []string) error { | ||
| if err := deletion.ValidateAndConfirm(cmd, args, func(id string) bool { return true }, resource.ScimToken); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| _, err := deletion.Delete(cmd, args, func(tokenId string) error { | ||
| return c.V2Client.DeleteScimToken(tokenId) | ||
| }, resource.ScimToken) | ||
|
|
||
| return err | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| package organization | ||
|
|
||
| import ( | ||
| "github.com/spf13/cobra" | ||
|
|
||
| pcmd "github.com/confluentinc/cli/v4/pkg/cmd" | ||
| "github.com/confluentinc/cli/v4/pkg/output" | ||
| ) | ||
|
|
||
| type scimTokenListOut struct { | ||
| Id string `human:"ID" serialized:"id"` | ||
| CreatedAt string `human:"Created At" serialized:"created_at"` | ||
| ExpiresAt string `human:"Expires At" serialized:"expires_at"` | ||
| } | ||
|
|
||
| func (c *scimTokenCommand) newListCommand() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "list", | ||
| Short: "List SCIM tokens.", | ||
| Long: "List SCIM tokens for the current organization.", | ||
| Args: cobra.NoArgs, | ||
| RunE: c.list, | ||
| } | ||
|
|
||
| pcmd.AddOutputFlag(cmd) | ||
|
|
||
| return cmd | ||
| } | ||
|
|
||
| func (c *scimTokenCommand) list(cmd *cobra.Command, _ []string) error { | ||
| tokens, err := c.V2Client.ListScimTokens() | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| list := output.NewList(cmd) | ||
| for _, token := range tokens { | ||
| list.Add(&scimTokenListOut{ | ||
| Id: token.GetId(), | ||
| CreatedAt: formatTimestamp(token.CreatedAt), | ||
| ExpiresAt: formatTimestamp(token.ExpiresAt), | ||
| }) | ||
| } | ||
| return list.Print() | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| package ccloudv2 | ||
|
|
||
| import ( | ||
| "net/http" | ||
|
|
||
| orgv2 "github.com/confluentinc/ccloud-sdk-go-v2/org/v2" | ||
|
|
||
| "github.com/confluentinc/cli/v4/pkg/errors" | ||
| ) | ||
|
|
||
| // SCIM token API calls | ||
|
|
||
| func (c *Client) CreateScimToken(token orgv2.InlineObject) (orgv2.OrgV2ScimToken, error) { | ||
| resp, httpResp, err := c.OrgClient.ScimTokensOrgV2Api.CreateOrgV2ScimToken(c.orgApiContext()).InlineObject(token).Execute() | ||
| return resp, errors.CatchCCloudV2Error(err, httpResp) | ||
| } | ||
|
|
||
| func (c *Client) ListScimTokens() ([]orgv2.OrgV2ScimToken, error) { | ||
| var list []orgv2.OrgV2ScimToken | ||
|
|
||
| done := false | ||
| pageToken := "" | ||
| for !done { | ||
| page, httpResp, err := c.executeListScimTokens(pageToken) | ||
| if err != nil { | ||
| return nil, errors.CatchCCloudV2Error(err, httpResp) | ||
| } | ||
| list = append(list, page.GetData()...) | ||
|
|
||
| pageToken, done, err = extractNextPageToken(page.GetMetadata().Next) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| } | ||
| return list, nil | ||
| } | ||
|
|
||
| func (c *Client) executeListScimTokens(pageToken string) (orgv2.OrgV2ScimTokenList, *http.Response, error) { | ||
| req := c.OrgClient.ScimTokensOrgV2Api.ListOrgV2ScimTokens(c.orgApiContext()).PageSize(ccloudV2ListPageSize) | ||
| if pageToken != "" { | ||
| req = req.PageToken(pageToken) | ||
| } | ||
| return req.Execute() | ||
| } | ||
|
|
||
| func (c *Client) DeleteScimToken(id string) error { | ||
| httpResp, err := c.OrgClient.ScimTokensOrgV2Api.DeleteOrgV2ScimToken(c.orgApiContext(), id).Execute() | ||
| return errors.CatchCCloudV2Error(err, httpResp) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
test/fixtures/output/organization/scim-token-create-custom-expiration.golden
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| Save the token as it is not retrievable later. | ||
| +------------+--------------------------------------+ | ||
| | ID | scim_token-5 | | ||
| | Token | scim_secret_token_value_scim_token-5 | | ||
| | Created At | 2026-02-12T10:58:00Z | | ||
| | Expires At | 2026-03-14T10:58:00Z | | ||
| +------------+--------------------------------------+ |
7 changes: 7 additions & 0 deletions
7
test/fixtures/output/organization/scim-token-create-json.golden
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| Save the token as it is not retrievable later. | ||
| { | ||
| "id": "scim_token-4", | ||
| "token": "scim_secret_token_value_scim_token-4", | ||
| "created_at": "2026-02-12T10:57:59Z", | ||
| "expires_at": "2026-08-12T10:57:59Z" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| Save the token as it is not retrievable later. | ||
| +------------+--------------------------------------+ | ||
| | ID | scim_token-3 | | ||
| | Token | scim_secret_token_value_scim_token-3 | | ||
| | Created At | 2026-02-12T10:57:58Z | | ||
| | Expires At | 2026-08-12T10:57:58Z | | ||
| +------------+--------------------------------------+ |
1 change: 1 addition & 0 deletions
1
test/fixtures/output/organization/scim-token-delete-not-found.golden
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Error: failed to delete nonexistent: SCIM token not found |
1 change: 1 addition & 0 deletions
1
test/fixtures/output/organization/scim-token-delete-prompt.golden
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Are you sure you want to delete SCIM token "scim_token-67890"? (y/n): Deleted SCIM token "scim_token-67890". |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Deleted SCIM token "scim_token-12345". |
27 changes: 27 additions & 0 deletions
27
test/fixtures/output/organization/scim-token-list-json.golden
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| [ | ||
| { | ||
| "id": "scim_token-12345", | ||
| "created_at": "2025-01-01T01:00:00Z", | ||
| "expires_at": "2026-01-01T01:00:00Z" | ||
| }, | ||
| { | ||
| "id": "scim_token-3", | ||
| "created_at": "2026-02-12T10:57:58Z", | ||
| "expires_at": "2026-08-12T10:57:58Z" | ||
| }, | ||
| { | ||
| "id": "scim_token-4", | ||
| "created_at": "2026-02-12T10:57:59Z", | ||
| "expires_at": "2026-08-12T10:57:59Z" | ||
| }, | ||
| { | ||
| "id": "scim_token-5", | ||
| "created_at": "2026-02-12T10:58:00Z", | ||
| "expires_at": "2026-03-14T10:58:00Z" | ||
| }, | ||
| { | ||
| "id": "scim_token-67890", | ||
| "created_at": "2025-02-01T01:00:00Z", | ||
| "expires_at": "2026-02-01T01:00:00Z" | ||
| } | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| ID | Created At | Expires At | ||
| -------------------+----------------------+----------------------- | ||
| scim_token-12345 | 2025-01-01T01:00:00Z | 2026-01-01T01:00:00Z | ||
| scim_token-3 | 2026-02-12T10:57:58Z | 2026-08-12T10:57:58Z | ||
| scim_token-4 | 2026-02-12T10:57:59Z | 2026-08-12T10:57:59Z | ||
| scim_token-5 | 2026-02-12T10:58:00Z | 2026-03-14T10:58:00Z | ||
| scim_token-67890 | 2025-02-01T01:00:00Z | 2026-02-01T01:00:00Z |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package test | ||
|
|
||
| func (s *CLITestSuite) TestOrganizationSCIM() { | ||
| tests := []CLITest{ | ||
| {args: "organization scim-token create", fixture: "organization/scim-token-create.golden"}, | ||
| {args: "organization scim-token create -o json", fixture: "organization/scim-token-create-json.golden"}, | ||
| {args: "organization scim-token create --expire-duration-mins 43200", fixture: "organization/scim-token-create-custom-expiration.golden"}, | ||
| {args: "organization scim-token list", fixture: "organization/scim-token-list.golden"}, | ||
| {args: "organization scim-token list -o json", fixture: "organization/scim-token-list-json.golden"}, | ||
| {args: "organization scim-token delete scim_token-12345 --force", fixture: "organization/scim-token-delete.golden"}, | ||
| {args: "organization scim-token delete scim_token-67890", input: "y\n", fixture: "organization/scim-token-delete-prompt.golden"}, | ||
| {args: "organization scim-token delete nonexistent --force", fixture: "organization/scim-token-delete-not-found.golden", exitCode: 1}, | ||
| } | ||
|
ameliadong97 marked this conversation as resolved.
|
||
|
|
||
| for _, test := range tests { | ||
| test.login = "cloud" | ||
| test.workflow = true | ||
| s.runIntegrationTest(test) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.