From 2ed9fd3f9445ee651fe434680af7c567328ae2c1 Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Thu, 6 Apr 2023 15:36:37 +0300 Subject: [PATCH] [#223] objectsvc: Refactor request parameters Resolve containedctx linter for commonPrm. Signed-off-by: Dmitrii Stepanov --- pkg/services/object/get/util.go | 9 ++--- pkg/services/object/head/remote.go | 3 +- pkg/services/object/internal/client/client.go | 36 +++++++------------ pkg/services/object/put/remote.go | 3 +- pkg/services/object/search/util.go | 3 +- 5 files changed, 19 insertions(+), 35 deletions(-) diff --git a/pkg/services/object/get/util.go b/pkg/services/object/get/util.go index 3bb68862b..09d8c67af 100644 --- a/pkg/services/object/get/util.go +++ b/pkg/services/object/get/util.go @@ -113,7 +113,6 @@ func (c *clientWrapper) getObject(ctx context.Context, exec *execCtx, info corec func (c *clientWrapper) getRange(ctx context.Context, exec *execCtx, key *ecdsa.PrivateKey, rng *object.Range) (*object.Object, error) { var prm internalclient.PayloadRangePrm - prm.SetContext(ctx) prm.SetClient(c.client) prm.SetTTL(exec.prm.common.TTL()) prm.SetNetmapEpoch(exec.curProcEpoch) @@ -128,7 +127,7 @@ func (c *clientWrapper) getRange(ctx context.Context, exec *execCtx, key *ecdsa. prm.SetRawFlag() } - res, err := internalclient.PayloadRange(prm) + res, err := internalclient.PayloadRange(ctx, prm) if err != nil { var errAccessDenied *apistatus.ObjectAccessDenied if errors.As(err, &errAccessDenied) { @@ -156,7 +155,6 @@ func (c *clientWrapper) getRange(ctx context.Context, exec *execCtx, key *ecdsa. func (c *clientWrapper) getHeadOnly(ctx context.Context, exec *execCtx, key *ecdsa.PrivateKey) (*object.Object, error) { var prm internalclient.HeadObjectPrm - prm.SetContext(ctx) prm.SetClient(c.client) prm.SetTTL(exec.prm.common.TTL()) prm.SetNetmapEpoch(exec.curProcEpoch) @@ -170,7 +168,7 @@ func (c *clientWrapper) getHeadOnly(ctx context.Context, exec *execCtx, key *ecd prm.SetRawFlag() } - res, err := internalclient.HeadObject(prm) + res, err := internalclient.HeadObject(ctx, prm) if err != nil { return nil, err } @@ -181,7 +179,6 @@ func (c *clientWrapper) getHeadOnly(ctx context.Context, exec *execCtx, key *ecd func (c *clientWrapper) get(ctx context.Context, exec *execCtx, key *ecdsa.PrivateKey) (*object.Object, error) { var prm internalclient.GetObjectPrm - prm.SetContext(ctx) prm.SetClient(c.client) prm.SetTTL(exec.prm.common.TTL()) prm.SetNetmapEpoch(exec.curProcEpoch) @@ -195,7 +192,7 @@ func (c *clientWrapper) get(ctx context.Context, exec *execCtx, key *ecdsa.Priva prm.SetRawFlag() } - res, err := internalclient.GetObject(prm) + res, err := internalclient.GetObject(ctx, prm) if err != nil { return nil, err } diff --git a/pkg/services/object/head/remote.go b/pkg/services/object/head/remote.go index f50c3422a..85f076a76 100644 --- a/pkg/services/object/head/remote.go +++ b/pkg/services/object/head/remote.go @@ -84,13 +84,12 @@ func (h *RemoteHeader) Head(ctx context.Context, prm *RemoteHeadPrm) (*object.Ob var headPrm internalclient.HeadObjectPrm - headPrm.SetContext(ctx) headPrm.SetClient(c) headPrm.SetPrivateKey(key) headPrm.SetAddress(prm.commonHeadPrm.addr) headPrm.SetTTL(remoteOpTTL) - res, err := internalclient.HeadObject(headPrm) + res, err := internalclient.HeadObject(ctx, headPrm) if err != nil { return nil, fmt.Errorf("(%T) could not head object in %s: %w", h, info.AddressGroup(), err) } diff --git a/pkg/services/object/internal/client/client.go b/pkg/services/object/internal/client/client.go index ee6777a5d..10a6af271 100644 --- a/pkg/services/object/internal/client/client.go +++ b/pkg/services/object/internal/client/client.go @@ -18,12 +18,9 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/session" ) -// nolint: containedctx type commonPrm struct { cli coreclient.Client - ctx context.Context - key *ecdsa.PrivateKey tokenSession *session.Object @@ -42,13 +39,6 @@ func (x *commonPrm) SetClient(cli coreclient.Client) { x.cli = cli } -// SetContext sets context.Context for network communication. -// -// Required parameter. -func (x *commonPrm) SetContext(ctx context.Context) { - x.ctx = ctx -} - // SetPrivateKey sets private key to sign the request(s). // // Required parameter. @@ -138,7 +128,7 @@ func (x GetObjectRes) Object() *object.Object { // - error of type *apistatus.ObjectAlreadyRemoved if the requested object is marked to be removed. // // GetObject ignores the provided session if it is not related to the requested object. -func GetObject(prm GetObjectPrm) (*GetObjectRes, error) { +func GetObject(ctx context.Context, prm GetObjectPrm) (*GetObjectRes, error) { // here we ignore session if it is opened for other object since such // request will almost definitely fail. The case can occur, for example, // when session is bound to the parent object and child object is requested. @@ -159,7 +149,7 @@ func GetObject(prm GetObjectPrm) (*GetObjectRes, error) { prm.cliPrm.UseKey(*prm.key) } - rdr, err := prm.cli.ObjectGetInit(prm.ctx, prm.cliPrm) + rdr, err := prm.cli.ObjectGetInit(ctx, prm.cliPrm) if err != nil { return nil, fmt.Errorf("init object reading: %w", err) } @@ -229,7 +219,7 @@ func (x HeadObjectRes) Header() *object.Object { // HeadObject reads object header by address. // -// Client, context and key must be set. +// Client and key must be set. // // Returns any error which prevented the operation from completing correctly in error return. // Returns: @@ -238,7 +228,7 @@ func (x HeadObjectRes) Header() *object.Object { // error of type *apistatus.ObjectAlreadyRemoved if the requested object is marked to be removed. // // HeadObject ignores the provided session if it is not related to the requested object. -func HeadObject(prm HeadObjectPrm) (*HeadObjectRes, error) { +func HeadObject(ctx context.Context, prm HeadObjectPrm) (*HeadObjectRes, error) { if prm.local { prm.cliPrm.MarkLocal() } @@ -254,7 +244,7 @@ func HeadObject(prm HeadObjectPrm) (*HeadObjectRes, error) { prm.cliPrm.WithXHeaders(prm.xHeaders...) - cliRes, err := prm.cli.ObjectHead(prm.ctx, prm.cliPrm) + cliRes, err := prm.cli.ObjectHead(ctx, prm.cliPrm) if err == nil { // pull out an error from status err = apistatus.ErrFromStatus(cliRes.Status()) @@ -327,7 +317,7 @@ const maxInitialBufferSize = 1024 * 1024 // 1 MiB // PayloadRange reads object payload range by address. // -// Client, context and key must be set. +// Client and key must be set. // // Returns any error which prevented the operation from completing correctly in error return. // Returns: @@ -337,7 +327,7 @@ const maxInitialBufferSize = 1024 * 1024 // 1 MiB // error of type *apistatus.ObjectOutOfRange if the requested range is too big. // // PayloadRange ignores the provided session if it is not related to the requested object. -func PayloadRange(prm PayloadRangePrm) (*PayloadRangeRes, error) { +func PayloadRange(ctx context.Context, prm PayloadRangePrm) (*PayloadRangeRes, error) { if prm.local { prm.cliPrm.MarkLocal() } @@ -354,7 +344,7 @@ func PayloadRange(prm PayloadRangePrm) (*PayloadRangeRes, error) { prm.cliPrm.SetLength(prm.ln) prm.cliPrm.WithXHeaders(prm.xHeaders...) - rdr, err := prm.cli.ObjectRangeInit(prm.ctx, prm.cliPrm) + rdr, err := prm.cli.ObjectRangeInit(ctx, prm.cliPrm) if err != nil { return nil, fmt.Errorf("init payload reading: %w", err) } @@ -408,10 +398,10 @@ func (x PutObjectRes) ID() oid.ID { // PutObject saves the object in local storage of the remote node. // -// Client, context and key must be set. +// Client and key must be set. // // Returns any error which prevented the operation from completing correctly in error return. -func PutObject(prm PutObjectPrm) (*PutObjectRes, error) { +func PutObject(ctx context.Context, prm PutObjectPrm) (*PutObjectRes, error) { var prmCli client.PrmObjectPutInit prmCli.MarkLocal() @@ -430,7 +420,7 @@ func PutObject(prm PutObjectPrm) (*PutObjectRes, error) { prmCli.WithXHeaders(prm.xHeaders...) - w, err := prm.cli.ObjectPutInit(prm.ctx, prmCli) + w, err := prm.cli.ObjectPutInit(ctx, prmCli) if err != nil { return nil, fmt.Errorf("init object writing on client: %w", err) } @@ -487,7 +477,7 @@ func (x SearchObjectsRes) IDList() []oid.ID { // SearchObjects selects objects from container which match the filters. // // Returns any error which prevented the operation from completing correctly in error return. -func SearchObjects(prm SearchObjectsPrm) (*SearchObjectsRes, error) { +func SearchObjects(ctx context.Context, prm SearchObjectsPrm) (*SearchObjectsRes, error) { if prm.local { prm.cliPrm.MarkLocal() } @@ -506,7 +496,7 @@ func SearchObjects(prm SearchObjectsPrm) (*SearchObjectsRes, error) { prm.cliPrm.UseKey(*prm.key) } - rdr, err := prm.cli.ObjectSearchInit(prm.ctx, prm.cliPrm) + rdr, err := prm.cli.ObjectSearchInit(ctx, prm.cliPrm) if err != nil { return nil, fmt.Errorf("init object searching in client: %w", err) } diff --git a/pkg/services/object/put/remote.go b/pkg/services/object/put/remote.go index 6933abca6..e7fa124fa 100644 --- a/pkg/services/object/put/remote.go +++ b/pkg/services/object/put/remote.go @@ -56,7 +56,6 @@ func (t *remoteTarget) Close(ctx context.Context) (*transformer.AccessIdentifier var prm internalclient.PutObjectPrm - prm.SetContext(ctx) prm.SetClient(c) prm.SetPrivateKey(t.privateKey) prm.SetSessionToken(t.commonPrm.SessionToken()) @@ -64,7 +63,7 @@ func (t *remoteTarget) Close(ctx context.Context) (*transformer.AccessIdentifier prm.SetXHeaders(t.commonPrm.XHeaders()) prm.SetObject(t.obj) - res, err := internalclient.PutObject(prm) + res, err := internalclient.PutObject(ctx, prm) if err != nil { return nil, fmt.Errorf("(%T) could not put object to %s: %w", t, t.nodeInfo.AddressGroup(), err) } diff --git a/pkg/services/object/search/util.go b/pkg/services/object/search/util.go index c12ed2c9f..49f3e5efd 100644 --- a/pkg/services/object/search/util.go +++ b/pkg/services/object/search/util.go @@ -99,7 +99,6 @@ func (c *clientWrapper) searchObjects(ctx context.Context, exec *execCtx, info c var prm internalclient.SearchObjectsPrm - prm.SetContext(ctx) prm.SetClient(c.client) prm.SetPrivateKey(key) prm.SetSessionToken(exec.prm.common.SessionToken()) @@ -110,7 +109,7 @@ func (c *clientWrapper) searchObjects(ctx context.Context, exec *execCtx, info c prm.SetContainerID(exec.containerID()) prm.SetFilters(exec.searchFilters()) - res, err := internalclient.SearchObjects(prm) + res, err := internalclient.SearchObjects(ctx, prm) if err != nil { return nil, err }