-
Notifications
You must be signed in to change notification settings - Fork 3
/
scope.go
57 lines (46 loc) · 1.32 KB
/
scope.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
package main
import "net/url"
// Scope define the scope of the personal access token a minimum of api must be set
type Scope struct {
API bool
ReadUser bool
Sudo bool
ReadRegistry bool
}
const gitlabPersonalAccessTokenScope = "personal_access_token[scopes][]"
const apiScope = "api"
const readUserScope = "read_user"
const sudoScope = "sudo"
const readRegistryScope = "read_registry"
// NewScope exports the permission for gitlab that is currently requested for the token
func NewScope(values url.Values, s Scope) url.Values {
if s.API == true {
key, value := addAPIScope()
values.Add(key, value)
}
if s.ReadUser == true {
key, value := addReadUserScope()
values.Add(key, value)
}
if s.Sudo == true {
key, value := addSudoScope()
values.Add(key, value)
}
if s.ReadRegistry == true {
key, value := addReadRegistryScope()
values.Add(key, value)
}
return values
}
func addAPIScope() (key string, value string) {
return gitlabPersonalAccessTokenScope, apiScope
}
func addReadUserScope() (key string, value string) {
return gitlabPersonalAccessTokenScope, readUserScope
}
func addSudoScope() (key string, value string) {
return gitlabPersonalAccessTokenScope, sudoScope
}
func addReadRegistryScope() (key string, value string) {
return gitlabPersonalAccessTokenScope, readRegistryScope
}