2022-06-02 12:24:31 +00:00
|
|
|
package container
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/common"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/commonflags"
|
|
|
|
commonCmd "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common"
|
|
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/session"
|
2022-06-02 12:24:31 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
attributeDelimiter = "="
|
|
|
|
|
|
|
|
awaitTimeout = 120 // in seconds
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2024-07-26 13:37:05 +00:00
|
|
|
errCreateTimeout = errors.New("timeout: container has not been persisted on sidechain")
|
|
|
|
errDeleteTimeout = errors.New("timeout: container has not been removed from sidechain")
|
2022-06-02 12:24:31 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func parseContainerID(cmd *cobra.Command) cid.ID {
|
|
|
|
if containerID == "" {
|
2023-01-16 09:20:16 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "", errors.New("container ID is not set"))
|
2022-06-02 12:24:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var id cid.ID
|
|
|
|
err := id.DecodeString(containerID)
|
2023-01-16 09:20:16 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "can't decode container ID value: %w", err)
|
2022-06-02 12:24:31 +00:00
|
|
|
return id
|
|
|
|
}
|
2022-10-20 09:40:33 +00:00
|
|
|
|
|
|
|
// decodes session.Container from the file by path provided in
|
|
|
|
// commonflags.SessionToken flag. Returns nil if the path is not specified.
|
|
|
|
func getSession(cmd *cobra.Command) *session.Container {
|
2022-12-27 09:36:30 +00:00
|
|
|
common.PrintVerbose(cmd, "Reading container session...")
|
2022-10-20 09:40:33 +00:00
|
|
|
|
|
|
|
path, _ := cmd.Flags().GetString(commonflags.SessionToken)
|
|
|
|
if path == "" {
|
2022-12-27 09:36:30 +00:00
|
|
|
common.PrintVerbose(cmd, "Session not provided.")
|
2022-10-20 09:40:33 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-12-27 09:36:30 +00:00
|
|
|
common.PrintVerbose(cmd, "Reading container session from the file [%s]...", path)
|
2022-10-20 09:40:33 +00:00
|
|
|
|
|
|
|
var res session.Container
|
|
|
|
|
2022-12-27 09:36:30 +00:00
|
|
|
err := common.ReadBinaryOrJSON(cmd, &res, path)
|
2023-01-16 09:20:16 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "read container session: %v", err)
|
2022-10-20 09:40:33 +00:00
|
|
|
|
2022-12-27 09:36:30 +00:00
|
|
|
common.PrintVerbose(cmd, "Session successfully read.")
|
2022-10-20 09:40:33 +00:00
|
|
|
|
|
|
|
return &res
|
|
|
|
}
|