Skip to content

Commit

Permalink
Merge pull request #1907 from dieterdemeyer/service-account-token-exp…
Browse files Browse the repository at this point in the history
…iration-support

Add support for service account token expiration
  • Loading branch information
svanharmelen committed Apr 5, 2024
2 parents 1ccfef0 + f21d2ce commit 05c7374
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
5 changes: 3 additions & 2 deletions group_serviceaccounts.go
Expand Up @@ -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 *ISOTime `url:"expires_at,omitempty" json:"expires_at,omitempty"`
}

// CreateServiceAccountPersonalAccessToken add a new Personal Access Token for a
Expand Down
11 changes: 9 additions & 2 deletions group_serviceaccounts_test.go
Expand Up @@ -22,6 +22,8 @@ import (
"reflect"
"testing"
"time"

"github.com/stretchr/testify/require"
)

func TestCreateServiceAccount(t *testing.T) {
Expand Down Expand Up @@ -72,9 +74,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"),
Scopes: Ptr([]string{"api"}),
Name: Ptr("service_account_token"),
ExpiresAt: Ptr(expireTime),
}
pat, _, err := client.Groups.CreateServiceAccountPersonalAccessToken(1, 57, options)
if err != nil {
Expand Down

0 comments on commit 05c7374

Please sign in to comment.