From 0754e6e65403b28cc73b1115f309939b2dd24c44 Mon Sep 17 00:00:00 2001 From: Airat Arifullin Date: Tue, 11 Jul 2023 13:31:49 +0300 Subject: [PATCH] [#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 4661853a5..ea815dbfe 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))