-
Notifications
You must be signed in to change notification settings - Fork 1
/
get-policy.go
30 lines (26 loc) · 922 Bytes
/
get-policy.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
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 GetPolicyCmd struct {
PolicyID string `name:"policy-id" required:"" help:"policy id"`
PolicyName string `name:"policy-name" required:"" help:"policy name"`
InstanceLabel string `name:"instance-label" required:"" help:"policy's instance label"`
}
func (cmd *GetPolicyCmd) Run(c *cc.CommonCtx) error {
client, err := c.AuthorizerClient()
if err != nil {
return err
}
resp, err := client.Authorizer.GetPolicy(c.Context, &authorizer.GetPolicyRequest{
Id: cmd.PolicyID,
PolicyInstance: &api.PolicyInstance{Name: cmd.PolicyName, InstanceLabel: cmd.InstanceLabel},
})
if err != nil {
return err
}
return jsonx.OutputJSONPB(c.UI.Output(), resp)
}