From 74c91eeef5fe520ae3f73a882315b1c9189ede53 Mon Sep 17 00:00:00 2001 From: aarifullin Date: Wed, 1 Nov 2023 18:18:28 +0300 Subject: [PATCH] [#777] client: Refactor PrmContainerList, PrmObjectSearch usage Signed-off-by: Airat Arifullin --- cmd/frostfs-cli/internal/client/client.go | 23 +++++----------- cmd/frostfs-cli/modules/container/list.go | 2 +- go.mod | 2 +- go.sum | 4 +-- pkg/services/object/internal/client/client.go | 26 +++++-------------- 5 files changed, 18 insertions(+), 39 deletions(-) diff --git a/cmd/frostfs-cli/internal/client/client.go b/cmd/frostfs-cli/internal/client/client.go index b370ff3aa..9807e111c 100644 --- a/cmd/frostfs-cli/internal/client/client.go +++ b/cmd/frostfs-cli/internal/client/client.go @@ -689,24 +689,15 @@ func (x SearchObjectsRes) IDList() []oid.ID { // // Returns any error which prevented the operation from completing correctly in error return. func SearchObjects(ctx context.Context, prm SearchObjectsPrm) (*SearchObjectsRes, error) { - var cliPrm client.PrmObjectSearch - cliPrm.InContainer(prm.cnrID) - cliPrm.SetFilters(prm.filters) - - if prm.sessionToken != nil { - cliPrm.WithinSession(*prm.sessionToken) + cliPrm := client.PrmObjectSearch{ + XHeaders: prm.xHeaders, + Local: prm.local, + BearerToken: prm.bearerToken, + Session: prm.sessionToken, + ContainerID: &prm.cnrID, + Filters: prm.filters, } - if prm.bearerToken != nil { - cliPrm.WithBearerToken(*prm.bearerToken) - } - - if prm.local { - cliPrm.MarkLocal() - } - - cliPrm.WithXHeaders(prm.xHeaders...) - rdr, err := prm.cli.ObjectSearchInit(ctx, cliPrm) if err != nil { return nil, fmt.Errorf("init object search: %w", err) diff --git a/cmd/frostfs-cli/modules/container/list.go b/cmd/frostfs-cli/modules/container/list.go index 1c7787760..1e7ba96ea 100644 --- a/cmd/frostfs-cli/modules/container/list.go +++ b/cmd/frostfs-cli/modules/container/list.go @@ -47,7 +47,7 @@ var listContainersCmd = &cobra.Command{ var prm internalclient.ListContainersPrm prm.SetClient(cli) - prm.SetAccount(idUser) + prm.Account = &idUser res, err := internalclient.ListContainers(cmd.Context(), prm) commonCmd.ExitOnErr(cmd, "rpc error: %w", err) diff --git a/go.mod b/go.mod index 9e97238c5..37cb477bf 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( git.frostfs.info/TrueCloudLab/frostfs-api-go/v2 v2.16.1-0.20231031104748-498877e378fd git.frostfs.info/TrueCloudLab/frostfs-contract v0.18.1-0.20231102065436-9ed3845aa989 git.frostfs.info/TrueCloudLab/frostfs-observability v0.0.0-20230531082742-c97d21411eb6 - git.frostfs.info/TrueCloudLab/frostfs-sdk-go v0.0.0-20231027075445-a02c0bfac885 + git.frostfs.info/TrueCloudLab/frostfs-sdk-go v0.0.0-20231101144515-6fbe1595cb3d git.frostfs.info/TrueCloudLab/hrw v1.2.1 git.frostfs.info/TrueCloudLab/tzhash v1.8.0 github.com/cheggaaa/pb v1.0.29 diff --git a/go.sum b/go.sum index 80b600167..62fd85c86 100644 --- a/go.sum +++ b/go.sum @@ -732,8 +732,8 @@ git.frostfs.info/TrueCloudLab/frostfs-crypto v0.6.0 h1:FxqFDhQYYgpe41qsIHVOcdzSV git.frostfs.info/TrueCloudLab/frostfs-crypto v0.6.0/go.mod h1:RUIKZATQLJ+TaYQa60X2fTDwfuhMfm8Ar60bQ5fr+vU= git.frostfs.info/TrueCloudLab/frostfs-observability v0.0.0-20230531082742-c97d21411eb6 h1:aGQ6QaAnTerQ5Dq5b2/f9DUQtSqPkZZ/bkMx/HKuLCo= git.frostfs.info/TrueCloudLab/frostfs-observability v0.0.0-20230531082742-c97d21411eb6/go.mod h1:W8Nn08/l6aQ7UlIbpF7FsQou7TVpcRD1ZT1KG4TrFhE= -git.frostfs.info/TrueCloudLab/frostfs-sdk-go v0.0.0-20231027075445-a02c0bfac885 h1:tbOUgoaN3usFTUA9k62z96uQDRNJUiz9TxzJr1AtSFo= -git.frostfs.info/TrueCloudLab/frostfs-sdk-go v0.0.0-20231027075445-a02c0bfac885/go.mod h1:t1akKcUH7iBrFHX8rSXScYMP17k2kYQXMbZooiL5Juw= +git.frostfs.info/TrueCloudLab/frostfs-sdk-go v0.0.0-20231101144515-6fbe1595cb3d h1:KVHsNsEoedQ1+f+eDq88AFKkLePGfnygt4bcUQrCgPw= +git.frostfs.info/TrueCloudLab/frostfs-sdk-go v0.0.0-20231101144515-6fbe1595cb3d/go.mod h1:t1akKcUH7iBrFHX8rSXScYMP17k2kYQXMbZooiL5Juw= git.frostfs.info/TrueCloudLab/hrw v1.2.1 h1:ccBRK21rFvY5R1WotI6LNoPlizk7qSvdfD8lNIRudVc= git.frostfs.info/TrueCloudLab/hrw v1.2.1/go.mod h1:C1Ygde2n843yTZEQ0FP69jYiuaYV0kriLvP4zm8JuvM= git.frostfs.info/TrueCloudLab/rfc6979 v0.4.0 h1:M2KR3iBj7WpY3hP10IevfIB9MURr4O9mwVfJ+SjT3HA= diff --git a/pkg/services/object/internal/client/client.go b/pkg/services/object/internal/client/client.go index e0a7e562a..dd2de0fd1 100644 --- a/pkg/services/object/internal/client/client.go +++ b/pkg/services/object/internal/client/client.go @@ -474,12 +474,12 @@ type SearchObjectsPrm struct { // // Required parameter. func (x *SearchObjectsPrm) SetContainerID(id cid.ID) { - x.cliPrm.InContainer(id) + x.cliPrm.ContainerID = &id } // SetFilters sets search filters. func (x *SearchObjectsPrm) SetFilters(fs objectSDK.SearchFilters) { - x.cliPrm.SetFilters(fs) + x.cliPrm.Filters = fs } // SearchObjectsRes groups the resulting values of SearchObjects operation. @@ -496,23 +496,11 @@ func (x SearchObjectsRes) IDList() []oid.ID { // // Returns any error which prevented the operation from completing correctly in error return. func SearchObjects(ctx context.Context, prm SearchObjectsPrm) (*SearchObjectsRes, error) { - if prm.local { - prm.cliPrm.MarkLocal() - } - - if prm.tokenSession != nil { - prm.cliPrm.WithinSession(*prm.tokenSession) - } - - if prm.tokenBearer != nil { - prm.cliPrm.WithBearerToken(*prm.tokenBearer) - } - - prm.cliPrm.WithXHeaders(prm.xHeaders...) - - if prm.key != nil { - prm.cliPrm.UseKey(*prm.key) - } + prm.cliPrm.Local = prm.local + prm.cliPrm.Session = prm.tokenSession + prm.cliPrm.BearerToken = prm.tokenBearer + prm.cliPrm.XHeaders = prm.xHeaders + prm.cliPrm.Key = prm.key rdr, err := prm.cli.ObjectSearchInit(ctx, prm.cliPrm) if err != nil {