-
Notifications
You must be signed in to change notification settings - Fork 111
/
statement.go
38 lines (33 loc) · 994 Bytes
/
statement.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
package storage
import (
"errors"
)
// Statement must have at least a role OR a non-empty actions list
type Statement struct {
Actions []string `json:"actions"`
Resources []string `json:"resources"`
Role string `json:"role"`
Projects []string `json:"projects"`
Effect Effect `json:"effect"`
}
// NewStatement is a factory for creating a Statement storage object that also does
// validation around what a valid statement is in terms of our storage layer.
func NewStatement(effect Effect, role string, projects, resources, actions []string) (Statement, error) {
if actions == nil {
actions = []string{}
}
if resources == nil {
resources = []string{}
}
if role == "" && len(actions) == 0 {
return Statement{},
errors.New("unsupported statement variant: you must pass a role, a non-empty array of actions, or both")
}
return Statement{
Effect: effect,
Role: role,
Projects: projects,
Actions: actions,
Resources: resources,
}, nil
}