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) _ = cobra.MarkFlagRequired(ff, commonflags.RPC) } 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) ctx, cancel := contextWithTimeout(cmd) defer cancel() cli, err := _client() commonCmd.ExitOnErr(cmd, "failed to create client: %w", err) 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, }, } commonCmd.ExitOnErr(cmd, "signing message: %w", tree.SignMessage(req, pk)) _, err = cli.Remove(ctx, req) commonCmd.ExitOnErr(cmd, "failed to call remove: %w", err) common.PrintVerbose(cmd, "Successful remove invocation.") }