diff --git a/pkg/services/container/executor.go b/pkg/services/container/executor.go index e6f058a01f..e0c0248a5a 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 bf082ebad5..249f94a3d9 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