-
Notifications
You must be signed in to change notification settings - Fork 23
/
list.go
59 lines (50 loc) · 1.56 KB
/
list.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 authorizer
import (
"io"
"github.com/aserto-dev/go-authorizer/aserto/authorizer/v2"
"github.com/aserto-dev/go-authorizer/aserto/authorizer/v2/api"
"github.com/aserto-dev/topaz/pkg/cli/cc"
"github.com/aserto-dev/topaz/pkg/cli/clients"
"github.com/aserto-dev/topaz/pkg/cli/jsonx"
"github.com/pkg/errors"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/fieldmaskpb"
)
type ListPoliciesCmd struct {
Request string `arg:"" type:"string" name:"request" optional:"" help:"json request or file path to list request or '-' to read from stdin"`
Template bool `name:"template" short:"t" help:"prints a check permission request template on stdout"`
clients.AuthorizerConfig
}
func (cmd *ListPoliciesCmd) Run(c *cc.CommonCtx) error {
if cmd.Template {
return cmd.print(c.UI.Output())
}
client, err := clients.NewAuthorizerClient(c, &cmd.AuthorizerConfig)
if err != nil {
return errors.Wrap(err, "failed to get authorizer client")
}
var req authorizer.ListPoliciesRequest
err = clients.UnmarshalRequest(cmd.Request, &req)
if err != nil {
return err
}
resp, err := client.ListPolicies(c.Context, &req)
if err != nil {
return err
}
return jsonx.OutputJSONPB(c.UI.Output(), resp)
}
func (cmd *ListPoliciesCmd) template() proto.Message {
return &authorizer.ListPoliciesRequest{
FieldMask: &fieldmaskpb.FieldMask{
Paths: []string{},
},
PolicyInstance: &api.PolicyInstance{
Name: "",
InstanceLabel: "",
},
}
}
func (cmd *ListPoliciesCmd) print(w io.Writer) error {
return jsonx.OutputJSONPB(w, cmd.template())
}