[#121] client: Make PrmContainerPut struct fields public

Signed-off-by: Airat Arifullin a.arifullin@yadro.com
This commit is contained in:
Airat Arifullin 2023-07-24 14:29:31 +03:00 committed by Evgenii Stratonikov
parent 0fe0d71678
commit 18a9e4bceb
2 changed files with 21 additions and 15 deletions

View file

@ -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.

View file

@ -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.
//
// NOTE: method is deprecated
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
//
// NOTE: method is deprecated
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)
} }