forked from TrueCloudLab/frostfs-sdk-go
[#121] client: Make PrmContainerPut struct fields public
Signed-off-by: Airat Arifullin a.arifullin@yadro.com
This commit is contained in:
parent
0fe0d71678
commit
18a9e4bceb
2 changed files with 21 additions and 15 deletions
|
@ -82,6 +82,7 @@ var (
|
|||
errorMissingAnnouncements = errors.New("missing announcements")
|
||||
errorZeroRangeLength = errors.New("zero range length")
|
||||
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.
|
||||
|
|
|
@ -19,20 +19,20 @@ import (
|
|||
|
||||
// PrmContainerPut groups parameters of ContainerPut operation.
|
||||
type PrmContainerPut struct {
|
||||
prmCommonMeta
|
||||
// FrostFS request X-Headers
|
||||
XHeaders []string
|
||||
|
||||
cnrSet bool
|
||||
cnr container.Container
|
||||
Container *container.Container
|
||||
|
||||
sessionSet bool
|
||||
session session.Container
|
||||
Session *session.Container
|
||||
}
|
||||
|
||||
// SetContainer sets structured information about new FrostFS container.
|
||||
// Required parameter.
|
||||
//
|
||||
// NOTE: method is deprecated
|
||||
func (x *PrmContainerPut) SetContainer(cnr container.Container) {
|
||||
x.cnr = cnr
|
||||
x.cnrSet = true
|
||||
x.Container = &cnr
|
||||
}
|
||||
|
||||
// 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 operation MUST be session.VerbContainerPut (ForVerb)
|
||||
// - token MUST be signed using private key of the owner of the container to be saved
|
||||
//
|
||||
// NOTE: method is deprecated
|
||||
func (x *PrmContainerPut) WithinSession(s session.Container) {
|
||||
x.session = s
|
||||
x.sessionSet = true
|
||||
x.Session = &s
|
||||
}
|
||||
|
||||
func (x *PrmContainerPut) buildRequest(c *Client) (*v2container.PutRequest, error) {
|
||||
if !x.cnrSet {
|
||||
if x.Container == nil {
|
||||
return nil, errorMissingContainer
|
||||
}
|
||||
|
||||
if len(x.XHeaders)%2 != 0 {
|
||||
return nil, errorInvalidXHeaders
|
||||
}
|
||||
|
||||
// TODO: check private key is set before forming the request
|
||||
var cnr v2container.Container
|
||||
x.cnr.WriteToV2(&cnr)
|
||||
x.Container.WriteToV2(&cnr)
|
||||
|
||||
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 {
|
||||
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)
|
||||
|
||||
var meta v2session.RequestMetaHeader
|
||||
writeXHeadersToMeta(x.prmCommonMeta.xHeaders, &meta)
|
||||
writeXHeadersToMeta(x.XHeaders, &meta)
|
||||
|
||||
if x.sessionSet {
|
||||
if x.Session != nil {
|
||||
var tokv2 v2session.Token
|
||||
x.session.WriteToV2(&tokv2)
|
||||
x.Session.WriteToV2(&tokv2)
|
||||
|
||||
meta.SetSessionToken(&tokv2)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue