2021-10-28 14:48:46 +00:00
|
|
|
package internal
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
|
2022-05-12 07:22:02 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/bearer"
|
2021-11-10 07:08:33 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/client"
|
|
|
|
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
2022-01-26 12:11:13 +00:00
|
|
|
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
|
2021-11-10 07:08:33 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/session"
|
2021-10-28 14:48:46 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// here are small structures with public setters to share between parameter structures
|
|
|
|
|
|
|
|
type commonPrm struct {
|
2022-01-13 15:01:50 +00:00
|
|
|
cli *client.Client
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// SetClient sets the base client for NeoFS API communication.
|
2022-01-13 15:01:50 +00:00
|
|
|
func (x *commonPrm) SetClient(cli *client.Client) {
|
2021-10-28 14:48:46 +00:00
|
|
|
x.cli = cli
|
|
|
|
}
|
|
|
|
|
|
|
|
type containerIDPrm struct {
|
|
|
|
cnrID *cid.ID
|
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// SetContainerID sets the container identifier.
|
2021-10-28 14:48:46 +00:00
|
|
|
func (x *containerIDPrm) SetContainerID(id *cid.ID) {
|
|
|
|
x.cnrID = id
|
|
|
|
}
|
|
|
|
|
|
|
|
type sessionTokenPrm struct {
|
|
|
|
sessionToken *session.Token
|
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// SetSessionToken sets the token of the session within which the request should be sent.
|
2021-10-28 14:48:46 +00:00
|
|
|
func (x *sessionTokenPrm) SetSessionToken(tok *session.Token) {
|
|
|
|
x.sessionToken = tok
|
|
|
|
}
|
|
|
|
|
|
|
|
type bearerTokenPrm struct {
|
2022-05-12 07:22:02 +00:00
|
|
|
bearerToken *bearer.Token
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// SetBearerToken sets the bearer token to be attached to the request.
|
2022-05-12 07:22:02 +00:00
|
|
|
func (x *bearerTokenPrm) SetBearerToken(tok *bearer.Token) {
|
2021-10-28 14:48:46 +00:00
|
|
|
x.bearerToken = tok
|
|
|
|
}
|
|
|
|
|
|
|
|
type objectAddressPrm struct {
|
2022-01-26 12:11:13 +00:00
|
|
|
objAddr *addressSDK.Address
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
2022-01-26 12:11:13 +00:00
|
|
|
func (x *objectAddressPrm) SetAddress(addr *addressSDK.Address) {
|
2021-10-28 14:48:46 +00:00
|
|
|
x.objAddr = addr
|
|
|
|
}
|
|
|
|
|
|
|
|
type rawPrm struct {
|
|
|
|
raw bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetRawFlag sets flag of raw request.
|
|
|
|
func (x *rawPrm) SetRawFlag(raw bool) {
|
|
|
|
x.raw = raw
|
|
|
|
}
|
|
|
|
|
|
|
|
type payloadWriterPrm struct {
|
|
|
|
wrt io.Writer
|
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// SetPayloadWriter sets the writer of the object payload.
|
2021-10-28 14:48:46 +00:00
|
|
|
func (x *payloadWriterPrm) SetPayloadWriter(wrt io.Writer) {
|
|
|
|
x.wrt = wrt
|
|
|
|
}
|
|
|
|
|
|
|
|
type commonObjectPrm struct {
|
|
|
|
commonPrm
|
|
|
|
sessionTokenPrm
|
|
|
|
bearerTokenPrm
|
|
|
|
|
2022-02-25 09:20:49 +00:00
|
|
|
local bool
|
2022-03-03 12:30:20 +00:00
|
|
|
|
|
|
|
xHeaders []*session.XHeader
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetTTL sets request TTL value.
|
|
|
|
func (x *commonObjectPrm) SetTTL(ttl uint32) {
|
2022-02-25 09:20:49 +00:00
|
|
|
x.local = ttl < 2
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetXHeaders sets request X-Headers.
|
2022-03-03 12:30:20 +00:00
|
|
|
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
|
2021-10-28 14:48:46 +00:00
|
|
|
}
|