cli: fix SDK PrmContainerGet usage for GetContainerPrm #590

Merged
fyrchik merged 2 commits from aarifullin/frostfs-node:fix/sdk_types_usage into master 2023-08-10 11:09:33 +00:00
6 changed files with 53 additions and 30 deletions

View file

@ -70,8 +70,8 @@ func ListContainers(ctx context.Context, prm ListContainersPrm) (res ListContain
// PutContainerPrm groups parameters of PutContainer operation. // PutContainerPrm groups parameters of PutContainer operation.
type PutContainerPrm struct { type PutContainerPrm struct {
commonPrm Client *client.Client
client.PrmContainerPut ClientParams client.PrmContainerPut
} }
// PutContainerRes groups the resulting values of PutContainer operation. // PutContainerRes groups the resulting values of PutContainer operation.
@ -93,7 +93,7 @@ func (x PutContainerRes) ID() cid.ID {
// //
// Returns any error which prevented the operation from completing correctly in error return. // Returns any error which prevented the operation from completing correctly in error return.
func PutContainer(ctx context.Context, prm PutContainerPrm) (res PutContainerRes, err error) { func PutContainer(ctx context.Context, prm PutContainerPrm) (res PutContainerRes, err error) {
cliRes, err := prm.cli.ContainerPut(ctx, prm.PrmContainerPut) cliRes, err := prm.Client.ContainerPut(ctx, prm.ClientParams)
if err == nil { if err == nil {
res.cnr = cliRes.ID() res.cnr = cliRes.ID()
} }
@ -103,13 +103,15 @@ func PutContainer(ctx context.Context, prm PutContainerPrm) (res PutContainerRes
// GetContainerPrm groups parameters of GetContainer operation. // GetContainerPrm groups parameters of GetContainer operation.
type GetContainerPrm struct { type GetContainerPrm struct {
commonPrm Client *client.Client
cliPrm client.PrmContainerGet ClientParams client.PrmContainerGet
} }
// SetContainer sets identifier of the container to be read. // SetContainer sets identifier of the container to be read.
//
// Deprecated: Use GetContainerPrm.ClientParams.ContainerID instead.
func (x *GetContainerPrm) SetContainer(id cid.ID) { func (x *GetContainerPrm) SetContainer(id cid.ID) {
*x.cliPrm.ContainerID = id x.ClientParams.ContainerID = &id
} }
// GetContainerRes groups the resulting values of GetContainer operation. // 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. // Returns any error which prevented the operation from completing correctly in error return.
func GetContainer(ctx context.Context, prm GetContainerPrm) (res GetContainerRes, err error) { 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 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 // IsACLExtendable checks if ACL of the container referenced by the given identifier
// can be extended. Client connection MUST BE correctly established in advance. // can be extended. Client connection MUST BE correctly established in advance.
func IsACLExtendable(ctx context.Context, c *client.Client, cnr cid.ID) (bool, error) { func IsACLExtendable(ctx context.Context, c *client.Client, cnr cid.ID) (bool, error) {
var prm GetContainerPrm prm := GetContainerPrm{
prm.SetClient(c) Client: c,
prm.SetContainer(cnr) ClientParams: client.PrmContainerGet{
ContainerID: &cnr,
},
}
res, err := GetContainer(ctx, prm) res, err := GetContainer(ctx, prm)
if err != nil { if err != nil {

View file

@ -101,12 +101,12 @@ It will be stored in sidechain when inner ring will accepts it.`,
commonCmd.ExitOnErr(cmd, "syncing container's settings rpc error: %w", err) commonCmd.ExitOnErr(cmd, "syncing container's settings rpc error: %w", err)
putPrm := internalclient.PutContainerPrm{ putPrm := internalclient.PutContainerPrm{
PrmContainerPut: client.PrmContainerPut{ Client: cli,
ClientParams: client.PrmContainerPut{
Container: &cnr, Container: &cnr,
Session: tok, Session: tok,
}, },
} }
putPrm.SetClient(cli)
res, err := internalclient.PutContainer(cmd.Context(), putPrm) res, err := internalclient.PutContainer(cmd.Context(), putPrm)
commonCmd.ExitOnErr(cmd, "put container rpc error: %w", err) commonCmd.ExitOnErr(cmd, "put container rpc error: %w", err)
@ -118,9 +118,12 @@ It will be stored in sidechain when inner ring will accepts it.`,
if containerAwait { if containerAwait {
cmd.Println("awaiting...") cmd.Println("awaiting...")
var getPrm internalclient.GetContainerPrm getPrm := internalclient.GetContainerPrm{
getPrm.SetClient(cli) Client: cli,
getPrm.SetContainer(id) ClientParams: client.PrmContainerGet{
ContainerID: &id,
},
}
for i := 0; i < awaitTimeout; i++ { for i := 0; i < awaitTimeout; i++ {
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)

View file

@ -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/commonflags"
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/key" "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/internal/key"
commonCmd "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common" 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" objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user"
"github.com/spf13/cobra" "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 { if force, _ := cmd.Flags().GetBool(commonflags.ForceFlag); !force {
common.PrintVerbose(cmd, "Reading the container to check ownership...") common.PrintVerbose(cmd, "Reading the container to check ownership...")
var getPrm internalclient.GetContainerPrm getPrm := internalclient.GetContainerPrm{
getPrm.SetClient(cli) Client: cli,
getPrm.SetContainer(id) ClientParams: client.PrmContainerGet{
ContainerID: &id,
},
}
resGet, err := internalclient.GetContainer(cmd.Context(), getPrm) resGet, err := internalclient.GetContainer(cmd.Context(), getPrm)
commonCmd.ExitOnErr(cmd, "can't get the container: %w", err) 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 { if containerAwait {
cmd.Println("awaiting...") cmd.Println("awaiting...")
var getPrm internalclient.GetContainerPrm getPrm := internalclient.GetContainerPrm{
getPrm.SetClient(cli) Client: cli,
getPrm.SetContainer(id) ClientParams: client.PrmContainerGet{
ContainerID: &id,
},
}
for i := 0; i < awaitTimeout; i++ { for i := 0; i < awaitTimeout; i++ {
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)

View file

@ -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/internal/key"
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/modules/util" "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-cli/modules/util"
commonCmd "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/internal/common" 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"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/acl" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/acl"
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id" 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) pk = key.GetOrGenerate(cmd)
cli := internalclient.GetSDKClientByFlag(cmd, pk, commonflags.RPC) cli := internalclient.GetSDKClientByFlag(cmd, pk, commonflags.RPC)
var prm internalclient.GetContainerPrm prm := internalclient.GetContainerPrm{
prm.SetClient(cli) Client: cli,
prm.SetContainer(id) ClientParams: client.PrmContainerGet{
ContainerID: &id,
},
}
res, err := internalclient.GetContainer(cmd.Context(), prm) res, err := internalclient.GetContainer(cmd.Context(), prm)
commonCmd.ExitOnErr(cmd, "rpc error: %w", err) commonCmd.ExitOnErr(cmd, "rpc error: %w", err)

View file

@ -52,8 +52,9 @@ var listContainersCmd = &cobra.Command{
res, err := internalclient.ListContainers(cmd.Context(), prm) res, err := internalclient.ListContainers(cmd.Context(), prm)
commonCmd.ExitOnErr(cmd, "rpc error: %w", err) commonCmd.ExitOnErr(cmd, "rpc error: %w", err)
var prmGet internalclient.GetContainerPrm prmGet := internalclient.GetContainerPrm{
prmGet.SetClient(cli) Client: cli,
}
containerIDs := res.IDList() containerIDs := res.IDList()
for _, cnrID := range containerIDs { for _, cnrID := range containerIDs {
@ -62,7 +63,7 @@ var listContainersCmd = &cobra.Command{
continue continue
} }
prmGet.SetContainer(cnrID) prmGet.ClientParams.ContainerID = &cnrID
res, err := internalclient.GetContainer(cmd.Context(), prmGet) res, err := internalclient.GetContainer(cmd.Context(), prmGet)
if err != nil { if err != nil {
cmd.Printf(" failed to read attributes: %v\n", err) cmd.Printf(" failed to read attributes: %v\n", err)

View file

@ -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) { func getPlacementPolicy(ctx context.Context, cnrID cid.ID, cli *client.Client) (netmapSDK.PlacementPolicy, error) {
var prm internalclient.GetContainerPrm prm := internalclient.GetContainerPrm{
prm.SetClient(cli) Client: cli,
prm.SetContainer(cnrID) ClientParams: client.PrmContainerGet{
ContainerID: &cnrID,
},
}
res, err := internalclient.GetContainer(ctx, prm) res, err := internalclient.GetContainer(ctx, prm)
if err != nil { if err != nil {