2023-10-31 08:55:42 +00:00
|
|
|
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"
|
|
|
|
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"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
chainIDFlag = "chain-id"
|
|
|
|
)
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
chainID, _ := cmd.Flags().GetString(chainIDFlag)
|
|
|
|
|
|
|
|
req := &control.RemoveChainLocalOverrideRequest{
|
|
|
|
Body: &control.RemoveChainLocalOverrideRequest_Body{
|
2023-12-05 09:11:28 +00:00
|
|
|
Target: &control.ChainTarget{
|
2023-12-13 12:25:47 +00:00
|
|
|
Name: cidStr,
|
2023-12-05 09:11:28 +00:00
|
|
|
Type: control.ChainTarget_CONTAINER,
|
|
|
|
},
|
2023-12-21 12:05:45 +00:00
|
|
|
ChainId: []byte(chainID),
|
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())
|
|
|
|
|
2023-12-11 10:18:34 +00:00
|
|
|
if resp.GetBody().GetRemoved() {
|
2023-10-31 08:55:42 +00:00
|
|
|
cmd.Println("Rule has been removed.")
|
|
|
|
} else {
|
|
|
|
cmd.Println("Rule has not been removed.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func initControlRemoveRuleCmd() {
|
|
|
|
initControlFlags(removeRuleCmd)
|
|
|
|
|
|
|
|
ff := removeRuleCmd.Flags()
|
|
|
|
ff.String(commonflags.CIDFlag, "", commonflags.CIDFlagUsage)
|
|
|
|
ff.String(chainIDFlag, "", "Chain id")
|
|
|
|
}
|