-
-
Notifications
You must be signed in to change notification settings - Fork 33
/
scope.go
59 lines (53 loc) · 1.23 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
58
59
package runn
import (
"errors"
"strings"
"sync"
)
type scopes struct {
readParent bool
readRemote bool
runExec bool
mu sync.RWMutex
}
const (
ScopeAllowReadParent = "read:parent"
ScopeAllowReadRemote = "read:remote"
ScopeAllowRunExec = "run:exec" //nostyle:repetition
ScopeDenyReadParent = "!read:parent"
ScopeDenyReadRemote = "!read:remote"
ScopeDenyRunExec = "!run:exec" //nostyle:repetition
)
var ErrInvalidScope = errors.New("invalid scope")
var globalScopes = &scopes{
readParent: false,
readRemote: false,
runExec: false,
}
func setScopes(scopes ...string) error {
globalScopes.mu.Lock()
defer globalScopes.mu.Unlock()
for _, s := range scopes {
splitted := strings.Split(strings.TrimSpace(s), ",")
for _, ss := range splitted {
switch ss {
case ScopeAllowReadParent:
globalScopes.readParent = true
case ScopeAllowReadRemote:
globalScopes.readRemote = true
case ScopeAllowRunExec:
globalScopes.runExec = true
case ScopeDenyReadParent:
globalScopes.readParent = false
case ScopeDenyReadRemote:
globalScopes.readRemote = false
case ScopeDenyRunExec:
globalScopes.runExec = false
case "":
default:
return ErrInvalidScope
}
}
}
return nil
}