package control import ( "encoding/hex" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client" "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/key" commonCmd "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/control" "github.com/spf13/cobra" ) const ( chainIDFlag = "chain-id" chainIDHexFlag = "chain-id-hex" ) var removeRuleCmd = &cobra.Command{ Use: "remove-rule", Short: "Remove local override", Long: "Remove local APE override of the node", Run: removeRule, } func removeRule(cmd *cobra.Command, _ []string) { pk := key.Get(cmd) chainID, _ := cmd.Flags().GetString(chainIDFlag) hexEncoded, _ := cmd.Flags().GetBool(chainIDHexFlag) chainIDRaw := []byte(chainID) if hexEncoded { var err error chainIDRaw, err = hex.DecodeString(chainID) commonCmd.ExitOnErr(cmd, "can't decode chain ID as hex: %w", err) } req := &control.RemoveChainLocalOverrideRequest{ Body: &control.RemoveChainLocalOverrideRequest_Body{ Target: parseTarget(cmd), ChainId: chainIDRaw, }, } signRequest(cmd, pk, req) cli := getClient(cmd, pk) var resp *control.RemoveChainLocalOverrideResponse var err error err = cli.ExecRaw(func(client *client.Client) error { resp, err = control.RemoveChainLocalOverride(client, req) return err }) commonCmd.ExitOnErr(cmd, "rpc error: %w", err) verifyResponse(cmd, resp.GetSignature(), resp.GetBody()) cmd.Println("Rule has been removed.") } func initControlRemoveRuleCmd() { initControlFlags(removeRuleCmd) ff := removeRuleCmd.Flags() ff.String(targetNameFlag, "", targetNameDesc) ff.String(targetTypeFlag, "", targetTypeDesc) _ = removeRuleCmd.MarkFlagRequired(targetTypeFlag) ff.String(chainIDFlag, "", "Chain id") ff.Bool(chainIDHexFlag, false, "Flag to parse chain ID as hex") }