2022-10-18 13:41:10 +00:00
|
|
|
package tree
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/sha256"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"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"
|
2022-10-18 13:41:10 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
var listCmd = &cobra.Command{
|
|
|
|
Use: "list",
|
|
|
|
Short: "Get tree IDs",
|
|
|
|
Run: list,
|
|
|
|
PersistentPreRun: func(cmd *cobra.Command, _ []string) {
|
|
|
|
commonflags.Bind(cmd)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func initListCmd() {
|
|
|
|
commonflags.Init(listCmd)
|
|
|
|
|
|
|
|
ff := listCmd.Flags()
|
2022-10-18 11:43:04 +00:00
|
|
|
ff.String(commonflags.CIDFlag, "", commonflags.CIDFlagUsage)
|
|
|
|
_ = listCmd.MarkFlagRequired(commonflags.CIDFlag)
|
2022-10-18 13:41:10 +00:00
|
|
|
|
|
|
|
_ = cobra.MarkFlagRequired(ff, commonflags.RPC)
|
|
|
|
}
|
|
|
|
|
|
|
|
func list(cmd *cobra.Command, _ []string) {
|
|
|
|
pk := key.GetOrGenerate(cmd)
|
2022-10-18 11:43:04 +00:00
|
|
|
cidString, _ := cmd.Flags().GetString(commonflags.CIDFlag)
|
2022-10-18 13:41:10 +00:00
|
|
|
|
|
|
|
var cnr cid.ID
|
|
|
|
err := cnr.DecodeString(cidString)
|
2023-01-16 09:20:16 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "decode container ID string: %w", err)
|
2022-10-18 13:41:10 +00:00
|
|
|
|
2024-09-13 08:32:03 +00:00
|
|
|
ctx, cancel := contextWithTimeout(cmd)
|
|
|
|
defer cancel()
|
2022-10-18 13:41:10 +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)
|
2022-10-18 13:41:10 +00:00
|
|
|
|
|
|
|
rawCID := make([]byte, sha256.Size)
|
|
|
|
cnr.Encode(rawCID)
|
|
|
|
|
|
|
|
req := &tree.TreeListRequest{
|
|
|
|
Body: &tree.TreeListRequest_Body{
|
|
|
|
ContainerId: rawCID,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2023-07-11 09:36:33 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "signing message: %w", tree.SignMessage(req, pk))
|
2022-10-18 13:41:10 +00:00
|
|
|
|
|
|
|
resp, err := cli.TreeList(ctx, req)
|
2023-07-11 09:36:33 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "failed to call treeList %w", err)
|
2022-10-18 13:41:10 +00:00
|
|
|
|
|
|
|
for _, treeID := range resp.GetBody().GetIds() {
|
|
|
|
cmd.Println(treeID)
|
|
|
|
}
|
|
|
|
}
|