2023-10-31 08:55:42 +00:00
|
|
|
package control
|
|
|
|
|
|
|
|
import (
|
2023-12-21 12:55:09 +00:00
|
|
|
"encoding/hex"
|
2024-03-12 10:43:16 +00:00
|
|
|
"errors"
|
2023-10-31 08:55:42 +00:00
|
|
|
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/key"
|
|
|
|
commonCmd "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common"
|
2024-11-18 10:33:47 +00:00
|
|
|
apecmd "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common/ape"
|
2023-10-31 08:55:42 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/control"
|
2024-11-07 14:32:10 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/rpc/client"
|
2023-10-31 08:55:42 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2024-03-12 10:43:16 +00:00
|
|
|
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,
|
|
|
|
}
|
|
|
|
)
|
2023-10-31 08:55:42 +00:00
|
|
|
|
|
|
|
func removeRule(cmd *cobra.Command, _ []string) {
|
|
|
|
pk := key.Get(cmd)
|
2024-11-18 10:33:47 +00:00
|
|
|
hexEncoded, _ := cmd.Flags().GetBool(apecmd.ChainIDHexFlag)
|
|
|
|
removeAll, _ := cmd.Flags().GetBool(apecmd.AllFlag)
|
2024-03-12 10:43:16 +00:00
|
|
|
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
|
|
|
|
}
|
2023-12-21 12:55:09 +00:00
|
|
|
|
2024-11-18 10:33:47 +00:00
|
|
|
chainID, _ := cmd.Flags().GetString(apecmd.ChainIDFlag)
|
2024-03-12 10:43:16 +00:00
|
|
|
if chainID == "" {
|
|
|
|
commonCmd.ExitOnErr(cmd, "read chain id error: %w", errEmptyChainID)
|
|
|
|
}
|
2023-12-21 12:55:09 +00:00
|
|
|
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)
|
|
|
|
}
|
2023-10-31 08:55:42 +00:00
|
|
|
|
|
|
|
req := &control.RemoveChainLocalOverrideRequest{
|
|
|
|
Body: &control.RemoveChainLocalOverrideRequest_Body{
|
2024-01-12 14:44:27 +00:00
|
|
|
Target: parseTarget(cmd),
|
2023-12-21 12:55:09 +00:00
|
|
|
ChainId: chainIDRaw,
|
2023-10-31 08:55:42 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
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())
|
|
|
|
|
2024-02-27 09:27:09 +00:00
|
|
|
cmd.Println("Rule has been removed.")
|
2023-10-31 08:55:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func initControlRemoveRuleCmd() {
|
|
|
|
initControlFlags(removeRuleCmd)
|
|
|
|
|
|
|
|
ff := removeRuleCmd.Flags()
|
2024-11-18 10:33:47 +00:00
|
|
|
ff.String(apecmd.TargetNameFlag, "", apecmd.TargetNameFlagDesc)
|
|
|
|
ff.String(apecmd.TargetTypeFlag, "", apecmd.TargetTypeFlagDesc)
|
|
|
|
_ = removeRuleCmd.MarkFlagRequired(apecmd.TargetTypeFlag)
|
|
|
|
ff.String(apecmd.ChainIDFlag, "", apecmd.ChainIDFlagDesc)
|
|
|
|
ff.Bool(apecmd.ChainIDHexFlag, false, apecmd.ChainIDHexFlagDesc)
|
|
|
|
ff.Bool(apecmd.AllFlag, false, "Remove all chains")
|
|
|
|
removeRuleCmd.MarkFlagsMutuallyExclusive(apecmd.AllFlag, apecmd.ChainIDFlag)
|
2023-10-31 08:55:42 +00:00
|
|
|
}
|