Skip to content

Commit e3fe829

Browse files
committed
feat: fixed api client code
1 parent 92fcb85 commit e3fe829

File tree

5 files changed

+24
-24
lines changed

5 files changed

+24
-24
lines changed

commercetools/resource_api_client.go

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,16 @@ func resourceAPIClient() *schema.Resource {
4040
Required: true,
4141
ForceNew: true,
4242
},
43-
"accessTokenValiditySeconds": {
43+
"access_token_validity_seconds": {
4444
Description: "Expiration time in seconds for each access token obtained by the APIClient. Only present when set with the APIClientDraft. If not present the default value applies.",
45-
Type: schema.TypeSet,
46-
Elem: &schema.Schema{Type: schema.TypeInt},
47-
Required: false,
45+
Type: schema.TypeInt,
46+
Optional: true,
4847
ForceNew: true,
4948
},
50-
"refreshTokenValiditySeconds": {
49+
"refresh_token_validity_seconds": {
5150
Description: "Inactivity expiration time in seconds for each refresh token obtained by the APIClient. Only present when set with the APIClientDraft. If not present the default value applies.",
52-
Type: schema.TypeSet,
53-
Elem: &schema.Schema{Type: schema.TypeInt},
54-
Required: false,
51+
Type: schema.TypeInt,
52+
Optional: true,
5553
ForceNew: true,
5654
},
5755
"secret": {
@@ -75,11 +73,11 @@ func resourceAPIClientCreate(ctx context.Context, d *schema.ResourceData, m any)
7573
Name: d.Get("name").(string),
7674
Scope: strings.Join(scopeParts, " "),
7775
}
78-
if val := d.Get("accessTokenValiditySeconds").(*int); val != nil && *val > 0 {
79-
draft.AccessTokenValiditySeconds = val
76+
if val := d.Get("access_token_validity_seconds").(int); val != 0 {
77+
draft.AccessTokenValiditySeconds = &val
8078
}
81-
if val := d.Get("refreshTokenValiditySeconds").(*int); val != nil && *val > 0 {
82-
draft.RefreshTokenValiditySeconds = val
79+
if val := d.Get("refresh_token_validity_seconds").(int); val != 0 {
80+
draft.RefreshTokenValiditySeconds = &val
8381
}
8482

8583
client := getClient(m)
@@ -119,8 +117,8 @@ func resourceAPIClientRead(ctx context.Context, d *schema.ResourceData, m any) d
119117
scopes := strings.Split(apiClient.Scope, " ")
120118
sort.Strings(scopes)
121119
_ = d.Set("scope", scopes)
122-
_ = d.Set("accessTokenValiditySeconds", apiClient.AccessTokenValiditySeconds)
123-
_ = d.Set("refreshTokenValiditySeconds", apiClient.RefreshTokenValiditySeconds)
120+
_ = d.Set("access_token_validity_seconds", apiClient.AccessTokenValiditySeconds)
121+
_ = d.Set("refresh_token_validity_seconds", apiClient.RefreshTokenValiditySeconds)
124122
return nil
125123
}
126124

docker-compose.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
services:
2+
commercetools:
3+
image: labdigital/commercetools-mock-server
4+
ports:
5+
- 8989:8989

docs/index.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ provider "commercetools" {
4949
client_id = "<your client id>"
5050
client_secret = "<your client secret>"
5151
project_key = "<your project key>"
52-
project_key = "<your project key>"
5352
scopes = "<space seperated list of scopes>"
5453
api_url = "<api url>"
5554
token_url = "<token url>"

docs/resources/api_client.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,14 @@ description: |-
1111

1212
Create a new API client. Note that Commercetools might return slightly different scopes, resulting in a new API client being created everytime Terraform is run. In this case, fix your scopes accordingly to match what is returned by Commercetools.
1313

14-
Also see the [API client HTTP API documentation](https://docs.commercetools.com//http-api-projects-api-clients).
14+
Also see the [API client HTTP API documentation](https://docs.commercetools.com/api/projects/api-clients).
1515

1616
## Example Usage
1717

1818
```terraform
1919
resource "commercetools_api_client" "my-api-client" {
2020
name = "My API Client"
2121
scope = ["manage_orders:my-ct-project-key", "manage_payments:my-ct-project-key"]
22-
accessTokenValiditySeconds = 3600
23-
refreshTokenValiditySeconds = 60
2422
}
2523
```
2624

@@ -29,14 +27,13 @@ resource "commercetools_api_client" "my-api-client" {
2927

3028
### Required
3129

32-
- `name` (String) Name of the API client.
33-
- `scope` (Set of String) A list of the [OAuth scopes](https://docs.commercetools.com/api/scopes).
34-
30+
- `name` (String) Name of the API client
31+
- `scope` (Set of String) A list of the [OAuth scopes](https://docs.commercetools.com/api/scopes)
3532

3633
### Optional
3734

38-
- `accessTokenValiditySeconds` (Int) Expiration time in seconds for each access token obtained by the APIClient. See the latest CommerceTools documentation for [API Clients](https://docs.commercetools.com/api/projects/api-clients) for valid number ranges.
39-
- `refreshTokenValiditySeconds` (Int) Inactivity expiration time in seconds for each refresh token obtained by the APIClient. See the latest CommerceTools documentation for [API Clients](https://docs.commercetools.com/api/projects/api-clients) for valid number ranges.
35+
- `access_token_validity_seconds` (Number) Expiration time in seconds for each access token obtained by the APIClient. Only present when set with the APIClientDraft. If not present the default value applies.
36+
- `refresh_token_validity_seconds` (Number) Inactivity expiration time in seconds for each refresh token obtained by the APIClient. Only present when set with the APIClientDraft. If not present the default value applies.
4037

4138
### Read-Only
4239

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module github.com/labd/terraform-provider-commercetools
22

3-
go 1.22.0
3+
go 1.22.7
4+
45
toolchain go1.22.8
56

67
//replace github.com/labd/commercetools-go-sdk v1.5.1 => ../commercetools-go-sdk

0 commit comments

Comments
 (0)