-
Notifications
You must be signed in to change notification settings - Fork 2
/
tx_check_access.go
66 lines (55 loc) · 1.58 KB
/
tx_check_access.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
60
61
62
63
64
65
66
package cli
import (
"strconv"
"strings"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
gogotypes "github.com/cosmos/gogoproto/types"
"github.com/spf13/cobra"
"github.com/sourcenetwork/sourcehub/x/acp/types"
)
var _ = strconv.Itoa(0)
func CmdCheckAccess() *cobra.Command {
cmd := &cobra.Command{
Use: "check-access [policy-id] [subject] {resource:objId#permission}",
Short: "Broadcast message CheckAccess",
Args: cobra.MinimumNArgs(3),
RunE: func(cmd *cobra.Command, args []string) (err error) {
policyId := args[0]
subject := args[1]
var operations []*types.Operation
for _, operationStr := range args[2:] {
resource, operationStr, _ := strings.Cut(operationStr, ":")
objId, relation, _ := strings.Cut(operationStr, ":")
operation := &types.Operation{
Object: types.NewObject(resource, objId),
Permission: relation,
}
operations = append(operations, operation)
}
accessRequest := &types.AccessRequest{
Operations: operations,
Actor: &types.Actor{
Id: subject,
},
}
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
msg := &types.MsgCheckAccess{
Creator: clientCtx.GetFromAddress().String(),
PolicyId: policyId,
CreationTime: gogotypes.TimestampNow(),
AccessRequest: accessRequest,
}
if err := msg.ValidateBasic(); err != nil {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}