Skip to content

Commit

Permalink
Update README and token access and types
Browse files Browse the repository at this point in the history
  • Loading branch information
ilijamt committed Dec 12, 2024
1 parent 8fab913 commit bff6418
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 31 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ Depending on the type of token you have different scopes:
* `Project` - https://docs.gitlab.com/ee/user/project/settings/project_access_tokens.html#scopes-for-a-project-access-token
* `Group` - https://docs.gitlab.com/ee/user/group/settings/group_access_tokens.html#scopes-for-a-group-access-token
* `Deploy` - https://docs.gitlab.com/ee/user/project/deploy_tokens/#scope
#### token_types
Can be
Expand Down
6 changes: 3 additions & 3 deletions helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,15 @@ func (i *inMemoryClient) CreatePipelineProjectTriggerAccessToken(ctx context.Con
}
i.internalCounter++
var tokenId = i.internalCounter
key := fmt.Sprintf("%s_%v_%v", gitlab.TokenPipelineProjectTrigger.String(), projectId, tokenId)
key := fmt.Sprintf("%s_%v_%v", gitlab.TokenTypePipelineProjectTrigger.String(), projectId, tokenId)
var entryToken = gitlab.EntryToken{
TokenID: tokenId,
UserID: projectId,
ParentID: "",
Path: strconv.Itoa(projectId),
Name: name,
Token: fmt.Sprintf("glptt-%s", uuid.New().String()),
TokenType: gitlab.TokenPipelineProjectTrigger,
TokenType: gitlab.TokenTypePipelineProjectTrigger,
CreatedAt: g.Ptr(time.Now()),
}
i.accessTokens[key] = entryToken
Expand All @@ -208,7 +208,7 @@ func (i *inMemoryClient) RevokePipelineProjectTriggerAccessToken(ctx context.Con
if i.revokePipelineProjectTriggerAccessTokenError {
return fmt.Errorf("RevokePipelineProjectTriggerAccessToken")
}
key := fmt.Sprintf("%s_%v_%v", gitlab.TokenPipelineProjectTrigger.String(), projectId, tokenId)
key := fmt.Sprintf("%s_%v_%v", gitlab.TokenTypePipelineProjectTrigger.String(), projectId, tokenId)
delete(i.accessTokens, key)
return nil
}
Expand Down
23 changes: 15 additions & 8 deletions path_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,14 @@ func (b *Backend) pathRolesWrite(ctx context.Context, req *logical.Request, data
case TokenTypeGroupServiceAccount:
validAccessLevels = ValidGroupServiceAccountAccessLevels
skipFields = append(skipFields, "access_level")
case TokenPipelineProjectTrigger:
case TokenTypePipelineProjectTrigger:
validAccessLevels = ValidPipelineProjectTriggerAccessLevels
skipFields = append(skipFields, "access_level", "scopes")
case TokenDeploy:
validAccessLevels = ValidDeployTokenScopes
case TokenTypeProjectDeploy:
validAccessLevels = ValidProjectDeployAccessLevels
skipFields = append(skipFields, "access_level")
case TokenTypeGroupDeploy:
validAccessLevels = ValidGroupDeployAccessLevels
skipFields = append(skipFields, "access_level")

Check warning on line 277 in path_role.go

View check run for this annotation

Codecov / codecov/patch

path_role.go#L269-L277

Added lines #L269 - L277 were not covered by tests
}

Expand Down Expand Up @@ -313,14 +316,18 @@ func (b *Backend) pathRolesWrite(ctx context.Context, req *logical.Request, data
if tokenType == TokenTypePersonal || tokenType == TokenTypeUserServiceAccount || tokenType == TokenTypeGroupServiceAccount {
validScopes = append(validScopes, ValidPersonalTokenScopes...)
}
if tokenType == TokenTypeUserServiceAccount {

switch tokenType {
case TokenTypeUserServiceAccount:
validScopes = append(validScopes, ValidUserServiceAccountTokenScopes...)
}
if tokenType == TokenTypeGroupServiceAccount {
case TokenTypeGroupServiceAccount:
validScopes = append(validScopes, ValidGroupServiceAccountTokenScopes...)
}
if tokenType == TokenPipelineProjectTrigger {
case TokenTypePipelineProjectTrigger:
validScopes = []string{}
case TokenTypeProjectDeploy:
validScopes = ValidProjectDeployTokenScopes
case TokenTypeGroupDeploy:
validScopes = ValidGroupDeployTokenScopes

Check warning on line 330 in path_role.go

View check run for this annotation

Codecov / codecov/patch

path_role.go#L325-L330

Added lines #L325 - L330 were not covered by tests
}

for _, scope := range role.Scopes {
Expand Down
7 changes: 4 additions & 3 deletions type_access_level.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ var (
AccessLevelMaintainerPermissions.String(),
AccessLevelOwnerPermissions.String(),
}
ValidPipelineProjectTriggerAccessLevels = []string{
AccessLevelUnknown.String(),
}

ValidPipelineProjectTriggerAccessLevels = []string{AccessLevelUnknown.String()}
ValidProjectDeployAccessLevels = []string{AccessLevelUnknown.String()}
ValidGroupDeployAccessLevels = []string{AccessLevelUnknown.String()}
)

func (i AccessLevel) String() string {
Expand Down
22 changes: 11 additions & 11 deletions type_token_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import (
type TokenType string

const (
TokenTypePersonal = TokenType("personal")
TokenTypeProject = TokenType("project")
TokenTypeGroup = TokenType("group")
TokenTypeUserServiceAccount = TokenType("user-service-account")
TokenTypeGroupServiceAccount = TokenType("group-service-account")
TokenPipelineProjectTrigger = TokenType("pipeline-project-trigger")
TokenProjectDeploy = TokenType("project-deploy")
TokenGroupDeploy = TokenType("group-deploy")
TokenTypePersonal = TokenType("personal")
TokenTypeProject = TokenType("project")
TokenTypeGroup = TokenType("group")
TokenTypeUserServiceAccount = TokenType("user-service-account")
TokenTypeGroupServiceAccount = TokenType("group-service-account")
TokenTypePipelineProjectTrigger = TokenType("pipeline-project-trigger")
TokenTypeProjectDeploy = TokenType("project-deploy")
TokenTypeGroupDeploy = TokenType("group-deploy")

TokenTypeUnknown = TokenType("")
)
Expand All @@ -30,9 +30,9 @@ var (
TokenTypeGroup.String(),
TokenTypeUserServiceAccount.String(),
TokenTypeGroupServiceAccount.String(),
TokenPipelineProjectTrigger.String(),
TokenProjectDeploy.String(),
TokenGroupDeploy.String(),
TokenTypePipelineProjectTrigger.String(),
TokenTypeProjectDeploy.String(),
TokenTypeGroupDeploy.String(),
}
)

Expand Down
12 changes: 6 additions & 6 deletions type_token_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ func TestTokenType(t *testing.T) {
input: gitlab.TokenTypeGroupServiceAccount.String(),
},
{
expected: gitlab.TokenPipelineProjectTrigger,
input: gitlab.TokenPipelineProjectTrigger.String(),
expected: gitlab.TokenTypePipelineProjectTrigger,
input: gitlab.TokenTypePipelineProjectTrigger.String(),
},
{
expected: gitlab.TokenProjectDeploy,
input: gitlab.TokenProjectDeploy.String(),
expected: gitlab.TokenTypeProjectDeploy,
input: gitlab.TokenTypeProjectDeploy.String(),
},
{
expected: gitlab.TokenGroupDeploy,
input: gitlab.TokenGroupDeploy.String(),
expected: gitlab.TokenTypeGroupDeploy,
input: gitlab.TokenTypeGroupDeploy.String(),
},
{
expected: gitlab.TokenTypeUnknown,
Expand Down

0 comments on commit bff6418

Please sign in to comment.