forked from TrueCloudLab/frostfs-node
67 lines
1.8 KiB
Go
67 lines
1.8 KiB
Go
|
package apemanager
|
||
|
|
||
|
import (
|
||
|
"encoding/hex"
|
||
|
"errors"
|
||
|
|
||
|
internalclient "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/client"
|
||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/commonflags"
|
||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/key"
|
||
|
commonCmd "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common"
|
||
|
client_sdk "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client"
|
||
|
"github.com/spf13/cobra"
|
||
|
)
|
||
|
|
||
|
var (
|
||
|
errEmptyChainID = errors.New("chain id cannot be empty")
|
||
|
|
||
|
removeCmd = &cobra.Command{
|
||
|
Use: "remove",
|
||
|
Short: "Remove rule chain for a target",
|
||
|
Run: remove,
|
||
|
PersistentPreRun: func(cmd *cobra.Command, _ []string) {
|
||
|
commonflags.Bind(cmd)
|
||
|
},
|
||
|
}
|
||
|
)
|
||
|
|
||
|
func remove(cmd *cobra.Command, _ []string) {
|
||
|
target := parseTarget(cmd)
|
||
|
|
||
|
key := key.Get(cmd)
|
||
|
cli := internalclient.GetSDKClientByFlag(cmd, key, commonflags.RPC)
|
||
|
|
||
|
chainID, _ := cmd.Flags().GetString(chainIDFlag)
|
||
|
if chainID == "" {
|
||
|
commonCmd.ExitOnErr(cmd, "read chain id error: %w", errEmptyChainID)
|
||
|
}
|
||
|
chainIDRaw := []byte(chainID)
|
||
|
|
||
|
hexEncoded, _ := cmd.Flags().GetBool(chainIDHexFlag)
|
||
|
if hexEncoded {
|
||
|
var err error
|
||
|
chainIDRaw, err = hex.DecodeString(chainID)
|
||
|
commonCmd.ExitOnErr(cmd, "can't decode chain ID as hex: %w", err)
|
||
|
}
|
||
|
|
||
|
_, err := cli.APEManagerRemoveChain(cmd.Context(), client_sdk.PrmAPEManagerRemoveChain{
|
||
|
ChainTarget: target,
|
||
|
ChainID: chainIDRaw,
|
||
|
})
|
||
|
|
||
|
commonCmd.ExitOnErr(cmd, "remove chain error: %w", err)
|
||
|
|
||
|
cmd.Println("\nRule has been removed.")
|
||
|
}
|
||
|
|
||
|
func initRemoveCmd() {
|
||
|
commonflags.Init(removeCmd)
|
||
|
|
||
|
ff := removeCmd.Flags()
|
||
|
ff.String(targetNameFlag, "", targetNameDesc)
|
||
|
ff.String(targetTypeFlag, "", targetTypeDesc)
|
||
|
_ = removeCmd.MarkFlagRequired(targetTypeFlag)
|
||
|
ff.String(chainIDFlag, "", "Chain id")
|
||
|
ff.Bool(chainIDHexFlag, false, "Flag to parse chain ID as hex")
|
||
|
}
|