-
Notifications
You must be signed in to change notification settings - Fork 1
/
decisiontree.go
44 lines (37 loc) · 1.08 KB
/
decisiontree.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
package authorizer
import (
"github.com/aserto-dev/aserto/pkg/cc"
"github.com/aserto-dev/aserto/pkg/jsonx"
"github.com/aserto-dev/go-authorizer/aserto/authorizer/v2"
"github.com/aserto-dev/go-authorizer/aserto/authorizer/v2/api"
)
type DecisionTreeCmd struct {
AuthParams `embed:""`
Path string `name:"path" help:"policy package to evaluate"`
Decisions []string `name:"decisions" default:"*" help:"policy decisions to return"`
}
func (cmd *DecisionTreeCmd) Run(c *cc.CommonCtx) error {
client, err := c.AuthorizerClient()
if err != nil {
return err
}
resource, err := cmd.ResourceContext()
if err != nil {
return err
}
resp, err := client.Authorizer.DecisionTree(c.Context, &authorizer.DecisionTreeRequest{
PolicyContext: &api.PolicyContext{
Path: cmd.Path,
Decisions: cmd.Decisions,
},
IdentityContext: cmd.IdentityContext(),
ResourceContext: resource,
Options: &authorizer.DecisionTreeOptions{
PathSeparator: authorizer.PathSeparator_PATH_SEPARATOR_DOT,
},
})
if err != nil {
return err
}
return jsonx.OutputJSONPB(c.UI.Output(), resp)
}