diff --git a/cmd/frostfs-cli/modules/tree/add.go b/cmd/frostfs-cli/modules/tree/add.go index 707a4d8ee..ea9245271 100644 --- a/cmd/frostfs-cli/modules/tree/add.go +++ b/cmd/frostfs-cli/modules/tree/add.go @@ -5,6 +5,7 @@ import ( "fmt" "strings" + "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" @@ -60,7 +61,7 @@ func add(cmd *cobra.Command, _ []string) { TreeId: tid, ParentId: pid, Meta: meta, - BearerToken: nil, // TODO: #1891 add token handling + BearerToken: common.ReadBearerToken(cmd, bearerFlagKey).Marshal(), } commonCmd.ExitOnErr(cmd, "message signing: %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 e83408a89..6b182e1e4 100644 --- a/cmd/frostfs-cli/modules/tree/add_by_path.go +++ b/cmd/frostfs-cli/modules/tree/add_by_path.go @@ -72,7 +72,7 @@ func addByPath(cmd *cobra.Command, _ []string) { // PathAttribute: pAttr, Path: strings.Split(path, "/"), Meta: meta, - BearerToken: nil, // TODO: #1891 add token handling + BearerToken: common.ReadBearerToken(cmd, bearerFlagKey).Marshal(), } commonCmd.ExitOnErr(cmd, "message signing: %w", tree.SignMessage(req, pk)) diff --git a/cmd/frostfs-cli/modules/tree/get_by_path.go b/cmd/frostfs-cli/modules/tree/get_by_path.go index 75acbaedf..6f6fc7ff9 100644 --- a/cmd/frostfs-cli/modules/tree/get_by_path.go +++ b/cmd/frostfs-cli/modules/tree/get_by_path.go @@ -71,7 +71,7 @@ func getByPath(cmd *cobra.Command, _ []string) { Path: strings.Split(path, "/"), LatestOnly: latestOnly, AllAttributes: true, - BearerToken: nil, // TODO: #1891 add token handling + BearerToken: common.ReadBearerToken(cmd, bearerFlagKey).Marshal(), } commonCmd.ExitOnErr(cmd, "message signing: %w", tree.SignMessage(req, pk)) diff --git a/cmd/frostfs-cli/modules/tree/root.go b/cmd/frostfs-cli/modules/tree/root.go index c70e6f5e2..b5de0dd6f 100644 --- a/cmd/frostfs-cli/modules/tree/root.go +++ b/cmd/frostfs-cli/modules/tree/root.go @@ -32,6 +32,8 @@ const ( pathAttributeFlagKey = "pattr" latestOnlyFlagKey = "latest" + + bearerFlagKey = "bearer" ) func initCTID(cmd *cobra.Command) { @@ -42,4 +44,6 @@ func initCTID(cmd *cobra.Command) { ff.String(treeIDFlagKey, "", "Tree ID") _ = cmd.MarkFlagRequired(treeIDFlagKey) + + ff.StringP(bearerFlagKey, "", "", "Path to bearer token") } diff --git a/cmd/internal/common/exit.go b/cmd/internal/common/exit.go index d38f27e02..9e4fa3098 100644 --- a/cmd/internal/common/exit.go +++ b/cmd/internal/common/exit.go @@ -46,6 +46,8 @@ func ExitOnErr(cmd *cobra.Command, errFmt string, err error) { } cmd.PrintErrln(err) - cmd.PersistentPostRun(cmd, nil) + if cmd.PersistentPostRun != nil { + cmd.PersistentPostRun(cmd, nil) + } os.Exit(code) }