forked from TrueCloudLab/frostfs-sdk-go
[#121] client: Make PrmObjectSearch fields public
Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
This commit is contained in:
parent
a487033505
commit
a9237aabd2
1 changed files with 79 additions and 36 deletions
|
@ -24,19 +24,26 @@ import (
|
||||||
|
|
||||||
// PrmObjectSearch groups parameters of ObjectSearch operation.
|
// PrmObjectSearch groups parameters of ObjectSearch operation.
|
||||||
type PrmObjectSearch struct {
|
type PrmObjectSearch struct {
|
||||||
meta v2session.RequestMetaHeader
|
XHeaders []string
|
||||||
|
|
||||||
key *ecdsa.PrivateKey
|
Local bool
|
||||||
|
|
||||||
cnrSet bool
|
BearerToken *bearer.Token
|
||||||
cnrID cid.ID
|
|
||||||
|
|
||||||
filters object.SearchFilters
|
Session *session.Object
|
||||||
|
|
||||||
|
ContainerID *cid.ID
|
||||||
|
|
||||||
|
Key *ecdsa.PrivateKey
|
||||||
|
|
||||||
|
Filters object.SearchFilters
|
||||||
}
|
}
|
||||||
|
|
||||||
// MarkLocal tells the server to execute the operation locally.
|
// MarkLocal tells the server to execute the operation locally.
|
||||||
|
//
|
||||||
|
// Deprecated: Use PrmObjectSearch.Local instead.
|
||||||
func (x *PrmObjectSearch) MarkLocal() {
|
func (x *PrmObjectSearch) MarkLocal() {
|
||||||
x.meta.SetTTL(1)
|
x.Local = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithinSession specifies session within which the search query must be executed.
|
// WithinSession specifies session within which the search query must be executed.
|
||||||
|
@ -45,10 +52,10 @@ func (x *PrmObjectSearch) MarkLocal() {
|
||||||
// This may affect the execution of an operation (e.g. access control).
|
// This may affect the execution of an operation (e.g. access control).
|
||||||
//
|
//
|
||||||
// Must be signed.
|
// Must be signed.
|
||||||
|
//
|
||||||
|
// Deprecated: Use PrmObjectSearch.Session instead.
|
||||||
func (x *PrmObjectSearch) WithinSession(t session.Object) {
|
func (x *PrmObjectSearch) WithinSession(t session.Object) {
|
||||||
var tokv2 v2session.Token
|
x.Session = &t
|
||||||
t.WriteToV2(&tokv2)
|
|
||||||
x.meta.SetSessionToken(&tokv2)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithBearerToken attaches bearer token to be used for the operation.
|
// WithBearerToken attaches bearer token to be used for the operation.
|
||||||
|
@ -56,37 +63,44 @@ func (x *PrmObjectSearch) WithinSession(t session.Object) {
|
||||||
// If set, underlying eACL rules will be used in access control.
|
// If set, underlying eACL rules will be used in access control.
|
||||||
//
|
//
|
||||||
// Must be signed.
|
// Must be signed.
|
||||||
|
//
|
||||||
|
// Deprecated: Use PrmObjectSearch.BearerToken instead.
|
||||||
func (x *PrmObjectSearch) WithBearerToken(t bearer.Token) {
|
func (x *PrmObjectSearch) WithBearerToken(t bearer.Token) {
|
||||||
var v2token acl.BearerToken
|
x.BearerToken = &t
|
||||||
t.WriteToV2(&v2token)
|
|
||||||
x.meta.SetBearerToken(&v2token)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithXHeaders specifies list of extended headers (string key-value pairs)
|
// WithXHeaders specifies list of extended headers (string key-value pairs)
|
||||||
// to be attached to the request. Must have an even length.
|
// to be attached to the request. Must have an even length.
|
||||||
//
|
//
|
||||||
// Slice must not be mutated until the operation completes.
|
// Slice must not be mutated until the operation completes.
|
||||||
|
//
|
||||||
|
// Deprecated: Use PrmObjectSearch.XHeaders instead.
|
||||||
func (x *PrmObjectSearch) WithXHeaders(hs ...string) {
|
func (x *PrmObjectSearch) WithXHeaders(hs ...string) {
|
||||||
writeXHeadersToMeta(hs, &x.meta)
|
x.XHeaders = hs
|
||||||
}
|
}
|
||||||
|
|
||||||
// UseKey specifies private key to sign the requests.
|
// UseKey specifies private key to sign the requests.
|
||||||
// If key is not provided, then Client default key is used.
|
// If key is not provided, then Client default key is used.
|
||||||
|
//
|
||||||
|
// Deprecated: Use PrmObjectSearch.Key instead.
|
||||||
func (x *PrmObjectSearch) UseKey(key ecdsa.PrivateKey) {
|
func (x *PrmObjectSearch) UseKey(key ecdsa.PrivateKey) {
|
||||||
x.key = &key
|
x.Key = &key
|
||||||
}
|
}
|
||||||
|
|
||||||
// InContainer specifies the container in which to look for objects.
|
// InContainer specifies the container in which to look for objects.
|
||||||
// Required parameter.
|
// Required parameter.
|
||||||
|
//
|
||||||
|
// Deprecated: Use PrmObjectSearch.ContainerID instead.
|
||||||
func (x *PrmObjectSearch) InContainer(id cid.ID) {
|
func (x *PrmObjectSearch) InContainer(id cid.ID) {
|
||||||
x.cnrID = id
|
x.ContainerID = &id
|
||||||
x.cnrSet = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetFilters sets filters by which to select objects. All container objects
|
// SetFilters sets filters by which to select objects. All container objects
|
||||||
// match unset/empty filters.
|
// match unset/empty filters.
|
||||||
|
//
|
||||||
|
// Deprecated: Use PrmObjectSearch.Filters instead.
|
||||||
func (x *PrmObjectSearch) SetFilters(filters object.SearchFilters) {
|
func (x *PrmObjectSearch) SetFilters(filters object.SearchFilters) {
|
||||||
x.filters = filters
|
x.Filters = filters
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResObjectSearch groups the final result values of ObjectSearch operation.
|
// ResObjectSearch groups the final result values of ObjectSearch operation.
|
||||||
|
@ -212,6 +226,48 @@ func (x *ObjectListReader) Close() (*ResObjectSearch, error) {
|
||||||
return &x.res, nil
|
return &x.res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (x *PrmObjectSearch) buildRequest(c *Client) (*v2object.SearchRequest, error) {
|
||||||
|
if x.ContainerID == nil {
|
||||||
|
return nil, errorMissingContainer
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(x.XHeaders)%2 != 0 {
|
||||||
|
return nil, errorInvalidXHeaders
|
||||||
|
}
|
||||||
|
|
||||||
|
meta := new(v2session.RequestMetaHeader)
|
||||||
|
writeXHeadersToMeta(x.XHeaders, meta)
|
||||||
|
|
||||||
|
if x.BearerToken != nil {
|
||||||
|
v2BearerToken := new(acl.BearerToken)
|
||||||
|
x.BearerToken.WriteToV2(v2BearerToken)
|
||||||
|
meta.SetBearerToken(v2BearerToken)
|
||||||
|
}
|
||||||
|
|
||||||
|
if x.Session != nil {
|
||||||
|
v2SessionToken := new(v2session.Token)
|
||||||
|
x.Session.WriteToV2(v2SessionToken)
|
||||||
|
meta.SetSessionToken(v2SessionToken)
|
||||||
|
}
|
||||||
|
|
||||||
|
if x.Local {
|
||||||
|
meta.SetTTL(1)
|
||||||
|
}
|
||||||
|
cnrV2 := new(v2refs.ContainerID)
|
||||||
|
x.ContainerID.WriteToV2(cnrV2)
|
||||||
|
|
||||||
|
body := new(v2object.SearchRequestBody)
|
||||||
|
body.SetVersion(1)
|
||||||
|
body.SetContainerID(cnrV2)
|
||||||
|
body.SetFilters(x.Filters.ToV2())
|
||||||
|
|
||||||
|
req := new(v2object.SearchRequest)
|
||||||
|
req.SetBody(body)
|
||||||
|
c.prepareRequest(req, meta)
|
||||||
|
|
||||||
|
return req, nil
|
||||||
|
}
|
||||||
|
|
||||||
// ObjectSearchInit initiates object selection through a remote server using FrostFS API protocol.
|
// ObjectSearchInit initiates object selection through a remote server using FrostFS API protocol.
|
||||||
//
|
//
|
||||||
// The call only opens the transmission channel, explicit fetching of matched objects
|
// The call only opens the transmission channel, explicit fetching of matched objects
|
||||||
|
@ -221,30 +277,17 @@ func (x *ObjectListReader) Close() (*ResObjectSearch, error) {
|
||||||
// Returns an error if parameters are set incorrectly (see PrmObjectSearch docs).
|
// Returns an error if parameters are set incorrectly (see PrmObjectSearch docs).
|
||||||
// Context is required and must not be nil. It is used for network communication.
|
// Context is required and must not be nil. It is used for network communication.
|
||||||
func (c *Client) ObjectSearchInit(ctx context.Context, prm PrmObjectSearch) (*ObjectListReader, error) {
|
func (c *Client) ObjectSearchInit(ctx context.Context, prm PrmObjectSearch) (*ObjectListReader, error) {
|
||||||
// check parameters
|
req, err := prm.buildRequest(c)
|
||||||
if !prm.cnrSet {
|
if err != nil {
|
||||||
return nil, errorMissingContainer
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var cidV2 v2refs.ContainerID
|
key := prm.Key
|
||||||
prm.cnrID.WriteToV2(&cidV2)
|
|
||||||
|
|
||||||
var body v2object.SearchRequestBody
|
|
||||||
body.SetVersion(1)
|
|
||||||
body.SetContainerID(&cidV2)
|
|
||||||
body.SetFilters(prm.filters.ToV2())
|
|
||||||
|
|
||||||
// init reader
|
|
||||||
var req v2object.SearchRequest
|
|
||||||
req.SetBody(&body)
|
|
||||||
c.prepareRequest(&req, &prm.meta)
|
|
||||||
|
|
||||||
key := prm.key
|
|
||||||
if key == nil {
|
if key == nil {
|
||||||
key = &c.prm.key
|
key = &c.prm.key
|
||||||
}
|
}
|
||||||
|
|
||||||
err := signature.SignServiceMessage(key, &req)
|
err = signature.SignServiceMessage(key, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("sign request: %w", err)
|
return nil, fmt.Errorf("sign request: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -252,7 +295,7 @@ func (c *Client) ObjectSearchInit(ctx context.Context, prm PrmObjectSearch) (*Ob
|
||||||
var r ObjectListReader
|
var r ObjectListReader
|
||||||
ctx, r.cancelCtxStream = context.WithCancel(ctx)
|
ctx, r.cancelCtxStream = context.WithCancel(ctx)
|
||||||
|
|
||||||
r.stream, err = rpcapi.SearchObjects(&c.c, &req, client.WithContext(ctx))
|
r.stream, err = rpcapi.SearchObjects(&c.c, req, client.WithContext(ctx))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("open stream: %w", err)
|
return nil, fmt.Errorf("open stream: %w", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue