[#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.
type SearchSGPrm struct {
contextPrm
cnrID cid.ID
}
@ -60,13 +58,13 @@ var sgFilter = storagegroup.SearchQuery()
// SearchSG lists objects of storage group type in the container.
//
// 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
cliPrm.InContainer(prm.cnrID)
cliPrm.SetFilters(sgFilter)
cliPrm.UseKey(*x.key)
rdr, err := x.c.ObjectSearchInit(prm.ctx, cliPrm)
rdr, err := x.c.ObjectSearchInit(ctx, cliPrm)
if err != nil {
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.
//
// 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
cliPrm.FromContainer(prm.objAddr.Container())
cliPrm.ByID(prm.objAddr.Object())
cliPrm.UseKey(*x.key)
rdr, err := x.c.ObjectGetInit(prm.ctx, cliPrm)
rdr, err := x.c.ObjectGetInit(ctx, cliPrm)
if err != nil {
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.
// 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
if prm.raw {
@ -204,7 +202,7 @@ func (x Client) HeadObject(prm HeadObjectPrm) (*HeadObjectRes, error) {
cliPrm.ByID(prm.objAddr.Object())
cliPrm.UseKey(*x.key)
cliRes, err := x.c.ObjectHead(prm.ctx, cliPrm)
cliRes, err := x.c.ObjectHead(ctx, cliPrm)
if err == nil {
// pull out an error from 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) {
var prm GetObjectPrm
prm.SetContext(ctx)
prm.SetAddress(addr)
obj, err := c.GetObject(prm)
obj, err := c.GetObject(ctx, prm)
if err != nil {
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) {
var prm HeadObjectPrm
prm.SetContext(ctx)
prm.SetAddress(addr)
prm.SetTTL(ttl)
@ -253,7 +249,7 @@ func headObject(ctx context.Context, c Client, addr oid.Address, raw bool, ttl u
prm.SetRawFlag()
}
obj, err := c.HeadObject(prm)
obj, err := c.HeadObject(ctx, prm)
if err != nil {
return nil, err
}
@ -298,14 +294,14 @@ func (x HashPayloadRangeRes) Hash() []byte {
// from the remote server's local storage.
//
// 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
cliPrm.FromContainer(prm.objAddr.Container())
cliPrm.ByID(prm.objAddr.Object())
cliPrm.SetRangeList(prm.rng.GetOffset(), prm.rng.GetLength())
cliPrm.TillichZemorAlgo()
cliRes, err := x.c.ObjectHash(prm.ctx, cliPrm)
cliRes, err := x.c.ObjectHash(ctx, cliPrm)
if err == nil {
// pull out an error from 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) {
var prm HashPayloadRangePrm
prm.SetContext(ctx)
prm.SetAddress(addr)
prm.SetRange(rng)
res, err := c.HashPayloadRange(prm)
res, err := c.HashPayloadRange(ctx, prm)
if err != nil {
return nil, err
}

View file

@ -1,21 +1,9 @@
package frostfsapiclient
import (
"context"
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 {
objAddr oid.Address
}
@ -26,6 +14,5 @@ func (x *objectAddressPrm) SetAddress(addr oid.Address) {
}
type getObjectPrm struct {
contextPrm
objectAddressPrm
}

View file

@ -100,12 +100,11 @@ func (c *ClientCache) getSG(ctx context.Context, addr oid.Address, nm *netmap.Ne
continue
}
cctx, cancel := context.WithTimeout(ctx, c.sgTimeout)
getObjPrm.SetContext(cctx)
ctx, cancel := context.WithTimeout(ctx, c.sgTimeout)
// 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.
res, err := cli.GetObject(getObjPrm)
res, err := cli.GetObject(ctx, getObjPrm)
cancel()
@ -223,10 +222,9 @@ func (c ClientCache) ListSG(dst *storagegroup2.SearchSGDst, prm storagegroup2.Se
var cliPrm frostfsapiclient.SearchSGPrm
cliPrm.SetContext(prm.Context)
cliPrm.SetContainerID(prm.Container)
res, err := cli.SearchSG(cliPrm)
res, err := cli.SearchSG(prm.Context, cliPrm)
if err != nil {
return err
}