Skip to content
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

Add check for status code 404 when creating scoped_token #981

Merged
merged 4 commits into from
May 30, 2024
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
## 10.8.2 (May 30, 2024)
## 10.8.2 (May 31, 2024)

BUG FIXES:

* resource/artifactory_keypair: Remove `private_key` value from warning and error messages. Issue: [#977](https://github.com/jfrog/terraform-provider-artifactory/issues/977) PR: [#979](https://github.com/jfrog/terraform-provider-artifactory/pull/979)
* resource/artifactory_scoped_token: Add check for status code 404 after resource creation and display warning message due to Persistency Threshold. Issue: [#980](https://github.com/jfrog/terraform-provider-artifactory/issues/980) PR: [#981](https://github.com/jfrog/terraform-provider-artifactory/pull/981)

## 10.8.1 (May 24, 2024)

Expand Down
4 changes: 2 additions & 2 deletions docs/resources/scoped_token.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Provides an Artifactory Scoped Token resource. This can be used to create and ma
!>Scoped Tokens will be stored in the raw state as plain-text. [Read more about sensitive data in
state](https://www.terraform.io/docs/state/sensitive-data.html).

~>Token would not be saved by Artifactory if `expires_in` is less than the persistency threshold value (default to 10800 seconds) set in Access configuration. See [Persistency Threshold](https://jfrog.com/help/r/jfrog-platform-administration-documentation/using-the-revocable-and-persistency-thresholds) for details.
~>Token would not be saved by Artifactory if `expires_in` is less than the persistency threshold value (default to 10800 seconds) set in Access configuration. See [Persistency Threshold](https://jfrog.com/help/r/jfrog-platform-administration-documentation/persistency-threshold) for details.

## Example Usages

Expand Down Expand Up @@ -75,7 +75,7 @@ resource "artifactory_scoped_token" "audience" {

- `audiences` (Set of String) A list of the other instances or services that should accept this token identified by their Service-IDs. Limited to total 255 characters. Default to '*@*' if not set. Service ID must begin with valid JFrog service type. Options: jfrt, jfxr, jfpip, jfds, jfmc, jfac, jfevt, jfmd, jfcon, or *. For instructions to retrieve the Artifactory Service ID see this [documentation](https://jfrog.com/help/r/jfrog-rest-apis/get-service-id)
- `description` (String) Free text token description. Useful for filtering and managing tokens. Limited to 1024 characters.
- `expires_in` (Number) The amount of time, in seconds, it would take for the token to expire. An admin shall be able to set whether expiry is mandatory, what is the default expiry, and what is the maximum expiry allowed. Must be non-negative. Default value is based on configuration in 'access.config.yaml'. See [API documentation](https://jfrog.com/help/r/jfrog-rest-apis/create-token) for details. Access Token would not be saved by Artifactory if this is less than the persistence threshold value (default to 10800 seconds) set in Access configuration. See [official documentation](https://jfrog.com/help/r/jfrog-platform-administration-documentation/using-the-revocable-and-persistency-thresholds) for details.
- `expires_in` (Number) The amount of time, in seconds, it would take for the token to expire. An admin shall be able to set whether expiry is mandatory, what is the default expiry, and what is the maximum expiry allowed. Must be non-negative. Default value is based on configuration in 'access.config.yaml'. See [API documentation](https://jfrog.com/help/r/jfrog-rest-apis/create-token) for details. Access Token would not be saved by Artifactory if this is less than the persistence threshold value (default to 10800 seconds) set in Access configuration. See [official documentation](https://jfrog.com/help/r/jfrog-platform-administration-documentation/persistency-threshold) for details.
- `grant_type` (String) The grant type used to authenticate the request. In this case, the only value supported is `client_credentials` which is also the default value if this parameter is not specified.
- `include_reference_token` (Boolean) Also create a reference token which can be used like an API key.
- `refreshable` (Boolean) Is this token refreshable? Default is `false`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func (r *ScopedTokenResource) Schema(ctx context.Context, req resource.SchemaReq
},
},
"expires_in": schema.Int64Attribute{
MarkdownDescription: "The amount of time, in seconds, it would take for the token to expire. An admin shall be able to set whether expiry is mandatory, what is the default expiry, and what is the maximum expiry allowed. Must be non-negative. Default value is based on configuration in 'access.config.yaml'. See [API documentation](https://jfrog.com/help/r/jfrog-rest-apis/revoke-token-by-id) for details. Access Token would not be saved by Artifactory if this is less than the persistence threshold value (default to 10800 seconds) set in Access configuration. See [official documentation](https://jfrog.com/help/r/jfrog-platform-administration-documentation/using-the-revocable-and-persistency-thresholds) for details.",
MarkdownDescription: "The amount of time, in seconds, it would take for the token to expire. An admin shall be able to set whether expiry is mandatory, what is the default expiry, and what is the maximum expiry allowed. Must be non-negative. Default value is based on configuration in 'access.config.yaml'. See [API documentation](https://jfrog.com/help/r/jfrog-rest-apis/revoke-token-by-id) for details. Access Token would not be saved by Artifactory if this is less than the persistence threshold value (default to 10800 seconds) set in Access configuration. See [official documentation](https://jfrog.com/help/r/jfrog-platform-administration-documentation/persistency-threshold) for details.",
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.Int64{
Expand Down Expand Up @@ -412,8 +412,16 @@ func (r *ScopedTokenResource) Create(ctx context.Context, req resource.CreateReq
}

if response.IsError() {
utilfw.UnableToCreateResourceError(resp, artifactoryError.String())
return
if response.StatusCode() == http.StatusNotFound {
resp.Diagnostics.AddWarning(
fmt.Sprintf("Scoped token with ID %s is not found", id.ValueString()),
"Token would not be saved by Artifactory if 'expires_in' is less than the persistence threshold value (default to 10800 seconds) set in Access configuration. "+
"See https://jfrog.com/help/r/jfrog-platform-administration-documentation/persistency-threshold for details.",
)
} else {
utilfw.UnableToCreateResourceError(resp, artifactoryError.String())
return
}
}

// Assign the attribute values for the resource in the state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -853,8 +853,8 @@ func TestAccScopedToken_WithExpiresInLessThanPersistencyThreshold(t *testing.T)
ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories,
Steps: []resource.TestStep{
{
Config: accessTokenConfig,
ExpectError: regexp.MustCompile("Unable to Create Resource"),
Config: accessTokenConfig,
ExpectNonEmptyPlan: true,
},
},
})
Expand Down
Loading