package control import ( "crypto/sha256" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client" "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/commonflags" "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/key" "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/modules/util" commonCmd "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/control" cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id" apechain "git.frostfs.info/TrueCloudLab/policy-engine/pkg/chain" "github.com/spf13/cobra" ) var listRulesCmd = &cobra.Command{ Use: "list-rules", Short: "List local overrides", Long: "List local APE overrides of the node", Run: listRules, } func listRules(cmd *cobra.Command, _ []string) { pk := key.Get(cmd) var cnr cid.ID cidStr, _ := cmd.Flags().GetString(commonflags.CIDFlag) commonCmd.ExitOnErr(cmd, "can't decode container ID: %w", cnr.DecodeString(cidStr)) rawCID := make([]byte, sha256.Size) cnr.Encode(rawCID) req := &control.ListChainLocalOverridesRequest{ Body: &control.ListChainLocalOverridesRequest_Body{ Target: &control.ChainTarget{ Name: cidStr, Type: control.ChainTarget_CONTAINER, }, }, } signRequest(cmd, pk, req) cli := getClient(cmd, pk) var resp *control.ListChainLocalOverridesResponse var err error err = cli.ExecRaw(func(client *client.Client) error { resp, err = control.ListChainLocalOverrides(client, req) return err }) commonCmd.ExitOnErr(cmd, "rpc error: %w", err) verifyResponse(cmd, resp.GetSignature(), resp.GetBody()) chains := resp.GetBody().GetChains() if len(chains) == 0 { cmd.Println("Local overrides are not defined for the container.") return } for _, c := range chains { var chain apechain.Chain commonCmd.ExitOnErr(cmd, "decode error: %w", chain.DecodeBytes(c)) util.PrintHumanReadableAPEChain(cmd, &chain) } } func initControlListRulesCmd() { initControlFlags(listRulesCmd) ff := listRulesCmd.Flags() ff.String(commonflags.CIDFlag, "", commonflags.CIDFlagUsage) }