2023-10-16 15:15:04 +00:00
|
|
|
package control
|
|
|
|
|
|
|
|
import (
|
|
|
|
"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"
|
|
|
|
ircontrol "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/control/ir"
|
|
|
|
ircontrolsrv "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/control/ir/server"
|
2024-11-07 14:32:10 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/refs"
|
|
|
|
rawclient "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/rpc/client"
|
2023-10-16 15:15:04 +00:00
|
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
ownerFlag = "owner"
|
|
|
|
)
|
|
|
|
|
|
|
|
var removeContainerCmd = &cobra.Command{
|
|
|
|
Use: "remove-container",
|
|
|
|
Short: "Schedules a container removal",
|
|
|
|
Long: `Schedules a container removal via a notary request.
|
|
|
|
Container data will be deleted asynchronously by policer.
|
|
|
|
To check removal status "frostfs-cli container list" command can be used.`,
|
|
|
|
Run: removeContainer,
|
|
|
|
}
|
|
|
|
|
|
|
|
func initControlIRRemoveContainerCmd() {
|
2023-11-07 14:35:09 +00:00
|
|
|
initControlIRFlags(removeContainerCmd)
|
2023-10-16 15:15:04 +00:00
|
|
|
|
|
|
|
flags := removeContainerCmd.Flags()
|
|
|
|
flags.String(commonflags.CIDFlag, "", commonflags.CIDFlagUsage)
|
|
|
|
flags.String(ownerFlag, "", "Container owner's wallet address.")
|
|
|
|
removeContainerCmd.MarkFlagsMutuallyExclusive(commonflags.CIDFlag, ownerFlag)
|
2023-11-15 11:26:23 +00:00
|
|
|
removeContainerCmd.MarkFlagsOneRequired(commonflags.CIDFlag, ownerFlag)
|
2023-10-16 15:15:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func removeContainer(cmd *cobra.Command, _ []string) {
|
|
|
|
req := prepareRemoveContainerRequest(cmd)
|
|
|
|
|
|
|
|
pk := key.Get(cmd)
|
|
|
|
c := getClient(cmd, pk)
|
|
|
|
|
|
|
|
commonCmd.ExitOnErr(cmd, "could not sign request: %w", ircontrolsrv.SignMessage(pk, req))
|
|
|
|
|
|
|
|
var resp *ircontrol.RemoveContainerResponse
|
|
|
|
err := c.ExecRaw(func(client *rawclient.Client) error {
|
|
|
|
var err error
|
|
|
|
resp, err = ircontrol.RemoveContainer(client, req)
|
|
|
|
return err
|
|
|
|
})
|
|
|
|
commonCmd.ExitOnErr(cmd, "failed to execute request: %w", err)
|
|
|
|
|
|
|
|
verifyResponse(cmd, resp.GetSignature(), resp.GetBody())
|
|
|
|
|
|
|
|
if len(req.GetBody().GetContainerId()) > 0 {
|
|
|
|
cmd.Println("Container scheduled to removal")
|
|
|
|
} else {
|
|
|
|
cmd.Println("User containers sheduled to removal")
|
|
|
|
}
|
2023-11-07 14:35:09 +00:00
|
|
|
printVUB(cmd, resp.GetBody().GetVub())
|
2023-10-16 15:15:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func prepareRemoveContainerRequest(cmd *cobra.Command) *ircontrol.RemoveContainerRequest {
|
|
|
|
req := &ircontrol.RemoveContainerRequest{
|
|
|
|
Body: &ircontrol.RemoveContainerRequest_Body{},
|
|
|
|
}
|
|
|
|
|
|
|
|
cidStr, err := cmd.Flags().GetString(commonflags.CIDFlag)
|
|
|
|
commonCmd.ExitOnErr(cmd, "failed to get cid: ", err)
|
|
|
|
|
|
|
|
ownerStr, err := cmd.Flags().GetString(ownerFlag)
|
|
|
|
commonCmd.ExitOnErr(cmd, "failed to get owner: ", err)
|
|
|
|
|
|
|
|
if len(ownerStr) > 0 {
|
|
|
|
var owner user.ID
|
|
|
|
commonCmd.ExitOnErr(cmd, "invalid owner ID: %w", owner.DecodeString(ownerStr))
|
|
|
|
var ownerID refs.OwnerID
|
|
|
|
owner.WriteToV2(&ownerID)
|
|
|
|
req.Body.Owner = ownerID.StableMarshal(nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(cidStr) > 0 {
|
|
|
|
var containerID cid.ID
|
|
|
|
commonCmd.ExitOnErr(cmd, "invalid container ID: %w", containerID.DecodeString(cidStr))
|
|
|
|
req.Body.ContainerId = containerID[:]
|
|
|
|
}
|
2023-11-07 14:35:09 +00:00
|
|
|
|
|
|
|
req.Body.Vub = parseVUB(cmd)
|
|
|
|
|
2023-10-16 15:15:04 +00:00
|
|
|
return req
|
|
|
|
}
|