-
Notifications
You must be signed in to change notification settings - Fork 105
Adds AdminSCIMToken to Manage SCIM Tokens
#1310
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
Merged
Merged
Changes from 20 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
7b8e738
adds support for Admin Scim Tokens, adds integration tests, cleanup i…
skj-skj 97b0d7f
added mocks for admin scim token, and fixed typo in file name
skj-skj dad0849
Merge branch 'main' into skj/scim-token
skj-skj 3da5122
Potential fix for pull request finding
skj-skj 297b17f
Potential fix for pull request finding
skj-skj 73250c5
Potential fix for pull request finding
skj-skj 4f2ac96
addressed review comment, added copywrite header, added some cleanup,…
skj-skj f81f397
Potential fix for pull request finding
skj-skj ec9d586
updated mocks
skj-skj 120c677
Potential fix for pull request finding
skj-skj 763384c
addressed review comments, renamed field named to Tokens
skj-skj 7861fc0
Potential fix for pull request finding
skj-skj 0873c7f
Potential fix for pull request finding
skj-skj de9f850
fixed grammer in GoDoc
skj-skj ab93607
Potential fix for pull request finding
skj-skj 581a872
Potential fix for pull request finding
skj-skj 74ee550
Merge branch 'main' into skj/scim-token
skj-skj 0e2a790
added validtion for scim token description
skj-skj c8221ea
added const for api paths
skj-skj 4e3995a
updated scim tokens mocks
skj-skj fa12b41
removed AdminSCIMTokenPath const
skj-skj 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
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,135 @@ | ||
| // Copyright IBM Corp. 2018, 2026 | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
|
|
||
| package tfe | ||
|
|
||
|
skj-skj marked this conversation as resolved.
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "net/url" | ||
| "time" | ||
| ) | ||
|
|
||
| var _ AdminSCIMTokens = (*adminSCIMTokens)(nil) | ||
|
|
||
| // AdminSCIMTokens describes all the Admin SCIM token related methods that the Terraform | ||
| // Enterprise API supports | ||
| // | ||
| // TFE API docs: https://developer.hashicorp.com/terraform/enterprise/api-docs/admin/scim-tokens | ||
| type AdminSCIMTokens interface { | ||
| // List all Admin SCIM tokens. | ||
| List(ctx context.Context) (*AdminSCIMTokenList, error) | ||
|
|
||
| // Create an Admin SCIM token. | ||
| Create(ctx context.Context, description string) (*AdminSCIMToken, error) | ||
|
|
||
| // Create an Admin SCIM token with options. | ||
| CreateWithOptions(ctx context.Context, options AdminSCIMTokenCreateOptions) (*AdminSCIMToken, error) | ||
|
|
||
| // Read an Admin SCIM token by its ID. | ||
| Read(ctx context.Context, scimTokenID string) (*AdminSCIMToken, error) | ||
|
|
||
| // Delete an Admin SCIM token. | ||
| Delete(ctx context.Context, scimTokenID string) error | ||
| } | ||
|
|
||
| // adminSCIMTokens implements AdminSCIMTokens | ||
| type adminSCIMTokens struct { | ||
| client *Client | ||
| } | ||
|
|
||
| // AdminSCIMTokenList represents a list of Admin SCIM tokens | ||
| type AdminSCIMTokenList struct { | ||
|
skj-skj marked this conversation as resolved.
skj-skj marked this conversation as resolved.
|
||
| Items []*AdminSCIMToken | ||
| } | ||
|
skj-skj marked this conversation as resolved.
|
||
|
|
||
| // AdminSCIMToken represents a Terraform Enterprise Admin SCIM token. | ||
| type AdminSCIMToken struct { | ||
| ID string `jsonapi:"primary,authentication-tokens"` | ||
| CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"` | ||
| LastUsedAt time.Time `jsonapi:"attr,last-used-at,iso8601"` | ||
| ExpiredAt time.Time `jsonapi:"attr,expired-at,iso8601"` | ||
| Description string `jsonapi:"attr,description"` | ||
| Token string `jsonapi:"attr,token,omitempty"` | ||
| } | ||
|
|
||
| // AdminSCIMTokenCreateOptions represents the options for creating an Admin SCIM token | ||
| type AdminSCIMTokenCreateOptions struct { | ||
| // Required: A human-readable description of the token's purpose | ||
| // (for example, Okta SCIM Integration). | ||
| Description *string `jsonapi:"attr,description"` | ||
|
|
||
| // Optional: Optional ISO-8601 timestamp for token expiration. | ||
| // Defaults to 365 days in the future. Must be between 29 and 365 days in the future. | ||
| ExpiredAt *time.Time `jsonapi:"attr,expired-at,iso8601,omitempty"` | ||
| } | ||
|
|
||
| // List all Admin SCIM tokens. | ||
| func (a *adminSCIMTokens) List(ctx context.Context) (*AdminSCIMTokenList, error) { | ||
| req, err := a.client.NewRequest("GET", AdminSCIMTokensPath, nil) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| scimTokens := &AdminSCIMTokenList{} | ||
| err = req.Do(ctx, scimTokens) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return scimTokens, nil | ||
| } | ||
|
|
||
| // Create an Admin SCIM token. | ||
| func (a *adminSCIMTokens) Create(ctx context.Context, description string) (*AdminSCIMToken, error) { | ||
| return a.CreateWithOptions(ctx, AdminSCIMTokenCreateOptions{ | ||
| Description: &description, | ||
| }) | ||
| } | ||
|
|
||
| // Create an Admin SCIM token with options. | ||
| func (a *adminSCIMTokens) CreateWithOptions(ctx context.Context, options AdminSCIMTokenCreateOptions) (*AdminSCIMToken, error) { | ||
| if !validString(options.Description) { | ||
| return nil, ErrSCIMTokenDescription | ||
| } | ||
| req, err := a.client.NewRequest("POST", AdminSCIMTokensPath, &options) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| scimToken := &AdminSCIMToken{} | ||
| err = req.Do(ctx, scimToken) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return scimToken, nil | ||
| } | ||
|
|
||
| // Read an Admin SCIM token by its ID. | ||
| func (a *adminSCIMTokens) Read(ctx context.Context, scimTokenID string) (*AdminSCIMToken, error) { | ||
| if !validStringID(&scimTokenID) { | ||
| return nil, ErrInvalidTokenID | ||
| } | ||
| u := fmt.Sprintf(AdminSCIMTokenPath, url.PathEscape(scimTokenID)) | ||
| req, err := a.client.NewRequest("GET", u, nil) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| scimToken := &AdminSCIMToken{} | ||
| err = req.Do(ctx, scimToken) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return scimToken, nil | ||
| } | ||
|
|
||
| // Delete an Admin SCIM token. | ||
| func (a *adminSCIMTokens) Delete(ctx context.Context, scimTokenID string) error { | ||
| if !validStringID(&scimTokenID) { | ||
| return ErrInvalidTokenID | ||
| } | ||
| u := fmt.Sprintf(AuthenticationTokensPath, url.PathEscape(scimTokenID)) | ||
|
skj-skj marked this conversation as resolved.
|
||
| req, err := a.client.NewRequest("DELETE", u, nil) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| return req.Do(ctx, nil) | ||
| } | ||
Oops, something went wrong.
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.