-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtype_token_type.go
52 lines (43 loc) · 1.32 KB
/
type_token_type.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package gitlab
import (
"errors"
"fmt"
"slices"
)
type TokenType string
const (
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("")
)
var (
ErrUnknownTokenType = errors.New("unknown token type")
validTokenTypes = []string{
TokenTypePersonal.String(),
TokenTypeProject.String(),
TokenTypeGroup.String(),
TokenTypeUserServiceAccount.String(),
TokenTypeGroupServiceAccount.String(),
TokenTypePipelineProjectTrigger.String(),
TokenTypeProjectDeploy.String(),
TokenTypeGroupDeploy.String(),
}
)
func (i TokenType) String() string {
return string(i)
}
func (i TokenType) Value() string {
return i.String()
}
func TokenTypeParse(value string) (TokenType, error) {
if slices.Contains(validTokenTypes, value) {
return TokenType(value), nil
}
return TokenTypeUnknown, fmt.Errorf("failed to parse '%s': %w", value, ErrUnknownTokenType)
}