[#185] ir: Resolve containedctx linter

Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
Dmitrii Stepanov 2023-03-30 11:03:00 +03:00 committed by Gitea
parent c1cbe6ff2d
commit 8426d25f4b
3 changed files with 14 additions and 34 deletions

View file

@ -35,8 +35,6 @@ func (x *Client) SetPrivateKey(key *ecdsa.PrivateKey) {
// SearchSGPrm groups parameters of SearchSG operation. // SearchSGPrm groups parameters of SearchSG operation.
type SearchSGPrm struct { type SearchSGPrm struct {
contextPrm
cnrID cid.ID cnrID cid.ID
} }
@ -60,13 +58,13 @@ var sgFilter = storagegroup.SearchQuery()
// SearchSG lists objects of storage group type in the container. // SearchSG lists objects of storage group type in the 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 (x Client) SearchSG(prm SearchSGPrm) (*SearchSGRes, error) { func (x Client) SearchSG(ctx context.Context, prm SearchSGPrm) (*SearchSGRes, error) {
var cliPrm client.PrmObjectSearch var cliPrm client.PrmObjectSearch
cliPrm.InContainer(prm.cnrID) cliPrm.InContainer(prm.cnrID)
cliPrm.SetFilters(sgFilter) cliPrm.SetFilters(sgFilter)
cliPrm.UseKey(*x.key) cliPrm.UseKey(*x.key)
rdr, err := x.c.ObjectSearchInit(prm.ctx, cliPrm) rdr, err := x.c.ObjectSearchInit(ctx, cliPrm)
if err != nil { if err != nil {
return nil, fmt.Errorf("init object search: %w", err) return nil, fmt.Errorf("init object search: %w", err)
} }
@ -119,13 +117,13 @@ func (x GetObjectRes) Object() *object.Object {
// GetObject reads the object by address. // GetObject reads the object by address.
// //
// 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 (x Client) GetObject(prm GetObjectPrm) (*GetObjectRes, error) { func (x Client) GetObject(ctx context.Context, prm GetObjectPrm) (*GetObjectRes, error) {
var cliPrm client.PrmObjectGet var cliPrm client.PrmObjectGet
cliPrm.FromContainer(prm.objAddr.Container()) cliPrm.FromContainer(prm.objAddr.Container())
cliPrm.ByID(prm.objAddr.Object()) cliPrm.ByID(prm.objAddr.Object())
cliPrm.UseKey(*x.key) cliPrm.UseKey(*x.key)
rdr, err := x.c.ObjectGetInit(prm.ctx, cliPrm) rdr, err := x.c.ObjectGetInit(ctx, cliPrm)
if err != nil { if err != nil {
return nil, fmt.Errorf("init object search: %w", err) return nil, fmt.Errorf("init object search: %w", err)
} }
@ -189,7 +187,7 @@ func (x HeadObjectRes) Header() *object.Object {
// //
// 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.
// For raw requests, returns *object.SplitInfoError error if the requested object is virtual. // For raw requests, returns *object.SplitInfoError error if the requested object is virtual.
func (x Client) HeadObject(prm HeadObjectPrm) (*HeadObjectRes, error) { func (x Client) HeadObject(ctx context.Context, prm HeadObjectPrm) (*HeadObjectRes, error) {
var cliPrm client.PrmObjectHead var cliPrm client.PrmObjectHead
if prm.raw { if prm.raw {
@ -204,7 +202,7 @@ func (x Client) HeadObject(prm HeadObjectPrm) (*HeadObjectRes, error) {
cliPrm.ByID(prm.objAddr.Object()) cliPrm.ByID(prm.objAddr.Object())
cliPrm.UseKey(*x.key) cliPrm.UseKey(*x.key)
cliRes, err := x.c.ObjectHead(prm.ctx, cliPrm) cliRes, err := x.c.ObjectHead(ctx, cliPrm)
if err == nil { if err == nil {
// pull out an error from status // pull out an error from status
err = apistatus.ErrFromStatus(cliRes.Status()) err = apistatus.ErrFromStatus(cliRes.Status())
@ -231,10 +229,9 @@ func (x Client) HeadObject(prm HeadObjectPrm) (*HeadObjectRes, error) {
func GetObjectPayload(ctx context.Context, c Client, addr oid.Address) ([]byte, error) { func GetObjectPayload(ctx context.Context, c Client, addr oid.Address) ([]byte, error) {
var prm GetObjectPrm var prm GetObjectPrm
prm.SetContext(ctx)
prm.SetAddress(addr) prm.SetAddress(addr)
obj, err := c.GetObject(prm) obj, err := c.GetObject(ctx, prm)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -245,7 +242,6 @@ func GetObjectPayload(ctx context.Context, c Client, addr oid.Address) ([]byte,
func headObject(ctx context.Context, c Client, addr oid.Address, raw bool, ttl uint32) (*object.Object, error) { func headObject(ctx context.Context, c Client, addr oid.Address, raw bool, ttl uint32) (*object.Object, error) {
var prm HeadObjectPrm var prm HeadObjectPrm
prm.SetContext(ctx)
prm.SetAddress(addr) prm.SetAddress(addr)
prm.SetTTL(ttl) prm.SetTTL(ttl)
@ -253,7 +249,7 @@ func headObject(ctx context.Context, c Client, addr oid.Address, raw bool, ttl u
prm.SetRawFlag() prm.SetRawFlag()
} }
obj, err := c.HeadObject(prm) obj, err := c.HeadObject(ctx, prm)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -298,14 +294,14 @@ func (x HashPayloadRangeRes) Hash() []byte {
// from the remote server's local storage. // from the remote server's local storage.
// //
// 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 (x Client) HashPayloadRange(prm HashPayloadRangePrm) (res HashPayloadRangeRes, err error) { func (x Client) HashPayloadRange(ctx context.Context, prm HashPayloadRangePrm) (res HashPayloadRangeRes, err error) {
var cliPrm client.PrmObjectHash var cliPrm client.PrmObjectHash
cliPrm.FromContainer(prm.objAddr.Container()) cliPrm.FromContainer(prm.objAddr.Container())
cliPrm.ByID(prm.objAddr.Object()) cliPrm.ByID(prm.objAddr.Object())
cliPrm.SetRangeList(prm.rng.GetOffset(), prm.rng.GetLength()) cliPrm.SetRangeList(prm.rng.GetOffset(), prm.rng.GetLength())
cliPrm.TillichZemorAlgo() cliPrm.TillichZemorAlgo()
cliRes, err := x.c.ObjectHash(prm.ctx, cliPrm) cliRes, err := x.c.ObjectHash(ctx, cliPrm)
if err == nil { if err == nil {
// pull out an error from status // pull out an error from status
err = apistatus.ErrFromStatus(cliRes.Status()) err = apistatus.ErrFromStatus(cliRes.Status())
@ -331,11 +327,10 @@ func (x Client) HashPayloadRange(prm HashPayloadRangePrm) (res HashPayloadRangeR
func HashObjectRange(ctx context.Context, c Client, addr oid.Address, rng *object.Range) ([]byte, error) { func HashObjectRange(ctx context.Context, c Client, addr oid.Address, rng *object.Range) ([]byte, error) {
var prm HashPayloadRangePrm var prm HashPayloadRangePrm
prm.SetContext(ctx)
prm.SetAddress(addr) prm.SetAddress(addr)
prm.SetRange(rng) prm.SetRange(rng)
res, err := c.HashPayloadRange(prm) res, err := c.HashPayloadRange(ctx, prm)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -1,21 +1,9 @@
package frostfsapiclient package frostfsapiclient
import ( import (
"context"
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
) )
// nolint: containedctx
type contextPrm struct {
ctx context.Context
}
// SetContext sets context.Context used for network communication.
func (x *contextPrm) SetContext(ctx context.Context) {
x.ctx = ctx
}
type objectAddressPrm struct { type objectAddressPrm struct {
objAddr oid.Address objAddr oid.Address
} }
@ -26,6 +14,5 @@ func (x *objectAddressPrm) SetAddress(addr oid.Address) {
} }
type getObjectPrm struct { type getObjectPrm struct {
contextPrm
objectAddressPrm objectAddressPrm
} }

View file

@ -100,12 +100,11 @@ func (c *ClientCache) getSG(ctx context.Context, addr oid.Address, nm *netmap.Ne
continue continue
} }
cctx, cancel := context.WithTimeout(ctx, c.sgTimeout) ctx, cancel := context.WithTimeout(ctx, c.sgTimeout)
getObjPrm.SetContext(cctx)
// NOTE: we use the function which does not verify object integrity (checksums, signature), // NOTE: we use the function which does not verify object integrity (checksums, signature),
// but it would be useful to do as part of a data audit. // but it would be useful to do as part of a data audit.
res, err := cli.GetObject(getObjPrm) res, err := cli.GetObject(ctx, getObjPrm)
cancel() cancel()
@ -223,10 +222,9 @@ func (c ClientCache) ListSG(dst *storagegroup2.SearchSGDst, prm storagegroup2.Se
var cliPrm frostfsapiclient.SearchSGPrm var cliPrm frostfsapiclient.SearchSGPrm
cliPrm.SetContext(prm.Context)
cliPrm.SetContainerID(prm.Container) cliPrm.SetContainerID(prm.Container)
res, err := cli.SearchSG(cliPrm) res, err := cli.SearchSG(prm.Context, cliPrm)
if err != nil { if err != nil {
return err return err
} }