2023-07-11 09:43:48 +00:00
|
|
|
package tree
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/sha256"
|
|
|
|
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/common"
|
|
|
|
"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/tree"
|
|
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
var removeCmd = &cobra.Command{
|
|
|
|
Use: "remove",
|
|
|
|
Short: "Remove node",
|
|
|
|
Run: remove,
|
|
|
|
PersistentPreRun: func(cmd *cobra.Command, _ []string) {
|
|
|
|
commonflags.Bind(cmd)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func initRemoveCmd() {
|
|
|
|
commonflags.Init(removeCmd)
|
|
|
|
initCTID(removeCmd)
|
|
|
|
|
|
|
|
ff := removeCmd.Flags()
|
|
|
|
ff.Uint64(nodeIDFlagKey, 0, "Node ID.")
|
|
|
|
|
|
|
|
_ = getSubtreeCmd.MarkFlagRequired(nodeIDFlagKey)
|
|
|
|
}
|
|
|
|
|
|
|
|
func remove(cmd *cobra.Command, _ []string) {
|
|
|
|
pk := key.GetOrGenerate(cmd)
|
|
|
|
cidString, _ := cmd.Flags().GetString(commonflags.CIDFlag)
|
|
|
|
|
|
|
|
var cnr cid.ID
|
|
|
|
err := cnr.DecodeString(cidString)
|
|
|
|
commonCmd.ExitOnErr(cmd, "decode container ID string: %w", err)
|
|
|
|
|
2024-09-13 08:32:03 +00:00
|
|
|
ctx, cancel := contextWithTimeout(cmd)
|
|
|
|
defer cancel()
|
2023-07-11 09:43:48 +00:00
|
|
|
|
2024-09-13 08:32:03 +00:00
|
|
|
cli, err := _client()
|
2023-07-11 09:36:33 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "failed to create client: %w", err)
|
2023-07-11 09:43:48 +00:00
|
|
|
|
|
|
|
rawCID := make([]byte, sha256.Size)
|
|
|
|
cnr.Encode(rawCID)
|
|
|
|
|
|
|
|
tid, _ := cmd.Flags().GetString(treeIDFlagKey)
|
|
|
|
|
|
|
|
nid, _ := cmd.Flags().GetUint64(nodeIDFlagKey)
|
|
|
|
|
|
|
|
var bt []byte
|
|
|
|
if t := common.ReadBearerToken(cmd, bearerFlagKey); t != nil {
|
|
|
|
bt = t.Marshal()
|
|
|
|
}
|
|
|
|
req := &tree.RemoveRequest{
|
|
|
|
Body: &tree.RemoveRequest_Body{
|
|
|
|
ContainerId: rawCID,
|
|
|
|
TreeId: tid,
|
|
|
|
NodeId: nid,
|
|
|
|
BearerToken: bt,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2023-07-11 09:36:33 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "signing message: %w", tree.SignMessage(req, pk))
|
2023-07-11 09:43:48 +00:00
|
|
|
|
|
|
|
_, err = cli.Remove(ctx, req)
|
2023-07-11 09:36:33 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "failed to call remove: %w", err)
|
|
|
|
common.PrintVerbose(cmd, "Successful remove invocation.")
|
2023-07-11 09:43:48 +00:00
|
|
|
}
|