From be6bc9f3ea2741dfa91d668a23d2c4ad2cc7b28d Mon Sep 17 00:00:00 2001 From: Dieter De Meyer Date: Tue, 2 Apr 2024 15:45:28 +0200 Subject: [PATCH 1/3] Add support for setting token expiration --- group_serviceaccounts.go | 5 +++-- group_serviceaccounts_test.go | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/group_serviceaccounts.go b/group_serviceaccounts.go index 4acb0b180..6593c1fbe 100644 --- a/group_serviceaccounts.go +++ b/group_serviceaccounts.go @@ -62,8 +62,9 @@ func (s *GroupsService) CreateServiceAccount(gid interface{}, options ...Request // GitLab API docs: // https://docs.gitlab.com/ee/api/groups.html#create-personal-access-token-for-service-account-user type CreateServiceAccountPersonalAccessTokenOptions struct { - Scopes *[]string `url:"scopes,omitempty" json:"scopes,omitempty"` - Name *string `url:"name,omitempty" json:"name,omitempty"` + Scopes *[]string `url:"scopes,omitempty" json:"scopes,omitempty"` + Name *string `url:"name,omitempty" json:"name,omitempty"` + ExpiresAt *string `url:"expires_at,omitempty" json:"expires_at,omitempty"` } // CreateServiceAccountPersonalAccessToken add a new Personal Access Token for a diff --git a/group_serviceaccounts_test.go b/group_serviceaccounts_test.go index e4793f610..7de0adf07 100644 --- a/group_serviceaccounts_test.go +++ b/group_serviceaccounts_test.go @@ -73,8 +73,9 @@ func TestCreateServiceAccountPersonalAccessToken(t *testing.T) { }`) }) options := &CreateServiceAccountPersonalAccessTokenOptions{ - Scopes: Ptr([]string{"api"}), - Name: Ptr("service_account_token"), + Scopes: Ptr([]string{"api"}), + Name: Ptr("service_account_token"), + ExpiresAt: Ptr("2024-06-12"), } pat, _, err := client.Groups.CreateServiceAccountPersonalAccessToken(1, 57, options) if err != nil { From f0156f08b847b12e6ed6b8cdf9a9014141f583f4 Mon Sep 17 00:00:00 2001 From: Dieter De Meyer Date: Wed, 3 Apr 2024 18:36:23 +0200 Subject: [PATCH 2/3] Fix type of ExpiresAt field --- group_serviceaccounts.go | 2 +- group_serviceaccounts_test.go | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/group_serviceaccounts.go b/group_serviceaccounts.go index 6593c1fbe..3ccb41b5e 100644 --- a/group_serviceaccounts.go +++ b/group_serviceaccounts.go @@ -64,7 +64,7 @@ func (s *GroupsService) CreateServiceAccount(gid interface{}, options ...Request type CreateServiceAccountPersonalAccessTokenOptions struct { Scopes *[]string `url:"scopes,omitempty" json:"scopes,omitempty"` Name *string `url:"name,omitempty" json:"name,omitempty"` - ExpiresAt *string `url:"expires_at,omitempty" json:"expires_at,omitempty"` + ExpiresAt *ISOTime `url:"expires_at,omitempty" json:"expires_at,omitempty"` } // CreateServiceAccountPersonalAccessToken add a new Personal Access Token for a diff --git a/group_serviceaccounts_test.go b/group_serviceaccounts_test.go index 7de0adf07..7b930e8cc 100644 --- a/group_serviceaccounts_test.go +++ b/group_serviceaccounts_test.go @@ -18,6 +18,7 @@ package gitlab import ( "fmt" + "github.com/stretchr/testify/require" "net/http" "reflect" "testing" @@ -72,10 +73,14 @@ func TestCreateServiceAccountPersonalAccessToken(t *testing.T) { "token":"random_token" }`) }) + + expireTime, err := ParseISOTime("2024-06-12") + require.NoError(t, err) + options := &CreateServiceAccountPersonalAccessTokenOptions{ Scopes: Ptr([]string{"api"}), Name: Ptr("service_account_token"), - ExpiresAt: Ptr("2024-06-12"), + ExpiresAt: Ptr(expireTime), } pat, _, err := client.Groups.CreateServiceAccountPersonalAccessToken(1, 57, options) if err != nil { From f21d2ce6c7f931ef2ab39777b43b9a9b8d86f541 Mon Sep 17 00:00:00 2001 From: Sander van Harmelen Date: Fri, 5 Apr 2024 09:07:15 +0200 Subject: [PATCH 3/3] Order the imports using goimports --- group_serviceaccounts_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/group_serviceaccounts_test.go b/group_serviceaccounts_test.go index 7b930e8cc..b878c8eba 100644 --- a/group_serviceaccounts_test.go +++ b/group_serviceaccounts_test.go @@ -18,11 +18,12 @@ package gitlab import ( "fmt" - "github.com/stretchr/testify/require" "net/http" "reflect" "testing" "time" + + "github.com/stretchr/testify/require" ) func TestCreateServiceAccount(t *testing.T) {