Skip to content

Commit

Permalink
Project Access Token access level
Browse files Browse the repository at this point in the history
  • Loading branch information
myoshida committed Jul 17, 2021
1 parent a61604b commit ec657f8
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 38 deletions.
26 changes: 14 additions & 12 deletions project_access_tokens.go
Expand Up @@ -34,15 +34,16 @@ type ProjectAccessTokensService struct {
//
// GitLab API docs: https://docs.gitlab.com/ee/api/resource_access_tokens.html
type ProjectAccessToken struct {
ID int `json:"id"`
UserID int `json:"user_id"`
Name string `json:"name"`
Scopes []string `json:"scopes"`
CreatedAt *time.Time `json:"created_at"`
ExpiresAt *ISOTime `json:"expires_at"`
Active bool `json:"active"`
Revoked bool `json:"revoked"`
Token string `json:"token"`
ID int `json:"id"`
UserID int `json:"user_id"`
Name string `json:"name"`
Scopes []string `json:"scopes"`
CreatedAt *time.Time `json:"created_at"`
ExpiresAt *ISOTime `json:"expires_at"`
Active bool `json:"active"`
Revoked bool `json:"revoked"`
Token string `json:"token"`
AccessLevel int `json:"access_level"`
}

func (v ProjectAccessToken) String() string {
Expand Down Expand Up @@ -88,9 +89,10 @@ func (s *ProjectAccessTokensService) ListProjectAccessTokens(pid interface{}, op
// GitLab API docs:
// https://docs.gitlab.com/ee/api/resource_access_tokens.html#create-a-project-access-token
type CreateProjectAccessTokenOptions struct {
Name *string `url:"name,omitempty" json:"name,omitempty"`
Scopes []string `url:"scopes,omitempty" json:"scopes,omitempty"`
ExpiresAt *ISOTime `url:"expires_at,omitempty" json:"expires_at,omitempty"`
Name *string `url:"name,omitempty" json:"name,omitempty"`
Scopes []string `url:"scopes,omitempty" json:"scopes,omitempty"`
AccessLevel int `url:"access_level,omitempty" json:"access_level,omitempty"`
ExpiresAt *ISOTime `url:"expires_at,omitempty" json:"expires_at,omitempty"`
}

// CreateProjectAccessToken creates a new Project Access Token.
Expand Down
49 changes: 26 additions & 23 deletions project_access_tokens_test.go
Expand Up @@ -48,22 +48,24 @@ func TestListProjectAccessTokens(t *testing.T) {

want := []*ProjectAccessToken{
{
ID: 1876,
UserID: 2453,
Name: "token 10",
Scopes: []string{"api", "read_api", "read_repository", "write_repository"},
CreatedAt: &time1,
Active: true,
Revoked: false,
ID: 1876,
UserID: 2453,
Name: "token 10",
Scopes: []string{"api", "read_api", "read_repository", "write_repository"},
CreatedAt: &time1,
Active: true,
Revoked: false,
AccessLevel: 40,
},
{
ID: 1877,
UserID: 2456,
Name: "token 8",
Scopes: []string{"api", "read_api", "read_repository", "write_repository"},
CreatedAt: &time2,
Active: true,
Revoked: false,
ID: 1877,
UserID: 2456,
Name: "token 8",
Scopes: []string{"api", "read_api", "read_repository", "write_repository"},
CreatedAt: &time2,
Active: true,
Revoked: false,
AccessLevel: 30,
},
}

Expand Down Expand Up @@ -91,15 +93,16 @@ func TestCreateProjectAccessToken(t *testing.T) {
t.Errorf("ProjectAccessTokens.CreateProjectAccessToken returned error: %v", err)
}
want := &ProjectAccessToken{
ID: 1876,
UserID: 2453,
Name: "token 10",
Scopes: []string{"api", "read_api", "read_repository", "write_repository"},
ExpiresAt: nil,
CreatedAt: &time1,
Active: true,
Revoked: false,
Token: "2UsevZE1x1ZdFZW4MNzH",
ID: 1876,
UserID: 2453,
Name: "token 10",
Scopes: []string{"api", "read_api", "read_repository", "write_repository"},
ExpiresAt: nil,
CreatedAt: &time1,
Active: true,
Revoked: false,
Token: "2UsevZE1x1ZdFZW4MNzH",
AccessLevel: 40,
}

if !reflect.DeepEqual(want, projectAccessToken) {
Expand Down
3 changes: 2 additions & 1 deletion testdata/create_project_access_token.json
Expand Up @@ -12,5 +12,6 @@
"user_id": 2453,
"active": true,
"expires_at": null,
"token": "2UsevZE1x1ZdFZW4MNzH"
"token": "2UsevZE1x1ZdFZW4MNzH",
"access_level": 40
}
6 changes: 4 additions & 2 deletions testdata/list_project_access_tokens.json
Expand Up @@ -12,7 +12,8 @@
],
"user_id": 2453,
"active": true,
"expires_at": null
"expires_at": null,
"access_level": 40
},
{
"id": 1877,
Expand All @@ -27,6 +28,7 @@
],
"user_id": 2456,
"active": true,
"expires_at": null
"expires_at": null,
"access_level": 30
}
]

0 comments on commit ec657f8

Please sign in to comment.