From 2ad08ece11dc504120ff376836b56e64e1f015d6 Mon Sep 17 00:00:00 2001 From: Airat Arifullin Date: Thu, 10 Aug 2023 11:09:36 +0300 Subject: [PATCH] [#590] cli: fix SDK PrmContainerGet usage for GetContainerPrm Signed-off-by: Airat Arifullin --- cmd/frostfs-cli/internal/client/client.go | 19 ++++++++++++------- cmd/frostfs-cli/modules/container/create.go | 9 ++++++--- cmd/frostfs-cli/modules/container/delete.go | 19 +++++++++++++------ cmd/frostfs-cli/modules/container/get.go | 10 +++++++--- cmd/frostfs-cli/modules/container/list.go | 7 ++++--- cmd/frostfs-cli/modules/object/nodes.go | 9 ++++++--- 6 files changed, 48 insertions(+), 25 deletions(-) diff --git a/cmd/frostfs-cli/internal/client/client.go b/cmd/frostfs-cli/internal/client/client.go index e250f8692..0d4d47cb3 100644 --- a/cmd/frostfs-cli/internal/client/client.go +++ b/cmd/frostfs-cli/internal/client/client.go @@ -103,13 +103,15 @@ func PutContainer(ctx context.Context, prm PutContainerPrm) (res PutContainerRes // GetContainerPrm groups parameters of GetContainer operation. type GetContainerPrm struct { - commonPrm - cliPrm client.PrmContainerGet + Client *client.Client + ClientParams client.PrmContainerGet } // SetContainer sets identifier of the container to be read. +// +// Deprecated: Use GetContainerPrm.ClientParams.ContainerID instead. func (x *GetContainerPrm) SetContainer(id cid.ID) { - *x.cliPrm.ContainerID = id + x.ClientParams.ContainerID = &id } // GetContainerRes groups the resulting values of GetContainer operation. @@ -126,7 +128,7 @@ func (x GetContainerRes) Container() containerSDK.Container { // // Returns any error which prevented the operation from completing correctly in error return. func GetContainer(ctx context.Context, prm GetContainerPrm) (res GetContainerRes, err error) { - res.cliRes, err = prm.cli.ContainerGet(ctx, prm.cliPrm) + res.cliRes, err = prm.Client.ContainerGet(ctx, prm.ClientParams) return } @@ -134,9 +136,12 @@ func GetContainer(ctx context.Context, prm GetContainerPrm) (res GetContainerRes // IsACLExtendable checks if ACL of the container referenced by the given identifier // can be extended. Client connection MUST BE correctly established in advance. func IsACLExtendable(ctx context.Context, c *client.Client, cnr cid.ID) (bool, error) { - var prm GetContainerPrm - prm.SetClient(c) - prm.SetContainer(cnr) + prm := GetContainerPrm{ + Client: c, + ClientParams: client.PrmContainerGet{ + ContainerID: &cnr, + }, + } res, err := GetContainer(ctx, prm) if err != nil { diff --git a/cmd/frostfs-cli/modules/container/create.go b/cmd/frostfs-cli/modules/container/create.go index 29c2422ed..cf6c77956 100644 --- a/cmd/frostfs-cli/modules/container/create.go +++ b/cmd/frostfs-cli/modules/container/create.go @@ -118,9 +118,12 @@ It will be stored in sidechain when inner ring will accepts it.`, if containerAwait { cmd.Println("awaiting...") - var getPrm internalclient.GetContainerPrm - getPrm.SetClient(cli) - getPrm.SetContainer(id) + getPrm := internalclient.GetContainerPrm{ + Client: cli, + ClientParams: client.PrmContainerGet{ + ContainerID: &id, + }, + } for i := 0; i < awaitTimeout; i++ { time.Sleep(1 * time.Second) diff --git a/cmd/frostfs-cli/modules/container/delete.go b/cmd/frostfs-cli/modules/container/delete.go index f5b69edfd..893bf842a 100644 --- a/cmd/frostfs-cli/modules/container/delete.go +++ b/cmd/frostfs-cli/modules/container/delete.go @@ -9,6 +9,7 @@ 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-sdk-go/client" objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user" "github.com/spf13/cobra" @@ -30,9 +31,12 @@ Only owner of the container has a permission to remove container.`, if force, _ := cmd.Flags().GetBool(commonflags.ForceFlag); !force { common.PrintVerbose(cmd, "Reading the container to check ownership...") - var getPrm internalclient.GetContainerPrm - getPrm.SetClient(cli) - getPrm.SetContainer(id) + getPrm := internalclient.GetContainerPrm{ + Client: cli, + ClientParams: client.PrmContainerGet{ + ContainerID: &id, + }, + } resGet, err := internalclient.GetContainer(cmd.Context(), getPrm) commonCmd.ExitOnErr(cmd, "can't get the container: %w", err) @@ -99,9 +103,12 @@ Only owner of the container has a permission to remove container.`, if containerAwait { cmd.Println("awaiting...") - var getPrm internalclient.GetContainerPrm - getPrm.SetClient(cli) - getPrm.SetContainer(id) + getPrm := internalclient.GetContainerPrm{ + Client: cli, + ClientParams: client.PrmContainerGet{ + ContainerID: &id, + }, + } for i := 0; i < awaitTimeout; i++ { time.Sleep(1 * time.Second) diff --git a/cmd/frostfs-cli/modules/container/get.go b/cmd/frostfs-cli/modules/container/get.go index 90bcc190a..f0590c7a1 100644 --- a/cmd/frostfs-cli/modules/container/get.go +++ b/cmd/frostfs-cli/modules/container/get.go @@ -10,6 +10,7 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/key" "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/modules/util" commonCmd "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common" + "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/acl" cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id" @@ -147,9 +148,12 @@ func getContainer(cmd *cobra.Command) (container.Container, *ecdsa.PrivateKey) { pk = key.GetOrGenerate(cmd) cli := internalclient.GetSDKClientByFlag(cmd, pk, commonflags.RPC) - var prm internalclient.GetContainerPrm - prm.SetClient(cli) - prm.SetContainer(id) + prm := internalclient.GetContainerPrm{ + Client: cli, + ClientParams: client.PrmContainerGet{ + ContainerID: &id, + }, + } res, err := internalclient.GetContainer(cmd.Context(), prm) commonCmd.ExitOnErr(cmd, "rpc error: %w", err) diff --git a/cmd/frostfs-cli/modules/container/list.go b/cmd/frostfs-cli/modules/container/list.go index 189cc05c7..0e8ea7ad4 100644 --- a/cmd/frostfs-cli/modules/container/list.go +++ b/cmd/frostfs-cli/modules/container/list.go @@ -52,8 +52,9 @@ var listContainersCmd = &cobra.Command{ res, err := internalclient.ListContainers(cmd.Context(), prm) commonCmd.ExitOnErr(cmd, "rpc error: %w", err) - var prmGet internalclient.GetContainerPrm - prmGet.SetClient(cli) + prmGet := internalclient.GetContainerPrm{ + Client: cli, + } containerIDs := res.IDList() for _, cnrID := range containerIDs { @@ -62,7 +63,7 @@ var listContainersCmd = &cobra.Command{ continue } - prmGet.SetContainer(cnrID) + prmGet.ClientParams.ContainerID = &cnrID res, err := internalclient.GetContainer(cmd.Context(), prmGet) if err != nil { cmd.Printf(" failed to read attributes: %v\n", err) diff --git a/cmd/frostfs-cli/modules/object/nodes.go b/cmd/frostfs-cli/modules/object/nodes.go index d2d20dc08..5499e5eec 100644 --- a/cmd/frostfs-cli/modules/object/nodes.go +++ b/cmd/frostfs-cli/modules/object/nodes.go @@ -155,9 +155,12 @@ func getPlacementPolicyAndNetmap(cmd *cobra.Command, cnrID cid.ID, cli *client.C } func getPlacementPolicy(ctx context.Context, cnrID cid.ID, cli *client.Client) (netmapSDK.PlacementPolicy, error) { - var prm internalclient.GetContainerPrm - prm.SetClient(cli) - prm.SetContainer(cnrID) + prm := internalclient.GetContainerPrm{ + Client: cli, + ClientParams: client.PrmContainerGet{ + ContainerID: &cnrID, + }, + } res, err := internalclient.GetContainer(ctx, prm) if err != nil {