From ee94576a6d67d74bf0644289a0c54cb9f4c17b9c Mon Sep 17 00:00:00 2001 From: Airat Arifullin Date: Tue, 11 Jul 2023 12:43:48 +0300 Subject: [PATCH 1/3] [#390] cli: Support more tree service API calls in CLI * Support healthcheck API call * Support move API call * Support remove API call * Support getSubtree API call * Support getOpLog API call Signed-off-by: Airat Arifullin a.arifullin@yadro.com --- cmd/frostfs-cli/modules/tree/add_by_path.go | 1 - cmd/frostfs-cli/modules/tree/get_by_path.go | 10 +- cmd/frostfs-cli/modules/tree/get_op_log.go | 83 +++++++++++++++ cmd/frostfs-cli/modules/tree/healthcheck.go | 42 ++++++++ cmd/frostfs-cli/modules/tree/move.go | 107 ++++++++++++++++++++ cmd/frostfs-cli/modules/tree/remove.go | 74 ++++++++++++++ cmd/frostfs-cli/modules/tree/root.go | 18 +++- cmd/frostfs-cli/modules/tree/subtree.go | 101 ++++++++++++++++++ 8 files changed, 430 insertions(+), 6 deletions(-) create mode 100644 cmd/frostfs-cli/modules/tree/get_op_log.go create mode 100644 cmd/frostfs-cli/modules/tree/healthcheck.go create mode 100644 cmd/frostfs-cli/modules/tree/move.go create mode 100644 cmd/frostfs-cli/modules/tree/remove.go create mode 100644 cmd/frostfs-cli/modules/tree/subtree.go diff --git a/cmd/frostfs-cli/modules/tree/add_by_path.go b/cmd/frostfs-cli/modules/tree/add_by_path.go index 6b182e1e4..6b182bf4f 100644 --- a/cmd/frostfs-cli/modules/tree/add_by_path.go +++ b/cmd/frostfs-cli/modules/tree/add_by_path.go @@ -62,7 +62,6 @@ func addByPath(cmd *cobra.Command, _ []string) { commonCmd.ExitOnErr(cmd, "meta data parsing: %w", err) path, _ := cmd.Flags().GetString(pathFlagKey) - // pAttr, _ := cmd.Flags().GetString(pathAttributeFlagKey) req := new(tree.AddByPathRequest) req.Body = &tree.AddByPathRequest_Body{ diff --git a/cmd/frostfs-cli/modules/tree/get_by_path.go b/cmd/frostfs-cli/modules/tree/get_by_path.go index 69a3dc7ea..877cda447 100644 --- a/cmd/frostfs-cli/modules/tree/get_by_path.go +++ b/cmd/frostfs-cli/modules/tree/get_by_path.go @@ -60,7 +60,11 @@ func getByPath(cmd *cobra.Command, _ []string) { latestOnly, _ := cmd.Flags().GetBool(latestOnlyFlagKey) path, _ := cmd.Flags().GetString(pathFlagKey) - // pAttr, _ := cmd.Flags().GetString(pathAttributeFlagKey) + + var bt []byte + if t := common.ReadBearerToken(cmd, bearerFlagKey); t != nil { + bt = t.Marshal() + } req := new(tree.GetNodeByPathRequest) req.Body = &tree.GetNodeByPathRequest_Body{ @@ -71,9 +75,7 @@ func getByPath(cmd *cobra.Command, _ []string) { Path: strings.Split(path, "/"), LatestOnly: latestOnly, AllAttributes: true, - } - if btok := common.ReadBearerToken(cmd, bearerFlagKey); btok != nil { - req.Body.BearerToken = btok.Marshal() + BearerToken: bt, } commonCmd.ExitOnErr(cmd, "message signing: %w", tree.SignMessage(req, pk)) diff --git a/cmd/frostfs-cli/modules/tree/get_op_log.go b/cmd/frostfs-cli/modules/tree/get_op_log.go new file mode 100644 index 000000000..6efa76133 --- /dev/null +++ b/cmd/frostfs-cli/modules/tree/get_op_log.go @@ -0,0 +1,83 @@ +package tree + +import ( + "crypto/sha256" + "errors" + "io" + + "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" + "github.com/spf13/cobra" +) + +var getOpLogCmd = &cobra.Command{ + Use: "get-op-log", + Short: "Get logged operations starting with some height", + Run: getOpLog, + PersistentPreRun: func(cmd *cobra.Command, _ []string) { + commonflags.Bind(cmd) + }, +} + +func initGetOpLogCmd() { + commonflags.Init(getOpLogCmd) + initCTID(getOpLogCmd) + + ff := getOpLogCmd.Flags() + ff.Uint64(heightFlagKey, 0, "Height to start with") + ff.Uint64(countFlagKey, 10, "Logged operations count") + + _ = cobra.MarkFlagRequired(ff, commonflags.RPC) +} + +func getOpLog(cmd *cobra.Command, _ []string) { + pk := key.GetOrGenerate(cmd) + + cidRaw, _ := cmd.Flags().GetString(commonflags.CIDFlag) + + var cnr cid.ID + err := cnr.DecodeString(cidRaw) + commonCmd.ExitOnErr(cmd, "decode container ID string: %w", err) + + tid, _ := cmd.Flags().GetString(treeIDFlagKey) + ctx := cmd.Context() + + cli, err := _client(ctx) + commonCmd.ExitOnErr(cmd, "failed to create client: %w", err) + + rawCID := make([]byte, sha256.Size) + cnr.Encode(rawCID) + + height, _ := cmd.Flags().GetUint64(heightFlagKey) + count, _ := cmd.Flags().GetUint64(countFlagKey) + + req := &tree.GetOpLogRequest{ + Body: &tree.GetOpLogRequest_Body{ + ContainerId: rawCID, + TreeId: tid, + Height: height, + Count: count, + }, + } + + commonCmd.ExitOnErr(cmd, "signing message: %w", tree.SignMessage(req, pk)) + + resp, err := cli.GetOpLog(ctx, req) + commonCmd.ExitOnErr(cmd, "get op log: %w", err) + + opLogResp, err := resp.Recv() + for ; err == nil; opLogResp, err = resp.Recv() { + o := opLogResp.GetBody().GetOperation() + + cmd.Println("Parent ID: ", o.GetParentId()) + + cmd.Println("\tChild ID: ", o.GetChildId()) + cmd.Printf("\tMeta: %s\n", o.GetMeta()) + } + if !errors.Is(err, io.EOF) { + commonCmd.ExitOnErr(cmd, "get op log response stream: %w", err) + } +} diff --git a/cmd/frostfs-cli/modules/tree/healthcheck.go b/cmd/frostfs-cli/modules/tree/healthcheck.go new file mode 100644 index 000000000..46d4c3409 --- /dev/null +++ b/cmd/frostfs-cli/modules/tree/healthcheck.go @@ -0,0 +1,42 @@ +package tree + +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" + "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/tree" + "github.com/spf13/cobra" +) + +var healthcheckCmd = &cobra.Command{ + Use: "healthcheck", + Short: "Check tree service availability", + Run: healthcheck, + PersistentPreRun: func(cmd *cobra.Command, _ []string) { + commonflags.Bind(cmd) + }, +} + +func initHealthcheckCmd() { + commonflags.Init(healthcheckCmd) + ff := healthcheckCmd.Flags() + _ = cobra.MarkFlagRequired(ff, commonflags.RPC) +} + +func healthcheck(cmd *cobra.Command, _ []string) { + pk := key.GetOrGenerate(cmd) + ctx := cmd.Context() + + cli, err := _client(ctx) + commonCmd.ExitOnErr(cmd, "client: %w", err) + + req := &tree.HealthcheckRequest{ + Body: &tree.HealthcheckRequest_Body{}, + } + commonCmd.ExitOnErr(cmd, "message signing: %w", tree.SignMessage(req, pk)) + + _, err = cli.Healthcheck(ctx, req) + commonCmd.ExitOnErr(cmd, "rpc call: %w", err) + + cmd.Println("Success.") +} diff --git a/cmd/frostfs-cli/modules/tree/move.go b/cmd/frostfs-cli/modules/tree/move.go new file mode 100644 index 000000000..b91769185 --- /dev/null +++ b/cmd/frostfs-cli/modules/tree/move.go @@ -0,0 +1,107 @@ +package tree + +import ( + "crypto/sha256" + "errors" + "io" + + "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/common" + "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" + "github.com/spf13/cobra" +) + +var moveCmd = &cobra.Command{ + Use: "move", + Short: "Move node", + Run: move, + PersistentPreRun: func(cmd *cobra.Command, _ []string) { + commonflags.Bind(cmd) + }, +} + +func initMoveCmd() { + commonflags.Init(moveCmd) + initCTID(moveCmd) + + ff := moveCmd.Flags() + ff.Uint64(nodeIDFlagKey, 0, "Node ID.") + ff.Uint64(parentIDFlagKey, 0, "Parent ID.") + + _ = getSubtreeCmd.MarkFlagRequired(nodeIDFlagKey) + _ = getSubtreeCmd.MarkFlagRequired(parentIDFlagKey) + + _ = cobra.MarkFlagRequired(ff, commonflags.RPC) +} + +func move(cmd *cobra.Command, _ []string) { + pk := key.GetOrGenerate(cmd) + cidString, _ := cmd.Flags().GetString(commonflags.CIDFlag) + + var cnr cid.ID + err := cnr.DecodeString(cidString) + commonCmd.ExitOnErr(cmd, "decode container ID string: %w", err) + + ctx := cmd.Context() + + cli, err := _client(ctx) + commonCmd.ExitOnErr(cmd, "client: %w", err) + + rawCID := make([]byte, sha256.Size) + cnr.Encode(rawCID) + + tid, _ := cmd.Flags().GetString(treeIDFlagKey) + pid, _ := cmd.Flags().GetUint64(parentIDFlagKey) + nid, _ := cmd.Flags().GetUint64(nodeIDFlagKey) + + var bt []byte + if t := common.ReadBearerToken(cmd, bearerFlagKey); t != nil { + bt = t.Marshal() + } + + subTreeReq := &tree.GetSubTreeRequest{ + Body: &tree.GetSubTreeRequest_Body{ + ContainerId: rawCID, + TreeId: tid, + RootId: nid, + Depth: 1, + BearerToken: bt, + }, + } + commonCmd.ExitOnErr(cmd, "message signing: %w", tree.SignMessage(subTreeReq, pk)) + resp, err := cli.GetSubTree(ctx, subTreeReq) + commonCmd.ExitOnErr(cmd, "rpc call: %w", err) + + var meta []*tree.KeyValue + subtreeResp, err := resp.Recv() + for ; err == nil; subtreeResp, err = resp.Recv() { + meta = subtreeResp.GetBody().GetMeta() + } + if !errors.Is(err, io.EOF) { + commonCmd.ExitOnErr(cmd, "rpc call: %w", err) + } + var metaErr error + if len(meta) == 0 { + metaErr = errors.New("no meta for given node ID") + } + commonCmd.ExitOnErr(cmd, "unexpected rpc call result: %w", metaErr) + + req := &tree.MoveRequest{ + Body: &tree.MoveRequest_Body{ + ContainerId: rawCID, + TreeId: tid, + ParentId: pid, + NodeId: nid, + Meta: meta, + }, + } + + commonCmd.ExitOnErr(cmd, "message signing: %w", tree.SignMessage(req, pk)) + + _, err = cli.Move(ctx, req) + commonCmd.ExitOnErr(cmd, "rpc call: %w", err) + cmd.Println("Success.") +} diff --git a/cmd/frostfs-cli/modules/tree/remove.go b/cmd/frostfs-cli/modules/tree/remove.go new file mode 100644 index 000000000..7002ac9a4 --- /dev/null +++ b/cmd/frostfs-cli/modules/tree/remove.go @@ -0,0 +1,74 @@ +package tree + +import ( + "crypto/sha256" + + "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/common" + "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" + "github.com/spf13/cobra" +) + +var removeCmd = &cobra.Command{ + Use: "remove", + Short: "Remove node", + Run: remove, + PersistentPreRun: func(cmd *cobra.Command, _ []string) { + commonflags.Bind(cmd) + }, +} + +func initRemoveCmd() { + commonflags.Init(removeCmd) + initCTID(removeCmd) + + ff := removeCmd.Flags() + ff.Uint64(nodeIDFlagKey, 0, "Node ID.") + + _ = getSubtreeCmd.MarkFlagRequired(nodeIDFlagKey) + + _ = cobra.MarkFlagRequired(ff, commonflags.RPC) +} + +func remove(cmd *cobra.Command, _ []string) { + pk := key.GetOrGenerate(cmd) + cidString, _ := cmd.Flags().GetString(commonflags.CIDFlag) + + var cnr cid.ID + err := cnr.DecodeString(cidString) + commonCmd.ExitOnErr(cmd, "decode container ID string: %w", err) + + ctx := cmd.Context() + + cli, err := _client(ctx) + commonCmd.ExitOnErr(cmd, "client: %w", err) + + rawCID := make([]byte, sha256.Size) + cnr.Encode(rawCID) + + tid, _ := cmd.Flags().GetString(treeIDFlagKey) + + nid, _ := cmd.Flags().GetUint64(nodeIDFlagKey) + + var bt []byte + if t := common.ReadBearerToken(cmd, bearerFlagKey); t != nil { + bt = t.Marshal() + } + req := &tree.RemoveRequest{ + Body: &tree.RemoveRequest_Body{ + ContainerId: rawCID, + TreeId: tid, + NodeId: nid, + BearerToken: bt, + }, + } + + commonCmd.ExitOnErr(cmd, "message signing: %w", tree.SignMessage(req, pk)) + + _, err = cli.Remove(ctx, req) + commonCmd.ExitOnErr(cmd, "rpc call: %w", err) + cmd.Println("Success.") +} diff --git a/cmd/frostfs-cli/modules/tree/root.go b/cmd/frostfs-cli/modules/tree/root.go index b5de0dd6f..701a78f2a 100644 --- a/cmd/frostfs-cli/modules/tree/root.go +++ b/cmd/frostfs-cli/modules/tree/root.go @@ -15,16 +15,28 @@ func init() { Cmd.AddCommand(getByPathCmd) Cmd.AddCommand(addByPathCmd) Cmd.AddCommand(listCmd) + Cmd.AddCommand(healthcheckCmd) + Cmd.AddCommand(moveCmd) + Cmd.AddCommand(removeCmd) + Cmd.AddCommand(getSubtreeCmd) + Cmd.AddCommand(getOpLogCmd) initAddCmd() initGetByPathCmd() initAddByPathCmd() initListCmd() + initHealthcheckCmd() + initMoveCmd() + initRemoveCmd() + initGetSubtreeCmd() + initGetOpLogCmd() } const ( treeIDFlagKey = "tid" parentIDFlagKey = "pid" + nodeIDFlagKey = "nid" + rootIDFlagKey = "root" metaFlagKey = "meta" @@ -34,6 +46,10 @@ const ( latestOnlyFlagKey = "latest" bearerFlagKey = "bearer" + + heightFlagKey = "height" + countFlagKey = "count" + depthFlagKey = "depth" ) func initCTID(cmd *cobra.Command) { @@ -45,5 +61,5 @@ func initCTID(cmd *cobra.Command) { ff.String(treeIDFlagKey, "", "Tree ID") _ = cmd.MarkFlagRequired(treeIDFlagKey) - ff.StringP(bearerFlagKey, "", "", "Path to bearer token") + ff.String(bearerFlagKey, "", "Path to bearer token") } diff --git a/cmd/frostfs-cli/modules/tree/subtree.go b/cmd/frostfs-cli/modules/tree/subtree.go new file mode 100644 index 000000000..f6dcf85ff --- /dev/null +++ b/cmd/frostfs-cli/modules/tree/subtree.go @@ -0,0 +1,101 @@ +package tree + +import ( + "crypto/sha256" + "errors" + "io" + + "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/common" + "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" + "github.com/spf13/cobra" +) + +var getSubtreeCmd = &cobra.Command{ + Use: "get-subtree", + Short: "Get subtree", + Run: getSubTree, + PersistentPreRun: func(cmd *cobra.Command, _ []string) { + commonflags.Bind(cmd) + }, +} + +func initGetSubtreeCmd() { + commonflags.Init(getSubtreeCmd) + initCTID(getSubtreeCmd) + + ff := getSubtreeCmd.Flags() + ff.Uint64(rootIDFlagKey, 0, "Root ID to traverse from.") + ff.Uint32(depthFlagKey, 10, "Traversal depth.") + + _ = getSubtreeCmd.MarkFlagRequired(commonflags.CIDFlag) + _ = getSubtreeCmd.MarkFlagRequired(treeIDFlagKey) + + _ = cobra.MarkFlagRequired(ff, commonflags.RPC) +} + +func getSubTree(cmd *cobra.Command, _ []string) { + pk := key.GetOrGenerate(cmd) + cidString, _ := cmd.Flags().GetString(commonflags.CIDFlag) + + var cnr cid.ID + err := cnr.DecodeString(cidString) + commonCmd.ExitOnErr(cmd, "decode container ID string: %w", err) + + ctx := cmd.Context() + + cli, err := _client(ctx) + commonCmd.ExitOnErr(cmd, "client: %w", err) + + rawCID := make([]byte, sha256.Size) + cnr.Encode(rawCID) + + tid, _ := cmd.Flags().GetString(treeIDFlagKey) + + rid, _ := cmd.Flags().GetUint64(rootIDFlagKey) + + depth, _ := cmd.Flags().GetUint32(depthFlagKey) + + var bt []byte + if t := common.ReadBearerToken(cmd, bearerFlagKey); t != nil { + bt = t.Marshal() + } + + req := &tree.GetSubTreeRequest{ + Body: &tree.GetSubTreeRequest_Body{ + ContainerId: rawCID, + TreeId: tid, + RootId: rid, + Depth: depth, + BearerToken: bt, + }, + } + + commonCmd.ExitOnErr(cmd, "message signing: %w", tree.SignMessage(req, pk)) + + resp, err := cli.GetSubTree(ctx, req) + commonCmd.ExitOnErr(cmd, "rpc call: %w", err) + + subtreeResp, err := resp.Recv() + for ; err == nil; subtreeResp, err = resp.Recv() { + b := subtreeResp.GetBody() + + cmd.Printf("Node ID: %d\n", b.GetNodeId()) + + cmd.Println("\tParent ID: ", b.GetParentId()) + cmd.Println("\tTimestamp: ", b.GetTimestamp()) + + if meta := b.GetMeta(); len(meta) > 0 { + cmd.Println("\tMeta pairs: ") + for _, kv := range meta { + cmd.Printf("\t\t%s: %s\n", kv.GetKey(), string(kv.GetValue())) + } + } + } + if !errors.Is(err, io.EOF) { + commonCmd.ExitOnErr(cmd, "rpc call: %w", err) + } +} -- 2.45.2 From 48b01d3ea9ec6c8523a375a36efacb5c72c991a4 Mon Sep 17 00:00:00 2001 From: Airat Arifullin Date: Tue, 11 Jul 2023 12:36:33 +0300 Subject: [PATCH 2/3] [#390] cli: Make tree commands errors and messages more verbose Signed-off-by: Airat Arifullin a.arifullin@yadro.com --- cmd/frostfs-cli/modules/tree/add.go | 6 +++--- cmd/frostfs-cli/modules/tree/add_by_path.go | 6 +++--- cmd/frostfs-cli/modules/tree/get_by_path.go | 6 +++--- cmd/frostfs-cli/modules/tree/healthcheck.go | 9 +++++---- cmd/frostfs-cli/modules/tree/list.go | 6 +++--- cmd/frostfs-cli/modules/tree/move.go | 12 ++++++------ cmd/frostfs-cli/modules/tree/remove.go | 8 ++++---- cmd/frostfs-cli/modules/tree/subtree.go | 6 +++--- 8 files changed, 30 insertions(+), 29 deletions(-) diff --git a/cmd/frostfs-cli/modules/tree/add.go b/cmd/frostfs-cli/modules/tree/add.go index ea9245271..28718687d 100644 --- a/cmd/frostfs-cli/modules/tree/add.go +++ b/cmd/frostfs-cli/modules/tree/add.go @@ -50,7 +50,7 @@ func add(cmd *cobra.Command, _ []string) { ctx := cmd.Context() cli, err := _client(ctx) - commonCmd.ExitOnErr(cmd, "client: %w", err) + commonCmd.ExitOnErr(cmd, "failed to create client: %w", err) rawCID := make([]byte, sha256.Size) cnr.Encode(rawCID) @@ -64,10 +64,10 @@ func add(cmd *cobra.Command, _ []string) { BearerToken: common.ReadBearerToken(cmd, bearerFlagKey).Marshal(), } - commonCmd.ExitOnErr(cmd, "message signing: %w", tree.SignMessage(req, pk)) + commonCmd.ExitOnErr(cmd, "signing message: %w", tree.SignMessage(req, pk)) resp, err := cli.Add(ctx, req) - commonCmd.ExitOnErr(cmd, "rpc call: %w", err) + commonCmd.ExitOnErr(cmd, "failed to cal add: %w", err) cmd.Println("Node ID: ", resp.Body.NodeId) } diff --git a/cmd/frostfs-cli/modules/tree/add_by_path.go b/cmd/frostfs-cli/modules/tree/add_by_path.go index 6b182bf4f..284dab63a 100644 --- a/cmd/frostfs-cli/modules/tree/add_by_path.go +++ b/cmd/frostfs-cli/modules/tree/add_by_path.go @@ -53,7 +53,7 @@ func addByPath(cmd *cobra.Command, _ []string) { ctx := cmd.Context() cli, err := _client(ctx) - commonCmd.ExitOnErr(cmd, "client: %w", err) + commonCmd.ExitOnErr(cmd, "failed to create client: %w", err) rawCID := make([]byte, sha256.Size) cnr.Encode(rawCID) @@ -74,10 +74,10 @@ func addByPath(cmd *cobra.Command, _ []string) { BearerToken: common.ReadBearerToken(cmd, bearerFlagKey).Marshal(), } - commonCmd.ExitOnErr(cmd, "message signing: %w", tree.SignMessage(req, pk)) + commonCmd.ExitOnErr(cmd, "signing message: %w", tree.SignMessage(req, pk)) resp, err := cli.AddByPath(ctx, req) - commonCmd.ExitOnErr(cmd, "rpc call: %w", err) + commonCmd.ExitOnErr(cmd, "failed to addByPath %w", err) cmd.Printf("Parent ID: %d\n", resp.GetBody().GetParentId()) diff --git a/cmd/frostfs-cli/modules/tree/get_by_path.go b/cmd/frostfs-cli/modules/tree/get_by_path.go index 877cda447..146f01c4e 100644 --- a/cmd/frostfs-cli/modules/tree/get_by_path.go +++ b/cmd/frostfs-cli/modules/tree/get_by_path.go @@ -53,7 +53,7 @@ func getByPath(cmd *cobra.Command, _ []string) { ctx := cmd.Context() cli, err := _client(ctx) - commonCmd.ExitOnErr(cmd, "client: %w", err) + commonCmd.ExitOnErr(cmd, "failed to create client: %w", err) rawCID := make([]byte, sha256.Size) cnr.Encode(rawCID) @@ -78,10 +78,10 @@ func getByPath(cmd *cobra.Command, _ []string) { BearerToken: bt, } - commonCmd.ExitOnErr(cmd, "message signing: %w", tree.SignMessage(req, pk)) + commonCmd.ExitOnErr(cmd, "signing message: %w", tree.SignMessage(req, pk)) resp, err := cli.GetNodeByPath(ctx, req) - commonCmd.ExitOnErr(cmd, "rpc call: %w", err) + commonCmd.ExitOnErr(cmd, "failed to call getNodeByPath: %w", err) nn := resp.GetBody().GetNodes() if len(nn) == 0 { diff --git a/cmd/frostfs-cli/modules/tree/healthcheck.go b/cmd/frostfs-cli/modules/tree/healthcheck.go index 46d4c3409..f0506467e 100644 --- a/cmd/frostfs-cli/modules/tree/healthcheck.go +++ b/cmd/frostfs-cli/modules/tree/healthcheck.go @@ -1,6 +1,7 @@ package tree import ( + "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/common" "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" @@ -28,15 +29,15 @@ func healthcheck(cmd *cobra.Command, _ []string) { ctx := cmd.Context() cli, err := _client(ctx) - commonCmd.ExitOnErr(cmd, "client: %w", err) + commonCmd.ExitOnErr(cmd, "failed to create client: %w", err) req := &tree.HealthcheckRequest{ Body: &tree.HealthcheckRequest_Body{}, } - commonCmd.ExitOnErr(cmd, "message signing: %w", tree.SignMessage(req, pk)) + commonCmd.ExitOnErr(cmd, "signing message: %w", tree.SignMessage(req, pk)) _, err = cli.Healthcheck(ctx, req) - commonCmd.ExitOnErr(cmd, "rpc call: %w", err) + commonCmd.ExitOnErr(cmd, "failed to call healthcheck: %w", err) - cmd.Println("Success.") + common.PrintVerbose(cmd, "Successful healthcheck invocation.") } diff --git a/cmd/frostfs-cli/modules/tree/list.go b/cmd/frostfs-cli/modules/tree/list.go index 8e4d2bd4c..a25d066d5 100644 --- a/cmd/frostfs-cli/modules/tree/list.go +++ b/cmd/frostfs-cli/modules/tree/list.go @@ -41,7 +41,7 @@ func list(cmd *cobra.Command, _ []string) { ctx := cmd.Context() cli, err := _client(ctx) - commonCmd.ExitOnErr(cmd, "client: %w", err) + commonCmd.ExitOnErr(cmd, "failed to create client: %w", err) rawCID := make([]byte, sha256.Size) cnr.Encode(rawCID) @@ -52,10 +52,10 @@ func list(cmd *cobra.Command, _ []string) { }, } - commonCmd.ExitOnErr(cmd, "message signing: %w", tree.SignMessage(req, pk)) + commonCmd.ExitOnErr(cmd, "signing message: %w", tree.SignMessage(req, pk)) resp, err := cli.TreeList(ctx, req) - commonCmd.ExitOnErr(cmd, "rpc call: %w", err) + commonCmd.ExitOnErr(cmd, "failed to call treeList %w", err) for _, treeID := range resp.GetBody().GetIds() { cmd.Println(treeID) diff --git a/cmd/frostfs-cli/modules/tree/move.go b/cmd/frostfs-cli/modules/tree/move.go index b91769185..84b2fb80e 100644 --- a/cmd/frostfs-cli/modules/tree/move.go +++ b/cmd/frostfs-cli/modules/tree/move.go @@ -48,7 +48,7 @@ func move(cmd *cobra.Command, _ []string) { ctx := cmd.Context() cli, err := _client(ctx) - commonCmd.ExitOnErr(cmd, "client: %w", err) + commonCmd.ExitOnErr(cmd, "failed to create client: %w", err) rawCID := make([]byte, sha256.Size) cnr.Encode(rawCID) @@ -71,7 +71,7 @@ func move(cmd *cobra.Command, _ []string) { BearerToken: bt, }, } - commonCmd.ExitOnErr(cmd, "message signing: %w", tree.SignMessage(subTreeReq, pk)) + commonCmd.ExitOnErr(cmd, "signing message: %w", tree.SignMessage(subTreeReq, pk)) resp, err := cli.GetSubTree(ctx, subTreeReq) commonCmd.ExitOnErr(cmd, "rpc call: %w", err) @@ -81,7 +81,7 @@ func move(cmd *cobra.Command, _ []string) { meta = subtreeResp.GetBody().GetMeta() } if !errors.Is(err, io.EOF) { - commonCmd.ExitOnErr(cmd, "rpc call: %w", err) + commonCmd.ExitOnErr(cmd, "failed to read getSubTree response stream: %w", err) } var metaErr error if len(meta) == 0 { @@ -99,9 +99,9 @@ func move(cmd *cobra.Command, _ []string) { }, } - commonCmd.ExitOnErr(cmd, "message signing: %w", tree.SignMessage(req, pk)) + commonCmd.ExitOnErr(cmd, "signing message: %w", tree.SignMessage(req, pk)) _, err = cli.Move(ctx, req) - commonCmd.ExitOnErr(cmd, "rpc call: %w", err) - cmd.Println("Success.") + commonCmd.ExitOnErr(cmd, "failed to call move: %w", err) + common.PrintVerbose(cmd, "Successful move invocation.") } diff --git a/cmd/frostfs-cli/modules/tree/remove.go b/cmd/frostfs-cli/modules/tree/remove.go index 7002ac9a4..74e9d9749 100644 --- a/cmd/frostfs-cli/modules/tree/remove.go +++ b/cmd/frostfs-cli/modules/tree/remove.go @@ -44,7 +44,7 @@ func remove(cmd *cobra.Command, _ []string) { ctx := cmd.Context() cli, err := _client(ctx) - commonCmd.ExitOnErr(cmd, "client: %w", err) + commonCmd.ExitOnErr(cmd, "failed to create client: %w", err) rawCID := make([]byte, sha256.Size) cnr.Encode(rawCID) @@ -66,9 +66,9 @@ func remove(cmd *cobra.Command, _ []string) { }, } - commonCmd.ExitOnErr(cmd, "message signing: %w", tree.SignMessage(req, pk)) + commonCmd.ExitOnErr(cmd, "signing message: %w", tree.SignMessage(req, pk)) _, err = cli.Remove(ctx, req) - commonCmd.ExitOnErr(cmd, "rpc call: %w", err) - cmd.Println("Success.") + commonCmd.ExitOnErr(cmd, "failed to call remove: %w", err) + common.PrintVerbose(cmd, "Successful remove invocation.") } diff --git a/cmd/frostfs-cli/modules/tree/subtree.go b/cmd/frostfs-cli/modules/tree/subtree.go index f6dcf85ff..64cb351ec 100644 --- a/cmd/frostfs-cli/modules/tree/subtree.go +++ b/cmd/frostfs-cli/modules/tree/subtree.go @@ -48,7 +48,7 @@ func getSubTree(cmd *cobra.Command, _ []string) { ctx := cmd.Context() cli, err := _client(ctx) - commonCmd.ExitOnErr(cmd, "client: %w", err) + commonCmd.ExitOnErr(cmd, "failed to create client: %w", err) rawCID := make([]byte, sha256.Size) cnr.Encode(rawCID) @@ -74,10 +74,10 @@ func getSubTree(cmd *cobra.Command, _ []string) { }, } - commonCmd.ExitOnErr(cmd, "message signing: %w", tree.SignMessage(req, pk)) + commonCmd.ExitOnErr(cmd, "signing message: %w", tree.SignMessage(req, pk)) resp, err := cli.GetSubTree(ctx, req) - commonCmd.ExitOnErr(cmd, "rpc call: %w", err) + commonCmd.ExitOnErr(cmd, "failed to call getSubTree: %w", err) subtreeResp, err := resp.Recv() for ; err == nil; subtreeResp, err = resp.Recv() { -- 2.45.2 From d92569f2df5207e5cb36e0402afbb3336cd410b2 Mon Sep 17 00:00:00 2001 From: Airat Arifullin Date: Tue, 11 Jul 2023 13:31:49 +0300 Subject: [PATCH 3/3] [#390] cli: Fix bearer token reading for tree subcommands Signed-off-by: Airat Arifullin a.arifullin@yadro.com --- cmd/frostfs-cli/modules/tree/add.go | 7 ++++++- cmd/frostfs-cli/modules/tree/add_by_path.go | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/cmd/frostfs-cli/modules/tree/add.go b/cmd/frostfs-cli/modules/tree/add.go index 28718687d..4ac1ed198 100644 --- a/cmd/frostfs-cli/modules/tree/add.go +++ b/cmd/frostfs-cli/modules/tree/add.go @@ -55,13 +55,18 @@ func add(cmd *cobra.Command, _ []string) { rawCID := make([]byte, sha256.Size) cnr.Encode(rawCID) + var bt []byte + if t := common.ReadBearerToken(cmd, bearerFlagKey); t != nil { + bt = t.Marshal() + } + req := new(tree.AddRequest) req.Body = &tree.AddRequest_Body{ ContainerId: rawCID, TreeId: tid, ParentId: pid, Meta: meta, - BearerToken: common.ReadBearerToken(cmd, bearerFlagKey).Marshal(), + BearerToken: bt, } commonCmd.ExitOnErr(cmd, "signing message: %w", tree.SignMessage(req, pk)) diff --git a/cmd/frostfs-cli/modules/tree/add_by_path.go b/cmd/frostfs-cli/modules/tree/add_by_path.go index 284dab63a..f5d5083bd 100644 --- a/cmd/frostfs-cli/modules/tree/add_by_path.go +++ b/cmd/frostfs-cli/modules/tree/add_by_path.go @@ -63,6 +63,11 @@ func addByPath(cmd *cobra.Command, _ []string) { path, _ := cmd.Flags().GetString(pathFlagKey) + var bt []byte + if t := common.ReadBearerToken(cmd, bearerFlagKey); t != nil { + bt = t.Marshal() + } + req := new(tree.AddByPathRequest) req.Body = &tree.AddByPathRequest_Body{ ContainerId: rawCID, @@ -71,7 +76,7 @@ func addByPath(cmd *cobra.Command, _ []string) { // PathAttribute: pAttr, Path: strings.Split(path, "/"), Meta: meta, - BearerToken: common.ReadBearerToken(cmd, bearerFlagKey).Marshal(), + BearerToken: bt, } commonCmd.ExitOnErr(cmd, "signing message: %w", tree.SignMessage(req, pk)) -- 2.45.2