From c6411e4f873adfcb578fdbea46059ca8600c7c18 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Wed, 10 Feb 2021 00:55:38 +0300 Subject: [PATCH] [#372] cli/sg: Support bearer token in storagegroup command Add `--bearer` flag to storagegroup command similar to object command. Attach parsed bearer token to all API requests of storagegroup command. Signed-off-by: Leonard Lyubich --- cmd/neofs-cli/modules/storagegroup.go | 32 +++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/cmd/neofs-cli/modules/storagegroup.go b/cmd/neofs-cli/modules/storagegroup.go index ddde0b04b..5f81dca6b 100644 --- a/cmd/neofs-cli/modules/storagegroup.go +++ b/cmd/neofs-cli/modules/storagegroup.go @@ -52,6 +52,7 @@ var sgDelCmd = &cobra.Command{ const ( sgMembersFlag = "members" sgIDFlag = "id" + sgBearerFlag = "bearer" ) var ( @@ -62,6 +63,9 @@ var ( func init() { rootCmd.AddCommand(storagegroupCmd) + storagegroupCmd.PersistentFlags().String(sgBearerFlag, "", + "File with signed JSON or binary encoded bearer token") + storagegroupCmd.AddCommand(sgPutCmd) sgPutCmd.Flags().String("cid", "", "Container ID") _ = sgPutCmd.MarkFlagRequired("cid") @@ -115,6 +119,10 @@ func (c *sgHeadReceiver) Head(addr *objectSDK.Address) (interface{}, error) { } } +func sgBearerToken(cmd *cobra.Command) (*token.BearerToken, error) { + return getBearerToken(cmd, sgBearerFlag) +} + func putSG(cmd *cobra.Command, _ []string) error { ownerID, err := getOwnerID() if err != nil { @@ -137,6 +145,11 @@ func putSG(cmd *cobra.Command, _ []string) error { members = append(members, id) } + bearerToken, err := sgBearerToken(cmd) + if err != nil { + return err + } + ctx := context.Background() cli, tok, err := initSession(ctx) @@ -169,6 +182,7 @@ func putSG(cmd *cobra.Command, _ []string) error { WithObject(obj.Object()), append(globalCallOptions(), client.WithSession(tok), + client.WithBearer(bearerToken), )..., ) if err != nil { @@ -199,6 +213,11 @@ func getSG(cmd *cobra.Command, _ []string) error { return err } + bearerToken, err := sgBearerToken(cmd) + if err != nil { + return err + } + addr := objectSDK.NewAddress() addr.SetContainerID(cid) addr.SetObjectID(id) @@ -215,6 +234,7 @@ func getSG(cmd *cobra.Command, _ []string) error { WithAddress(addr), append(globalCallOptions(), client.WithSession(tok), + client.WithBearer(bearerToken), )..., ) if err != nil { @@ -247,6 +267,11 @@ func listSG(cmd *cobra.Command, _ []string) error { return err } + bearerToken, err := sgBearerToken(cmd) + if err != nil { + return err + } + ctx := context.Background() cli, tok, err := initSession(ctx) @@ -260,6 +285,7 @@ func listSG(cmd *cobra.Command, _ []string) error { WithSearchFilters(storagegroup.SearchQuery()), append(globalCallOptions(), client.WithSession(tok), + client.WithBearer(bearerToken), )..., ) if err != nil { @@ -286,6 +312,11 @@ func delSG(cmd *cobra.Command, _ []string) error { return err } + bearerToken, err := sgBearerToken(cmd) + if err != nil { + return err + } + ctx := context.Background() cli, tok, err := initSession(ctx) @@ -302,6 +333,7 @@ func delSG(cmd *cobra.Command, _ []string) error { WithAddress(addr), append(globalCallOptions(), client.WithSession(tok), + client.WithBearer(bearerToken), )..., ) if err != nil {