From 98cc685a9bf95f38b00195d5fa07550306ec852f Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Tue, 25 May 2021 18:46:50 +0300 Subject: [PATCH] [#525] v2/container: Write session token from header to container If container is created via session, then session token should be written to it. Write session token from request meta header to `Container` structure which is passed to `wrapper.Put` function. Signed-off-by: Leonard Lyubich --- pkg/services/container/executor.go | 21 +++++++++++++++++++-- pkg/services/container/morph/executor.go | 7 ++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/pkg/services/container/executor.go b/pkg/services/container/executor.go index e6f058a01..e0c0248a5 100644 --- a/pkg/services/container/executor.go +++ b/pkg/services/container/executor.go @@ -5,10 +5,18 @@ import ( "fmt" "github.com/nspcc-dev/neofs-api-go/v2/container" + "github.com/nspcc-dev/neofs-api-go/v2/session" ) +// FIXME: (temp solution) we need to pass session token from header +type PutContext struct { + context.Context + + SessionToken *session.SessionToken +} + type ServiceExecutor interface { - Put(context.Context, *container.PutRequestBody) (*container.PutResponseBody, error) + Put(PutContext, *container.PutRequestBody) (*container.PutResponseBody, error) Delete(context.Context, *container.DeleteRequestBody) (*container.DeleteResponseBody, error) Get(context.Context, *container.GetRequestBody) (*container.GetResponseBody, error) List(context.Context, *container.ListRequestBody) (*container.ListResponseBody, error) @@ -30,7 +38,16 @@ func NewExecutionService(exec ServiceExecutor) Server { } func (s *executorSvc) Put(ctx context.Context, req *container.PutRequest) (*container.PutResponse, error) { - respBody, err := s.exec.Put(ctx, req.GetBody()) + var tok *session.SessionToken + + for meta := req.GetMetaHeader(); meta != nil; meta = meta.GetOrigin() { + tok = meta.GetSessionToken() + } + + respBody, err := s.exec.Put(PutContext{ + Context: ctx, + SessionToken: tok, + }, req.GetBody()) if err != nil { return nil, fmt.Errorf("could not execute Put request: %w", err) } diff --git a/pkg/services/container/morph/executor.go b/pkg/services/container/morph/executor.go index bf082ebad..249f94a3d 100644 --- a/pkg/services/container/morph/executor.go +++ b/pkg/services/container/morph/executor.go @@ -8,6 +8,7 @@ import ( eaclSDK "github.com/nspcc-dev/neofs-api-go/pkg/acl/eacl" containerSDK "github.com/nspcc-dev/neofs-api-go/pkg/container" "github.com/nspcc-dev/neofs-api-go/pkg/owner" + "github.com/nspcc-dev/neofs-api-go/pkg/session" "github.com/nspcc-dev/neofs-api-go/v2/container" "github.com/nspcc-dev/neofs-api-go/v2/refs" "github.com/nspcc-dev/neofs-node/pkg/morph/client/container/wrapper" @@ -24,7 +25,7 @@ func NewExecutor(w *wrapper.Wrapper) containerSvc.ServiceExecutor { } } -func (s *morphExecutor) Put(ctx context.Context, body *container.PutRequestBody) (*container.PutResponseBody, error) { +func (s *morphExecutor) Put(ctx containerSvc.PutContext, body *container.PutRequestBody) (*container.PutResponseBody, error) { cnr, err := containerSDK.NewVerifiedFromV2(body.GetContainer()) if err != nil { return nil, fmt.Errorf("invalid format of the container structure: %w", err) @@ -34,6 +35,10 @@ func (s *morphExecutor) Put(ctx context.Context, body *container.PutRequestBody) pkg.NewSignatureFromV2(body.GetSignature()), ) + cnr.SetSessionToken( + session.NewTokenFromV2(ctx.SessionToken), + ) + cid, err := wrapper.Put(s.wrapper, cnr) if err != nil { return nil, err