[#525] v2/container: Make context with token reusable
Rename `PutContext` to `ContextWithToken` and implement its constructor as a separate function in order to reuse it in other RPCs. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
959610080a
commit
5c2b8de87d
2 changed files with 12 additions and 6 deletions
|
@ -9,14 +9,14 @@ import (
|
|||
)
|
||||
|
||||
// FIXME: (temp solution) we need to pass session token from header
|
||||
type PutContext struct {
|
||||
type ContextWithToken struct {
|
||||
context.Context
|
||||
|
||||
SessionToken *session.SessionToken
|
||||
}
|
||||
|
||||
type ServiceExecutor interface {
|
||||
Put(PutContext, *container.PutRequestBody) (*container.PutResponseBody, error)
|
||||
Put(ContextWithToken, *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)
|
||||
|
@ -37,17 +37,23 @@ func NewExecutionService(exec ServiceExecutor) Server {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *executorSvc) Put(ctx context.Context, req *container.PutRequest) (*container.PutResponse, error) {
|
||||
func contextWithTokenFromRequest(ctx context.Context, req interface {
|
||||
GetMetaHeader() *session.RequestMetaHeader
|
||||
}) ContextWithToken {
|
||||
var tok *session.SessionToken
|
||||
|
||||
for meta := req.GetMetaHeader(); meta != nil; meta = meta.GetOrigin() {
|
||||
tok = meta.GetSessionToken()
|
||||
}
|
||||
|
||||
respBody, err := s.exec.Put(PutContext{
|
||||
return ContextWithToken{
|
||||
Context: ctx,
|
||||
SessionToken: tok,
|
||||
}, req.GetBody())
|
||||
}
|
||||
}
|
||||
|
||||
func (s *executorSvc) Put(ctx context.Context, req *container.PutRequest) (*container.PutResponse, error) {
|
||||
respBody, err := s.exec.Put(contextWithTokenFromRequest(ctx, req), req.GetBody())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not execute Put request: %w", err)
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ func NewExecutor(w *wrapper.Wrapper) containerSvc.ServiceExecutor {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *morphExecutor) Put(ctx containerSvc.PutContext, body *container.PutRequestBody) (*container.PutResponseBody, error) {
|
||||
func (s *morphExecutor) Put(ctx containerSvc.ContextWithToken, 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)
|
||||
|
|
Loading…
Reference in a new issue