[#205] pool: fix using default key for requests

Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
Denis Kirillov 2022-04-12 16:48:55 +03:00 committed by Alex Vanin
parent 53e064e556
commit 3e75660802

View file

@ -221,7 +221,9 @@ func (c *clientWrapper) objectPut(ctx context.Context, prm PrmObjectPut) (*oid.I
if prm.stoken != nil { if prm.stoken != nil {
wObj.WithinSession(*prm.stoken) wObj.WithinSession(*prm.stoken)
} }
if prm.key != nil {
wObj.UseKey(*prm.key) wObj.UseKey(*prm.key)
}
if prm.btoken != nil { if prm.btoken != nil {
wObj.WithBearerToken(*prm.btoken) wObj.WithBearerToken(*prm.btoken)
@ -302,7 +304,9 @@ func (c *clientWrapper) objectDelete(ctx context.Context, prm PrmObjectDelete) e
cliPrm.WithBearerToken(*prm.btoken) cliPrm.WithBearerToken(*prm.btoken)
} }
if prm.key != nil {
cliPrm.UseKey(*prm.key) cliPrm.UseKey(*prm.key)
}
_, err := c.client.ObjectDelete(ctx, cliPrm) _, err := c.client.ObjectDelete(ctx, cliPrm)
return err return err
} }
@ -341,7 +345,9 @@ func (c *clientWrapper) objectGet(ctx context.Context, prm PrmObjectGet) (*ResGe
return nil, fmt.Errorf("init object reading on client: %w", err) return nil, fmt.Errorf("init object reading on client: %w", err)
} }
if prm.key != nil {
rObj.UseKey(*prm.key) rObj.UseKey(*prm.key)
}
if !rObj.ReadHeader(&res.Header) { if !rObj.ReadHeader(&res.Header) {
_, err = rObj.Close() _, err = rObj.Close()
@ -372,7 +378,9 @@ func (c *clientWrapper) objectHead(ctx context.Context, prm PrmObjectHead) (*obj
cliPrm.WithBearerToken(*prm.btoken) cliPrm.WithBearerToken(*prm.btoken)
} }
if prm.key != nil {
cliPrm.UseKey(*prm.key) cliPrm.UseKey(*prm.key)
}
var obj object.Object var obj object.Object
@ -413,7 +421,9 @@ func (c *clientWrapper) objectRange(ctx context.Context, prm PrmObjectRange) (*R
if err != nil { if err != nil {
return nil, fmt.Errorf("init payload range reading on client: %w", err) return nil, fmt.Errorf("init payload range reading on client: %w", err)
} }
if prm.key != nil {
res.UseKey(*prm.key) res.UseKey(*prm.key)
}
return &ResObjectRange{payload: res}, nil return &ResObjectRange{payload: res}, nil
} }
@ -436,7 +446,9 @@ func (c *clientWrapper) objectSearch(ctx context.Context, prm PrmObjectSearch) (
if err != nil { if err != nil {
return nil, fmt.Errorf("init object searching on client: %w", err) return nil, fmt.Errorf("init object searching on client: %w", err)
} }
if prm.key != nil {
res.UseKey(*prm.key) res.UseKey(*prm.key)
}
return &ResObjectSearch{r: res}, nil return &ResObjectSearch{r: res}, nil
} }
@ -1333,6 +1345,13 @@ func (p *Pool) call(ctx *callContext, f func() error) error {
return err return err
} }
// fillAppropriateKey use pool key if caller didn't specify its own.
func (p *Pool) fillAppropriateKey(prm *prmCommon) {
if prm.key == nil {
prm.key = p.key
}
}
// PutObject writes an object through a remote server using NeoFS API protocol. // PutObject writes an object through a remote server using NeoFS API protocol.
func (p *Pool) PutObject(ctx context.Context, prm PrmObjectPut) (*oid.ID, error) { func (p *Pool) PutObject(ctx context.Context, prm PrmObjectPut) (*oid.ID, error) {
var prmCtx prmContext var prmCtx prmContext
@ -1340,6 +1359,8 @@ func (p *Pool) PutObject(ctx context.Context, prm PrmObjectPut) (*oid.ID, error)
prmCtx.useVerb(sessionv2.ObjectVerbPut) prmCtx.useVerb(sessionv2.ObjectVerbPut)
prmCtx.useAddress(newAddressFromCnrID(prm.hdr.ContainerID())) prmCtx.useAddress(newAddressFromCnrID(prm.hdr.ContainerID()))
p.fillAppropriateKey(&prm.prmCommon)
var ctxCall callContext var ctxCall callContext
ctxCall.Context = ctx ctxCall.Context = ctx
@ -1354,7 +1375,6 @@ func (p *Pool) PutObject(ctx context.Context, prm PrmObjectPut) (*oid.ID, error)
return nil, fmt.Errorf("open default session: %w", err) return nil, fmt.Errorf("open default session: %w", err)
} }
} }
prm.key = ctxCall.key
id, err := ctxCall.client.objectPut(ctx, prm) id, err := ctxCall.client.objectPut(ctx, prm)
if err != nil { if err != nil {
@ -1376,6 +1396,8 @@ func (p *Pool) DeleteObject(ctx context.Context, prm PrmObjectDelete) error {
prmCtx.useVerb(sessionv2.ObjectVerbDelete) prmCtx.useVerb(sessionv2.ObjectVerbDelete)
prmCtx.useAddress(&prm.addr) prmCtx.useAddress(&prm.addr)
p.fillAppropriateKey(&prm.prmCommon)
var cc callContext var cc callContext
cc.Context = ctx cc.Context = ctx
@ -1422,6 +1444,8 @@ func (p *Pool) GetObject(ctx context.Context, prm PrmObjectGet) (*ResGetObject,
prmCtx.useVerb(sessionv2.ObjectVerbGet) prmCtx.useVerb(sessionv2.ObjectVerbGet)
prmCtx.useAddress(&prm.addr) prmCtx.useAddress(&prm.addr)
p.fillAppropriateKey(&prm.prmCommon)
var cc callContext var cc callContext
cc.Context = ctx cc.Context = ctx
cc.sessionTarget = prm.UseSession cc.sessionTarget = prm.UseSession
@ -1445,6 +1469,8 @@ func (p *Pool) HeadObject(ctx context.Context, prm PrmObjectHead) (*object.Objec
prmCtx.useVerb(sessionv2.ObjectVerbHead) prmCtx.useVerb(sessionv2.ObjectVerbHead)
prmCtx.useAddress(&prm.addr) prmCtx.useAddress(&prm.addr)
p.fillAppropriateKey(&prm.prmCommon)
var cc callContext var cc callContext
cc.Context = ctx cc.Context = ctx
@ -1491,6 +1517,8 @@ func (p *Pool) ObjectRange(ctx context.Context, prm PrmObjectRange) (*ResObjectR
prmCtx.useVerb(sessionv2.ObjectVerbRange) prmCtx.useVerb(sessionv2.ObjectVerbRange)
prmCtx.useAddress(&prm.addr) prmCtx.useAddress(&prm.addr)
p.fillAppropriateKey(&prm.prmCommon)
var cc callContext var cc callContext
cc.Context = ctx cc.Context = ctx
cc.sessionTarget = prm.UseSession cc.sessionTarget = prm.UseSession
@ -1555,6 +1583,8 @@ func (p *Pool) SearchObjects(ctx context.Context, prm PrmObjectSearch) (*ResObje
prmCtx.useVerb(sessionv2.ObjectVerbSearch) prmCtx.useVerb(sessionv2.ObjectVerbSearch)
prmCtx.useAddress(newAddressFromCnrID(&prm.cnrID)) prmCtx.useAddress(newAddressFromCnrID(&prm.cnrID))
p.fillAppropriateKey(&prm.prmCommon)
var cc callContext var cc callContext
cc.Context = ctx cc.Context = ctx