From 11fde3cde4d19a274a953a5ea02d5f3aea7c3041 Mon Sep 17 00:00:00 2001 From: Anton Nikiforov Date: Tue, 12 Mar 2024 13:43:16 +0300 Subject: [PATCH] [#976] cli: Allow to remove all chains by target Signed-off-by: Anton Nikiforov --- .../modules/control/remove_rule.go | 46 +++++++++++++++---- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/cmd/frostfs-cli/modules/control/remove_rule.go b/cmd/frostfs-cli/modules/control/remove_rule.go index 7684ac1dc..4189ea76b 100644 --- a/cmd/frostfs-cli/modules/control/remove_rule.go +++ b/cmd/frostfs-cli/modules/control/remove_rule.go @@ -2,6 +2,7 @@ package control import ( "encoding/hex" + "errors" "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/rpc/client" "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/key" @@ -13,21 +14,48 @@ import ( const ( chainIDFlag = "chain-id" chainIDHexFlag = "chain-id-hex" + allFlag = "all" ) -var removeRuleCmd = &cobra.Command{ - Use: "remove-rule", - Short: "Remove local override", - Long: "Remove local APE override of the node", - Run: removeRule, -} +var ( + errEmptyChainID = errors.New("chain id cannot be empty") + + 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) + hexEncoded, _ := cmd.Flags().GetBool(chainIDHexFlag) + removeAll, _ := cmd.Flags().GetBool(allFlag) + if removeAll { + req := &control.RemoveChainLocalOverridesByTargetRequest{ + Body: &control.RemoveChainLocalOverridesByTargetRequest_Body{ + Target: parseTarget(cmd), + }, + } + signRequest(cmd, pk, req) + cli := getClient(cmd, pk) + var resp *control.RemoveChainLocalOverridesByTargetResponse + var err error + err = cli.ExecRaw(func(client *client.Client) error { + resp, err = control.RemoveChainLocalOverridesByTarget(client, req) + return err + }) + commonCmd.ExitOnErr(cmd, "rpc error: %w", err) + verifyResponse(cmd, resp.GetSignature(), resp.GetBody()) + cmd.Println("All rules have been removed.") + return + } chainID, _ := cmd.Flags().GetString(chainIDFlag) - hexEncoded, _ := cmd.Flags().GetBool(chainIDHexFlag) - + if chainID == "" { + commonCmd.ExitOnErr(cmd, "read chain id error: %w", errEmptyChainID) + } chainIDRaw := []byte(chainID) if hexEncoded { @@ -69,4 +97,6 @@ func initControlRemoveRuleCmd() { _ = removeRuleCmd.MarkFlagRequired(targetTypeFlag) ff.String(chainIDFlag, "", "Chain id") ff.Bool(chainIDHexFlag, false, "Flag to parse chain ID as hex") + ff.Bool(allFlag, false, "Remove all chains") + removeRuleCmd.MarkFlagsMutuallyExclusive(allFlag, chainIDFlag) }