diff --git a/cmd/neofs-cli/internal/client/client.go b/cmd/neofs-cli/internal/client/client.go index 706c84bcf..0fde595e8 100644 --- a/cmd/neofs-cli/internal/client/client.go +++ b/cmd/neofs-cli/internal/client/client.go @@ -337,6 +337,8 @@ func PutObject(prm PutObjectPrm) (*PutObjectRes, error) { wrt.MarkLocal() } + wrt.WithXHeaders(prm.xHeadersPrm()...) + if wrt.WriteHeader(*prm.hdr) { sz := prm.hdr.PayloadSize() @@ -434,6 +436,8 @@ func DeleteObject(prm DeleteObjectPrm) (*DeleteObjectRes, error) { delPrm.WithBearerToken(*prm.bearerToken) } + delPrm.WithXHeaders(prm.xHeadersPrm()...) + cliRes, err := prm.cli.ObjectDelete(context.Background(), delPrm) if err != nil { return nil, fmt.Errorf("remove object via client: %w", err) @@ -510,6 +514,8 @@ func GetObject(prm GetObjectPrm) (*GetObjectRes, error) { getPrm.MarkLocal() } + getPrm.WithXHeaders(prm.xHeadersPrm()...) + rdr, err := prm.cli.ObjectGetInit(context.Background(), getPrm) if err != nil { return nil, fmt.Errorf("init object reading on client: %w", err) @@ -586,6 +592,8 @@ func HeadObject(prm HeadObjectPrm) (*HeadObjectRes, error) { cliPrm.MarkLocal() } + cliPrm.WithXHeaders(prm.xHeadersPrm()...) + res, err := prm.cli.ObjectHead(context.Background(), cliPrm) if err != nil { return nil, fmt.Errorf("read object header via client: %w", err) @@ -649,6 +657,8 @@ func SearchObjects(prm SearchObjectsPrm) (*SearchObjectsRes, error) { cliPrm.MarkLocal() } + cliPrm.WithXHeaders(prm.xHeadersPrm()...) + rdr, err := prm.cli.ObjectSearchInit(context.Background(), cliPrm) if err != nil { return nil, fmt.Errorf("init object search: %w", err) @@ -760,6 +770,8 @@ func HashPayloadRanges(prm HashPayloadRangesPrm) (*HashPayloadRangesRes, error) cliPrm.WithBearerToken(*prm.bearerToken) } + cliPrm.WithXHeaders(prm.xHeadersPrm()...) + res, err := prm.cli.ObjectHash(context.Background(), cliPrm) if err != nil { 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.SetLength(prm.rng.GetLength()) + cliPrm.WithXHeaders(prm.xHeadersPrm()...) + rdr, err := prm.cli.ObjectRangeInit(context.Background(), cliPrm) if err != nil { return nil, fmt.Errorf("init payload reading: %w", err) diff --git a/cmd/neofs-cli/internal/client/prm.go b/cmd/neofs-cli/internal/client/prm.go index 186a60669..35af60e94 100644 --- a/cmd/neofs-cli/internal/client/prm.go +++ b/cmd/neofs-cli/internal/client/prm.go @@ -80,6 +80,8 @@ type commonObjectPrm struct { bearerTokenPrm local bool + + xHeaders []*session.XHeader } // SetTTL sets request TTL value. @@ -88,6 +90,19 @@ func (x *commonObjectPrm) SetTTL(ttl uint32) { } // SetXHeaders sets request X-Headers. -func (x *commonObjectPrm) SetXHeaders(_ []*session.XHeader) { - // FIXME: (neofs-node#1194) not supported by client +func (x *commonObjectPrm) SetXHeaders(hs []*session.XHeader) { + 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 } diff --git a/pkg/services/object/internal/client/client.go b/pkg/services/object/internal/client/client.go index 672c46937..20bc28a67 100644 --- a/pkg/services/object/internal/client/client.go +++ b/pkg/services/object/internal/client/client.go @@ -30,6 +30,8 @@ type commonPrm struct { tokenBearer *token.BearerToken local bool + + xHeaders []*session.XHeader } // SetClient sets base client for NeoFS API communication. @@ -75,8 +77,21 @@ func (x *commonPrm) SetTTL(ttl uint32) { // SetXHeaders sets request X-Headers. // // By default X-Headers will not be attached to the request. -func (x *commonPrm) SetXHeaders(_ []*session.XHeader) { - // FIXME: (neofs-node#1194) not supported by client +func (x *commonPrm) SetXHeaders(hs []*session.XHeader) { + 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 { @@ -148,6 +163,8 @@ func GetObject(prm GetObjectPrm) (*GetObjectRes, error) { prm.cliPrm.MarkLocal() } + prm.cliPrm.WithXHeaders(prm.xHeadersPrm()...) + rdr, err := prm.cli.ObjectGetInit(prm.ctx, prm.cliPrm) if err == nil { 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.WithXHeaders(prm.xHeadersPrm()...) + cliRes, err := prm.cli.ObjectHead(prm.ctx, prm.cliPrm) if err == nil { // pull out an error from status @@ -335,6 +354,7 @@ func PayloadRange(prm PayloadRangePrm) (*PayloadRangeRes, error) { } prm.cliPrm.SetLength(prm.ln) + prm.cliPrm.WithXHeaders(prm.xHeadersPrm()...) rdr, err := prm.cli.ObjectRangeInit(prm.ctx, prm.cliPrm) if err != nil { @@ -406,6 +426,8 @@ func PutObject(prm PutObjectPrm) (*PutObjectRes, error) { w.WithBearerToken(*prm.tokenBearer) } + w.WithXHeaders(prm.xHeadersPrm()...) + if w.WriteHeader(*prm.obj) { w.WritePayloadChunk(prm.obj.Payload()) } @@ -476,6 +498,8 @@ func SearchObjects(prm SearchObjectsPrm) (*SearchObjectsRes, error) { prm.cliPrm.WithBearerToken(*prm.tokenBearer) } + prm.cliPrm.WithXHeaders(prm.xHeadersPrm()...) + rdr, err := prm.cli.ObjectSearchInit(prm.ctx, prm.cliPrm) if err != nil { return nil, fmt.Errorf("init object searching in client: %w", err)