forked from TrueCloudLab/frostfs-node
[#1194] client: Support request X-headers
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
dd6d7d2d10
commit
b5bdcfc076
3 changed files with 57 additions and 4 deletions
|
@ -337,6 +337,8 @@ func PutObject(prm PutObjectPrm) (*PutObjectRes, error) {
|
||||||
wrt.MarkLocal()
|
wrt.MarkLocal()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wrt.WithXHeaders(prm.xHeadersPrm()...)
|
||||||
|
|
||||||
if wrt.WriteHeader(*prm.hdr) {
|
if wrt.WriteHeader(*prm.hdr) {
|
||||||
sz := prm.hdr.PayloadSize()
|
sz := prm.hdr.PayloadSize()
|
||||||
|
|
||||||
|
@ -434,6 +436,8 @@ func DeleteObject(prm DeleteObjectPrm) (*DeleteObjectRes, error) {
|
||||||
delPrm.WithBearerToken(*prm.bearerToken)
|
delPrm.WithBearerToken(*prm.bearerToken)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delPrm.WithXHeaders(prm.xHeadersPrm()...)
|
||||||
|
|
||||||
cliRes, err := prm.cli.ObjectDelete(context.Background(), delPrm)
|
cliRes, err := prm.cli.ObjectDelete(context.Background(), delPrm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("remove object via client: %w", err)
|
return nil, fmt.Errorf("remove object via client: %w", err)
|
||||||
|
@ -510,6 +514,8 @@ func GetObject(prm GetObjectPrm) (*GetObjectRes, error) {
|
||||||
getPrm.MarkLocal()
|
getPrm.MarkLocal()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getPrm.WithXHeaders(prm.xHeadersPrm()...)
|
||||||
|
|
||||||
rdr, err := prm.cli.ObjectGetInit(context.Background(), getPrm)
|
rdr, err := prm.cli.ObjectGetInit(context.Background(), getPrm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("init object reading on client: %w", err)
|
return nil, fmt.Errorf("init object reading on client: %w", err)
|
||||||
|
@ -586,6 +592,8 @@ func HeadObject(prm HeadObjectPrm) (*HeadObjectRes, error) {
|
||||||
cliPrm.MarkLocal()
|
cliPrm.MarkLocal()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cliPrm.WithXHeaders(prm.xHeadersPrm()...)
|
||||||
|
|
||||||
res, err := prm.cli.ObjectHead(context.Background(), cliPrm)
|
res, err := prm.cli.ObjectHead(context.Background(), cliPrm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("read object header via client: %w", err)
|
return nil, fmt.Errorf("read object header via client: %w", err)
|
||||||
|
@ -649,6 +657,8 @@ func SearchObjects(prm SearchObjectsPrm) (*SearchObjectsRes, error) {
|
||||||
cliPrm.MarkLocal()
|
cliPrm.MarkLocal()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cliPrm.WithXHeaders(prm.xHeadersPrm()...)
|
||||||
|
|
||||||
rdr, err := prm.cli.ObjectSearchInit(context.Background(), cliPrm)
|
rdr, err := prm.cli.ObjectSearchInit(context.Background(), 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)
|
||||||
|
@ -760,6 +770,8 @@ func HashPayloadRanges(prm HashPayloadRangesPrm) (*HashPayloadRangesRes, error)
|
||||||
cliPrm.WithBearerToken(*prm.bearerToken)
|
cliPrm.WithBearerToken(*prm.bearerToken)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cliPrm.WithXHeaders(prm.xHeadersPrm()...)
|
||||||
|
|
||||||
res, err := prm.cli.ObjectHash(context.Background(), cliPrm)
|
res, err := prm.cli.ObjectHash(context.Background(), cliPrm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("read payload hashes via client: %w", err)
|
return nil, fmt.Errorf("read payload hashes via client: %w", err)
|
||||||
|
@ -816,6 +828,8 @@ func PayloadRange(prm PayloadRangePrm) (*PayloadRangeRes, error) {
|
||||||
cliPrm.SetOffset(prm.rng.GetOffset())
|
cliPrm.SetOffset(prm.rng.GetOffset())
|
||||||
cliPrm.SetLength(prm.rng.GetLength())
|
cliPrm.SetLength(prm.rng.GetLength())
|
||||||
|
|
||||||
|
cliPrm.WithXHeaders(prm.xHeadersPrm()...)
|
||||||
|
|
||||||
rdr, err := prm.cli.ObjectRangeInit(context.Background(), cliPrm)
|
rdr, err := prm.cli.ObjectRangeInit(context.Background(), cliPrm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("init payload reading: %w", err)
|
return nil, fmt.Errorf("init payload reading: %w", err)
|
||||||
|
|
|
@ -80,6 +80,8 @@ type commonObjectPrm struct {
|
||||||
bearerTokenPrm
|
bearerTokenPrm
|
||||||
|
|
||||||
local bool
|
local bool
|
||||||
|
|
||||||
|
xHeaders []*session.XHeader
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetTTL sets request TTL value.
|
// SetTTL sets request TTL value.
|
||||||
|
@ -88,6 +90,19 @@ func (x *commonObjectPrm) SetTTL(ttl uint32) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetXHeaders sets request X-Headers.
|
// SetXHeaders sets request X-Headers.
|
||||||
func (x *commonObjectPrm) SetXHeaders(_ []*session.XHeader) {
|
func (x *commonObjectPrm) SetXHeaders(hs []*session.XHeader) {
|
||||||
// FIXME: (neofs-node#1194) not supported by client
|
x.xHeaders = hs
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x commonObjectPrm) xHeadersPrm() (res []string) {
|
||||||
|
if x.xHeaders != nil {
|
||||||
|
res = make([]string, len(x.xHeaders)*2)
|
||||||
|
|
||||||
|
for i := range x.xHeaders {
|
||||||
|
res[2*i] = x.xHeaders[i].Key()
|
||||||
|
res[2*i+1] = x.xHeaders[i].Value()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,8 @@ type commonPrm struct {
|
||||||
tokenBearer *token.BearerToken
|
tokenBearer *token.BearerToken
|
||||||
|
|
||||||
local bool
|
local bool
|
||||||
|
|
||||||
|
xHeaders []*session.XHeader
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetClient sets base client for NeoFS API communication.
|
// SetClient sets base client for NeoFS API communication.
|
||||||
|
@ -75,8 +77,21 @@ func (x *commonPrm) SetTTL(ttl uint32) {
|
||||||
// SetXHeaders sets request X-Headers.
|
// SetXHeaders sets request X-Headers.
|
||||||
//
|
//
|
||||||
// By default X-Headers will not be attached to the request.
|
// By default X-Headers will not be attached to the request.
|
||||||
func (x *commonPrm) SetXHeaders(_ []*session.XHeader) {
|
func (x *commonPrm) SetXHeaders(hs []*session.XHeader) {
|
||||||
// FIXME: (neofs-node#1194) not supported by client
|
x.xHeaders = hs
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x commonPrm) xHeadersPrm() (res []string) {
|
||||||
|
if len(x.xHeaders) > 0 {
|
||||||
|
res = make([]string, len(x.xHeaders)*2)
|
||||||
|
|
||||||
|
for i := range x.xHeaders {
|
||||||
|
res[2*i] = x.xHeaders[i].Key()
|
||||||
|
res[2*i+1] = x.xHeaders[i].Value()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
type readPrmCommon struct {
|
type readPrmCommon struct {
|
||||||
|
@ -148,6 +163,8 @@ func GetObject(prm GetObjectPrm) (*GetObjectRes, error) {
|
||||||
prm.cliPrm.MarkLocal()
|
prm.cliPrm.MarkLocal()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prm.cliPrm.WithXHeaders(prm.xHeadersPrm()...)
|
||||||
|
|
||||||
rdr, err := prm.cli.ObjectGetInit(prm.ctx, prm.cliPrm)
|
rdr, err := prm.cli.ObjectGetInit(prm.ctx, prm.cliPrm)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return nil, fmt.Errorf("init object reading: %w", err)
|
return nil, fmt.Errorf("init object reading: %w", err)
|
||||||
|
@ -243,6 +260,8 @@ func HeadObject(prm HeadObjectPrm) (*HeadObjectRes, error) {
|
||||||
prm.cliPrm.WithBearerToken(*prm.tokenBearer)
|
prm.cliPrm.WithBearerToken(*prm.tokenBearer)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prm.cliPrm.WithXHeaders(prm.xHeadersPrm()...)
|
||||||
|
|
||||||
cliRes, err := prm.cli.ObjectHead(prm.ctx, prm.cliPrm)
|
cliRes, err := prm.cli.ObjectHead(prm.ctx, prm.cliPrm)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
// pull out an error from status
|
// pull out an error from status
|
||||||
|
@ -335,6 +354,7 @@ func PayloadRange(prm PayloadRangePrm) (*PayloadRangeRes, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
prm.cliPrm.SetLength(prm.ln)
|
prm.cliPrm.SetLength(prm.ln)
|
||||||
|
prm.cliPrm.WithXHeaders(prm.xHeadersPrm()...)
|
||||||
|
|
||||||
rdr, err := prm.cli.ObjectRangeInit(prm.ctx, prm.cliPrm)
|
rdr, err := prm.cli.ObjectRangeInit(prm.ctx, prm.cliPrm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -406,6 +426,8 @@ func PutObject(prm PutObjectPrm) (*PutObjectRes, error) {
|
||||||
w.WithBearerToken(*prm.tokenBearer)
|
w.WithBearerToken(*prm.tokenBearer)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
w.WithXHeaders(prm.xHeadersPrm()...)
|
||||||
|
|
||||||
if w.WriteHeader(*prm.obj) {
|
if w.WriteHeader(*prm.obj) {
|
||||||
w.WritePayloadChunk(prm.obj.Payload())
|
w.WritePayloadChunk(prm.obj.Payload())
|
||||||
}
|
}
|
||||||
|
@ -476,6 +498,8 @@ func SearchObjects(prm SearchObjectsPrm) (*SearchObjectsRes, error) {
|
||||||
prm.cliPrm.WithBearerToken(*prm.tokenBearer)
|
prm.cliPrm.WithBearerToken(*prm.tokenBearer)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prm.cliPrm.WithXHeaders(prm.xHeadersPrm()...)
|
||||||
|
|
||||||
rdr, err := prm.cli.ObjectSearchInit(prm.ctx, prm.cliPrm)
|
rdr, err := prm.cli.ObjectSearchInit(prm.ctx, prm.cliPrm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("init object searching in client: %w", err)
|
return nil, fmt.Errorf("init object searching in client: %w", err)
|
||||||
|
|
Loading…
Reference in a new issue