From 18a9e4bceb671c2a7235ca1107b10c41695ee840 Mon Sep 17 00:00:00 2001 From: Airat Arifullin Date: Mon, 24 Jul 2023 14:29:31 +0300 Subject: [PATCH] [#121] client: Make PrmContainerPut struct fields public Signed-off-by: Airat Arifullin a.arifullin@yadro.com --- client/common.go | 1 + client/container_put.go | 35 ++++++++++++++++++++--------------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/client/common.go b/client/common.go index 1d561307..7449288d 100644 --- a/client/common.go +++ b/client/common.go @@ -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. diff --git a/client/container_put.go b/client/container_put.go index 630d265b..ebf90e87 100644 --- a/client/container_put.go +++ b/client/container_put.go @@ -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) }