2022-10-18 13:41:10 +00:00
|
|
|
package tree
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/sha256"
|
|
|
|
|
2022-12-23 17:35:35 +00:00
|
|
|
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/commonflags"
|
|
|
|
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/key"
|
2023-01-16 09:20:16 +00:00
|
|
|
commonCmd "github.com/TrueCloudLab/frostfs-node/cmd/internal/common"
|
2022-12-23 17:35:35 +00:00
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/services/tree"
|
|
|
|
cid "github.com/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
|
|
|
|
|
|
|
ctx := cmd.Context()
|
|
|
|
|
|
|
|
cli, err := _client(ctx)
|
2023-01-16 09:20:16 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "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-01-16 09:20:16 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "message signing: %w", tree.SignMessage(req, pk))
|
2022-10-18 13:41:10 +00:00
|
|
|
|
|
|
|
resp, err := cli.TreeList(ctx, req)
|
2023-01-16 09:20:16 +00:00
|
|
|
commonCmd.ExitOnErr(cmd, "rpc call: %w", err)
|
2022-10-18 13:41:10 +00:00
|
|
|
|
|
|
|
for _, treeID := range resp.GetBody().GetIds() {
|
|
|
|
cmd.Println(treeID)
|
|
|
|
}
|
|
|
|
}
|