[#121] client: Make client parameter fields public #127
3 changed files with 43 additions and 26 deletions
|
@ -82,6 +82,7 @@ var (
|
||||||
errorMissingAnnouncements = errors.New("missing announcements")
|
errorMissingAnnouncements = errors.New("missing announcements")
|
||||||
errorZeroRangeLength = errors.New("zero range length")
|
errorZeroRangeLength = errors.New("zero range length")
|
||||||
errorMissingRanges = errors.New("missing ranges")
|
errorMissingRanges = errors.New("missing ranges")
|
||||||
|
errorInvalidXHeaders = errors.New("xheaders must be presented only as key-value pairs")
|
||||||
)
|
)
|
||||||
|
|
||||||
// groups all the details required to send a single request and process a response to it.
|
// groups all the details required to send a single request and process a response to it.
|
||||||
|
|
|
@ -19,20 +19,20 @@ import (
|
||||||
|
|
||||||
// PrmContainerPut groups parameters of ContainerPut operation.
|
// PrmContainerPut groups parameters of ContainerPut operation.
|
||||||
type PrmContainerPut struct {
|
type PrmContainerPut struct {
|
||||||
prmCommonMeta
|
// FrostFS request X-Headers
|
||||||
|
XHeaders []string
|
||||||
|
|
||||||
cnrSet bool
|
Container *container.Container
|
||||||
cnr container.Container
|
|
||||||
|
|
||||||
sessionSet bool
|
Session *session.Container
|
||||||
session session.Container
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetContainer sets structured information about new FrostFS container.
|
// SetContainer sets structured information about new FrostFS container.
|
||||||
// Required parameter.
|
// Required parameter.
|
||||||
|
//
|
||||||
|
// Deprecated: Use PrmContainerPut.Container instead.
|
||||||
func (x *PrmContainerPut) SetContainer(cnr container.Container) {
|
func (x *PrmContainerPut) SetContainer(cnr container.Container) {
|
||||||
x.cnr = cnr
|
x.Container = &cnr
|
||||||
x.cnrSet = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithinSession specifies session within which container should be saved.
|
// WithinSession specifies session within which container should be saved.
|
||||||
|
@ -43,23 +43,28 @@ func (x *PrmContainerPut) SetContainer(cnr container.Container) {
|
||||||
// Session is optional, if set the following requirements apply:
|
// Session is optional, if set the following requirements apply:
|
||||||
// - session operation MUST be session.VerbContainerPut (ForVerb)
|
// - session operation MUST be session.VerbContainerPut (ForVerb)
|
||||||
// - token MUST be signed using private key of the owner of the container to be saved
|
// - token MUST be signed using private key of the owner of the container to be saved
|
||||||
|
//
|
||||||
|
// Deprecated: Use PrmContainerPut.Session instead.
|
||||||
func (x *PrmContainerPut) WithinSession(s session.Container) {
|
func (x *PrmContainerPut) WithinSession(s session.Container) {
|
||||||
x.session = s
|
x.Session = &s
|
||||||
x.sessionSet = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *PrmContainerPut) buildRequest(c *Client) (*v2container.PutRequest, error) {
|
func (x *PrmContainerPut) buildRequest(c *Client) (*v2container.PutRequest, error) {
|
||||||
if !x.cnrSet {
|
if x.Container == nil {
|
||||||
return nil, errorMissingContainer
|
return nil, errorMissingContainer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(x.XHeaders)%2 != 0 {
|
||||||
|
return nil, errorInvalidXHeaders
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: check private key is set before forming the request
|
// TODO: check private key is set before forming the request
|
||||||
var cnr v2container.Container
|
var cnr v2container.Container
|
||||||
x.cnr.WriteToV2(&cnr)
|
x.Container.WriteToV2(&cnr)
|
||||||
|
|
||||||
var sig frostfscrypto.Signature
|
var sig frostfscrypto.Signature
|
||||||
|
|
||||||
err := container.CalculateSignature(&sig, x.cnr, c.prm.key)
|
err := container.CalculateSignature(&sig, *x.Container, c.prm.key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("calculate container signature: %w", err)
|
return nil, fmt.Errorf("calculate container signature: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -72,11 +77,11 @@ func (x *PrmContainerPut) buildRequest(c *Client) (*v2container.PutRequest, erro
|
||||||
reqBody.SetSignature(&sigv2)
|
reqBody.SetSignature(&sigv2)
|
||||||
|
|
||||||
var meta v2session.RequestMetaHeader
|
var meta v2session.RequestMetaHeader
|
||||||
writeXHeadersToMeta(x.prmCommonMeta.xHeaders, &meta)
|
writeXHeadersToMeta(x.XHeaders, &meta)
|
||||||
|
|
||||||
if x.sessionSet {
|
if x.Session != nil {
|
||||||
var tokv2 v2session.Token
|
var tokv2 v2session.Token
|
||||||
x.session.WriteToV2(&tokv2)
|
x.Session.WriteToV2(&tokv2)
|
||||||
|
|
||||||
meta.SetSessionToken(&tokv2)
|
meta.SetSessionToken(&tokv2)
|
||||||
}
|
}
|
||||||
|
|
33
pool/pool.go
33
pool/pool.go
|
@ -407,7 +407,7 @@ func (c *clientWrapper) containerPut(ctx context.Context, prm PrmContainerPut) (
|
||||||
}
|
}
|
||||||
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
res, err := cl.ContainerPut(ctx, prm.prmClient)
|
res, err := cl.ContainerPut(ctx, prm.ClientParams)
|
||||||
c.incRequests(time.Since(start), methodContainerPut)
|
c.incRequests(time.Since(start), methodContainerPut)
|
||||||
var st apistatus.Status
|
var st apistatus.Status
|
||||||
if res != nil {
|
if res != nil {
|
||||||
|
@ -417,13 +417,13 @@ func (c *clientWrapper) containerPut(ctx context.Context, prm PrmContainerPut) (
|
||||||
return cid.ID{}, fmt.Errorf("container put on client: %w", err)
|
return cid.ID{}, fmt.Errorf("container put on client: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !prm.waitParamsSet {
|
if prm.WaitParams == nil {
|
||||||
prm.waitParams.setDefaults()
|
prm.WaitParams = defaultWaitParams()
|
||||||
}
|
}
|
||||||
|
|
||||||
idCnr := res.ID()
|
idCnr := res.ID()
|
||||||
|
|
||||||
err = waitForContainerPresence(ctx, c, idCnr, &prm.waitParams)
|
err = waitForContainerPresence(ctx, c, idCnr, prm.WaitParams)
|
||||||
if err = c.handleError(ctx, nil, err); err != nil {
|
if err = c.handleError(ctx, nil, err); err != nil {
|
||||||
return cid.ID{}, fmt.Errorf("wait container presence on client: %w", err)
|
return cid.ID{}, fmt.Errorf("wait container presence on client: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -1221,6 +1221,13 @@ func (x *WaitParams) setDefaults() {
|
||||||
x.pollInterval = 5 * time.Second
|
x.pollInterval = 5 * time.Second
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func defaultWaitParams() *WaitParams {
|
||||||
|
return &WaitParams{
|
||||||
|
timeout: 120 * time.Second,
|
||||||
|
pollInterval: 5 * time.Second,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// checkForPositive panics if any of the wait params isn't positive.
|
// checkForPositive panics if any of the wait params isn't positive.
|
||||||
func (x *WaitParams) checkForPositive() {
|
func (x *WaitParams) checkForPositive() {
|
||||||
if x.timeout <= 0 || x.pollInterval <= 0 {
|
if x.timeout <= 0 || x.pollInterval <= 0 {
|
||||||
|
@ -1400,35 +1407,39 @@ func (x *PrmObjectSearch) SetFilters(filters object.SearchFilters) {
|
||||||
|
|
||||||
// PrmContainerPut groups parameters of PutContainer operation.
|
// PrmContainerPut groups parameters of PutContainer operation.
|
||||||
type PrmContainerPut struct {
|
type PrmContainerPut struct {
|
||||||
prmClient sdkClient.PrmContainerPut
|
ClientParams sdkClient.PrmContainerPut
|
||||||
|
|
||||||
waitParams WaitParams
|
WaitParams *WaitParams
|
||||||
waitParamsSet bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetContainer container structure to be used as a parameter of the base
|
// SetContainer container structure to be used as a parameter of the base
|
||||||
// client's operation.
|
// client's operation.
|
||||||
//
|
//
|
||||||
// See git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client.PrmContainerPut.SetContainer.
|
// See git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client.PrmContainerPut.SetContainer.
|
||||||
|
//
|
||||||
|
// Deprecated: Use PrmContainerPut.ClientParams.Container instead.
|
||||||
func (x *PrmContainerPut) SetContainer(cnr container.Container) {
|
func (x *PrmContainerPut) SetContainer(cnr container.Container) {
|
||||||
x.prmClient.SetContainer(cnr)
|
x.ClientParams.SetContainer(cnr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithinSession specifies session to be used as a parameter of the base
|
// WithinSession specifies session to be used as a parameter of the base
|
||||||
// client's operation.
|
// client's operation.
|
||||||
//
|
//
|
||||||
// See git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client.PrmContainerPut.WithinSession.
|
// See git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client.PrmContainerPut.WithinSession.
|
||||||
|
//
|
||||||
|
// Deprecated: Use PrmContainerPut.ClientParams.Session instead.
|
||||||
func (x *PrmContainerPut) WithinSession(s session.Container) {
|
func (x *PrmContainerPut) WithinSession(s session.Container) {
|
||||||
x.prmClient.WithinSession(s)
|
x.ClientParams.WithinSession(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetWaitParams specifies timeout params to complete operation.
|
// SetWaitParams specifies timeout params to complete operation.
|
||||||
// If not provided the default one will be used.
|
// If not provided the default one will be used.
|
||||||
// Panics if any of the wait params isn't positive.
|
// Panics if any of the wait params isn't positive.
|
||||||
|
//
|
||||||
|
// Deprecated: Use PrmContainerPut.ClientParams.WaitParams instead.
|
||||||
func (x *PrmContainerPut) SetWaitParams(waitParams WaitParams) {
|
func (x *PrmContainerPut) SetWaitParams(waitParams WaitParams) {
|
||||||
waitParams.checkForPositive()
|
waitParams.checkForPositive()
|
||||||
x.waitParams = waitParams
|
x.WaitParams = &waitParams
|
||||||
x.waitParamsSet = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// PrmContainerGet groups parameters of GetContainer operation.
|
// PrmContainerGet groups parameters of GetContainer operation.
|
||||||
|
|
Loading…
Reference in a new issue