2022-06-01 12:42:28 +00:00
|
|
|
package object
|
|
|
|
|
|
|
|
import (
|
2022-10-18 11:43:04 +00:00
|
|
|
"fmt"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
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"
|
|
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
2022-06-01 12:42:28 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
var objectDelCmd = &cobra.Command{
|
|
|
|
Use: "delete",
|
|
|
|
Aliases: []string{"del"},
|
2023-01-27 10:44:39 +00:00
|
|
|
Short: "Delete object from FrostFS",
|
|
|
|
Long: "Delete object from FrostFS",
|
2022-06-01 12:42:28 +00:00
|
|
|
Run: deleteObject,
|
|
|
|
}
|
|
|
|
|
|
|
|
func initObjectDeleteCmd() {
|
|
|
|
commonflags.Init(objectDelCmd)
|
2022-10-20 09:40:33 +00:00
|
|
|
initFlagSession(objectDelCmd, "DELETE")
|
2022-06-01 12:42:28 +00:00
|
|
|
|
|
|
|
flags := objectDelCmd.Flags()
|
|
|
|
|
2022-10-18 11:43:04 +00:00
|
|
|
flags.String(commonflags.CIDFlag, "", commonflags.CIDFlagUsage)
|
|
|
|
flags.String(commonflags.OIDFlag, "", commonflags.OIDFlagUsage)
|
|
|
|
flags.Bool(binaryFlag, false, "Deserialize object structure from given file.")
|
|
|
|
flags.String(fileFlag, "", "File with object payload")
|
2022-06-01 12:42:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func deleteObject(cmd *cobra.Command, _ []string) {
|
|
|
|
var cnr cid.ID
|
|
|
|
var obj oid.ID
|
2022-10-18 11:43:04 +00:00
|
|
|
var objAddr oid.Address
|
|
|
|
|
|
|
|
binary, _ := cmd.Flags().GetBool(binaryFlag)
|
|
|
|
if binary {
|
|
|
|
filename, _ := cmd.Flags().GetString(fileFlag)
|
|
|
|
if filename == "" {
|
2023-01-16 09:20:16 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "", fmt.Errorf("required flag \"%s\" not set", fileFlag))
|
2022-10-18 11:43:04 +00:00
|
|
|
}
|
|
|
|
objAddr = readObjectAddressBin(cmd, &cnr, &obj, filename)
|
|
|
|
} else {
|
|
|
|
cidVal, _ := cmd.Flags().GetString(commonflags.CIDFlag)
|
|
|
|
if cidVal == "" {
|
2023-01-16 09:20:16 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "", fmt.Errorf("required flag \"%s\" not set", commonflags.CIDFlag))
|
2022-10-18 11:43:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
oidVal, _ := cmd.Flags().GetString(commonflags.OIDFlag)
|
|
|
|
if oidVal == "" {
|
2023-01-16 09:20:16 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "", fmt.Errorf("required flag \"%s\" not set", commonflags.OIDFlag))
|
2022-10-18 11:43:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
objAddr = readObjectAddress(cmd, &cnr, &obj)
|
|
|
|
}
|
2022-06-01 12:42:28 +00:00
|
|
|
|
|
|
|
pk := key.GetOrGenerate(cmd)
|
|
|
|
|
|
|
|
var prm internalclient.DeleteObjectPrm
|
2022-10-20 09:40:33 +00:00
|
|
|
ReadOrOpenSession(cmd, &prm, pk, cnr, &obj)
|
2022-06-01 12:42:28 +00:00
|
|
|
Prepare(cmd, &prm)
|
|
|
|
prm.SetAddress(objAddr)
|
|
|
|
|
2023-05-24 13:51:57 +00:00
|
|
|
res, err := internalclient.DeleteObject(cmd.Context(), prm)
|
2023-01-16 09:20:16 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "rpc error: %w", err)
|
2022-06-01 12:42:28 +00:00
|
|
|
|
|
|
|
tomb := res.Tombstone()
|
|
|
|
|
|
|
|
cmd.Println("Object removed successfully.")
|
|
|
|
cmd.Printf(" ID: %s\n CID: %s\n", tomb, cnr)
|
|
|
|
}
|