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

access_service_token: add support for Duration #1347

Merged
merged 1 commit into from
Aug 15, 2023
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: 3 additions & 0 deletions .changelog/1347.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
access_service_token: add support for managing `Duration`
```
13 changes: 10 additions & 3 deletions access_service_tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type AccessServiceToken struct {
ID string `json:"id"`
Name string `json:"name"`
UpdatedAt *time.Time `json:"updated_at"`
Duration string `json:"duration,omitempty"`
}

// AccessServiceTokenUpdateResponse represents the response from the API
Expand All @@ -33,6 +34,7 @@ type AccessServiceTokenUpdateResponse struct {
ID string `json:"id"`
Name string `json:"name"`
ClientID string `json:"client_id"`
Duration string `json:"duration,omitempty"`
}

// AccessServiceTokenRefreshResponse represents the response from the API
Expand All @@ -44,6 +46,7 @@ type AccessServiceTokenRefreshResponse struct {
ID string `json:"id"`
Name string `json:"name"`
ClientID string `json:"client_id"`
Duration string `json:"duration,omitempty"`
}

// AccessServiceTokenCreateResponse is the same API response as the Update
Expand All @@ -57,6 +60,7 @@ type AccessServiceTokenCreateResponse struct {
Name string `json:"name"`
ClientID string `json:"client_id"`
ClientSecret string `json:"client_secret"`
Duration string `json:"duration,omitempty"`
}

// AccessServiceTokenRotateResponse is the same API response as the Create
Expand All @@ -69,6 +73,7 @@ type AccessServiceTokenRotateResponse struct {
Name string `json:"name"`
ClientID string `json:"client_id"`
ClientSecret string `json:"client_secret"`
Duration string `json:"duration,omitempty"`
}

// AccessServiceTokensListResponse represents the response from the list
Expand Down Expand Up @@ -127,12 +132,14 @@ type AccessServiceTokensRotateSecretDetailResponse struct {
type ListAccessServiceTokensParams struct{}

type CreateAccessServiceTokenParams struct {
Name string `json:"name"`
Name string `json:"name"`
Duration string `json:"duration,omitempty"`
}

type UpdateAccessServiceTokenParams struct {
Name string `json:"name"`
UUID string `json:"-"`
Name string `json:"name"`
UUID string `json:"-"`
Duration string `json:"duration,omitempty"`
}

func (api *API) ListAccessServiceTokens(ctx context.Context, rc *ResourceContainer, params ListAccessServiceTokensParams) ([]AccessServiceToken, ResultInfo, error) {
Expand Down
24 changes: 18 additions & 6 deletions access_service_tokens_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ func TestAccessServiceTokens(t *testing.T) {
"expires_at": "2015-01-01T05:20:00.12345Z",
"id": "f174e90a-fafe-4643-bbbc-4a0ed4fc8415",
"name": "CI/CD token",
"client_id": "88bf3b6d86161464f6509f7219099e57.access.example.com"
"client_id": "88bf3b6d86161464f6509f7219099e57.access.example.com",
"duration": "8760h"
}
]
}
Expand All @@ -47,6 +48,7 @@ func TestAccessServiceTokens(t *testing.T) {
ID: "f174e90a-fafe-4643-bbbc-4a0ed4fc8415",
Name: "CI/CD token",
ClientID: "88bf3b6d86161464f6509f7219099e57.access.example.com",
Duration: "8760h",
},
}

Expand Down Expand Up @@ -85,7 +87,8 @@ func TestCreateAccessServiceToken(t *testing.T) {
"id": "f174e90a-fafe-4643-bbbc-4a0ed4fc8415",
"name": "CI/CD token",
"client_id": "88bf3b6d86161464f6509f7219099e57.access.example.com",
"client_secret": "bdd31cbc4dec990953e39163fbbb194c93313ca9f0a6e420346af9d326b1d2a5"
"client_secret": "bdd31cbc4dec990953e39163fbbb194c93313ca9f0a6e420346af9d326b1d2a5",
"duration": "8760h"
}
}
`)
Expand All @@ -99,6 +102,7 @@ func TestCreateAccessServiceToken(t *testing.T) {
Name: "CI/CD token",
ClientID: "88bf3b6d86161464f6509f7219099e57.access.example.com",
ClientSecret: "bdd31cbc4dec990953e39163fbbb194c93313ca9f0a6e420346af9d326b1d2a5",
Duration: "8760h",
}

mux.HandleFunc("/accounts/"+testAccountID+"/access/service_tokens", handler)
Expand Down Expand Up @@ -135,7 +139,8 @@ func TestUpdateAccessServiceToken(t *testing.T) {
"expires_at": "2015-01-01T05:20:00.12345Z",
"id": "f174e90a-fafe-4643-bbbc-4a0ed4fc8415",
"name": "CI/CD token",
"client_id": "88bf3b6d86161464f6509f7219099e57.access.example.com"
"client_id": "88bf3b6d86161464f6509f7219099e57.access.example.com",
"duration": "8760h"
}
}
`)
Expand All @@ -148,6 +153,7 @@ func TestUpdateAccessServiceToken(t *testing.T) {
ID: "f174e90a-fafe-4643-bbbc-4a0ed4fc8415",
Name: "CI/CD token",
ClientID: "88bf3b6d86161464f6509f7219099e57.access.example.com",
Duration: "8760h",
}

mux.HandleFunc("/accounts/"+testAccountID+"/access/service_tokens/f174e90a-fafe-4643-bbbc-4a0ed4fc8415", handler)
Expand Down Expand Up @@ -184,7 +190,8 @@ func TestRefreshAccessServiceToken(t *testing.T) {
"expires_at": "2015-01-01T05:20:00.12345Z",
"id": "f174e90a-fafe-4643-bbbc-4a0ed4fc8415",
"name": "CI/CD token",
"client_id": "88bf3b6d86161464f6509f7219099e57.access.example.com"
"client_id": "88bf3b6d86161464f6509f7219099e57.access.example.com",
"duration": "8760h"
}
}
`)
Expand All @@ -197,6 +204,7 @@ func TestRefreshAccessServiceToken(t *testing.T) {
ID: "f174e90a-fafe-4643-bbbc-4a0ed4fc8415",
Name: "CI/CD token",
ClientID: "88bf3b6d86161464f6509f7219099e57.access.example.com",
Duration: "8760h",
}

mux.HandleFunc("/accounts/"+testAccountID+"/access/service_tokens/f174e90a-fafe-4643-bbbc-4a0ed4fc8415/refresh", handler)
Expand Down Expand Up @@ -226,7 +234,8 @@ func TestRotateAccessServiceToken(t *testing.T) {
"id": "f174e90a-fafe-4643-bbbc-4a0ed4fc8415",
"name": "CI/CD token",
"client_id": "88bf3b6d86161464f6509f7219099e57.access.example.com",
"client_secret": "bdd31cbc4dec990953e39163fbbb194c93313ca9f0a6e420346af9d326b1d2a5"
"client_secret": "bdd31cbc4dec990953e39163fbbb194c93313ca9f0a6e420346af9d326b1d2a5",
"duration": "8760h"
}
}
`)
Expand All @@ -240,6 +249,7 @@ func TestRotateAccessServiceToken(t *testing.T) {
Name: "CI/CD token",
ClientID: "88bf3b6d86161464f6509f7219099e57.access.example.com",
ClientSecret: "bdd31cbc4dec990953e39163fbbb194c93313ca9f0a6e420346af9d326b1d2a5",
Duration: "8760h",
}

mux.HandleFunc("/accounts/"+testAccountID+"/access/service_tokens/f174e90a-fafe-4643-bbbc-4a0ed4fc8415/rotate", handler)
Expand Down Expand Up @@ -268,7 +278,8 @@ func TestDeleteAccessServiceToken(t *testing.T) {
"expires_at": "2015-01-01T05:20:00.12345Z",
"id": "f174e90a-fafe-4643-bbbc-4a0ed4fc8415",
"name": "CI/CD token",
"client_id": "88bf3b6d86161464f6509f7219099e57.access.example.com"
"client_id": "88bf3b6d86161464f6509f7219099e57.access.example.com",
"duration": "8760h"
}
}
`)
Expand All @@ -281,6 +292,7 @@ func TestDeleteAccessServiceToken(t *testing.T) {
ID: "f174e90a-fafe-4643-bbbc-4a0ed4fc8415",
Name: "CI/CD token",
ClientID: "88bf3b6d86161464f6509f7219099e57.access.example.com",
Duration: "8760h",
}

mux.HandleFunc("/accounts/"+testAccountID+"/access/service_tokens/f174e90a-fafe-4643-bbbc-4a0ed4fc8415", handler)
Expand Down
Loading