-
Notifications
You must be signed in to change notification settings - Fork 352
/
actions.go
88 lines (79 loc) · 2.98 KB
/
actions.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package permissions
import (
"errors"
"fmt"
"strings"
)
var (
ErrInvalidAction = errors.New("invalid action")
ErrInvalidServiceName = errors.New("invalid service name")
)
const (
ReadRepositoryAction = "fs:ReadRepository"
CreateRepositoryAction = "fs:CreateRepository"
AttachStorageNamespace = "fs:AttachStorageNamespace"
DeleteRepositoryAction = "fs:DeleteRepository"
ListRepositoriesAction = "fs:ListRepositories"
ReadObjectAction = "fs:ReadObject"
WriteObjectAction = "fs:WriteObject"
DeleteObjectAction = "fs:DeleteObject"
ListObjectsAction = "fs:ListObjects"
CreateCommitAction = "fs:CreateCommit"
ReadCommitAction = "fs:ReadCommit"
ListCommitsAction = "fs:ListCommits"
CreateBranchAction = "fs:CreateBranch"
DeleteBranchAction = "fs:DeleteBranch"
ReadBranchAction = "fs:ReadBranch"
RevertBranchAction = "fs:RevertBranch"
ListBranchesAction = "fs:ListBranches"
CreateTagAction = "fs:CreateTag"
DeleteTagAction = "fs:DeleteTag"
ReadTagAction = "fs:ReadTag"
ListTagsAction = "fs:ListTags"
ReadStorageConfiguration = "fs:ReadConfig"
ReadUserAction = "auth:ReadUser"
CreateUserAction = "auth:CreateUser"
DeleteUserAction = "auth:DeleteUser"
ListUsersAction = "auth:ListUsers"
ReadGroupAction = "auth:ReadGroup"
CreateGroupAction = "auth:CreateGroup"
DeleteGroupAction = "auth:DeleteGroup"
ListGroupsAction = "auth:ListGroups"
AddGroupMemberAction = "auth:AddGroupMember"
RemoveGroupMemberAction = "auth:RemoveGroupMember"
ReadPolicyAction = "auth:ReadPolicy"
CreatePolicyAction = "auth:CreatePolicy"
UpdatePolicyAction = "auth:UpdatePolicy"
DeletePolicyAction = "auth:DeletePolicy"
ListPoliciesAction = "auth:ListPolicies"
AttachPolicyAction = "auth:AttachPolicy"
DetachPolicyAction = "auth:DetachPolicy"
ReadCredentialsAction = "auth:ReadCredentials"
CreateCredentialsAction = "auth:CreateCredentials"
DeleteCredentialsAction = "auth:DeleteCredentials"
ListCredentialsAction = "auth:ListCredentials"
ReadActionsAction = "ci:ReadAction"
PrepareGarbageCollectionCommitsAction = "retention:PrepareGarbageCollectionCommits"
GetGarbageCollectionRulesAction = "retention:GetGarbageCollectionRules"
SetGarbageCollectionRulesAction = "retention:SetGarbageCollectionRules"
GetBranchProtectionRulesAction = "branches:GetBranchProtectionRules"
SetBranchProtectionRulesAction = "branches:SetBranchProtectionRules"
)
var serviceSet = map[string]struct{}{
"fs": {},
"auth": {},
"ci": {},
"retention": {},
"branches": {},
}
func IsValidAction(name string) error {
parts := strings.Split(name, ":")
const actionParts = 2
if len(parts) != actionParts {
return fmt.Errorf("%s: %w", name, ErrInvalidAction)
}
if _, ok := serviceSet[parts[0]]; !ok {
return fmt.Errorf("%s: %w", name, ErrInvalidServiceName)
}
return nil
}