forked from TrueCloudLab/frostfs-node
7b418c36b4
There is a need to check if session is opened during system testing/debug. Signed-off-by: Leonard Lyubich <ctulhurider@gmail.com>
45 lines
1 KiB
Go
45 lines
1 KiB
Go
package session
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/session"
|
|
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
type ServiceExecutor interface {
|
|
Create(context.Context, *session.CreateRequestBody) (*session.CreateResponseBody, error)
|
|
}
|
|
|
|
type executorSvc struct {
|
|
exec ServiceExecutor
|
|
|
|
log *logger.Logger
|
|
}
|
|
|
|
// NewExecutionService wraps ServiceExecutor and returns Session Service interface.
|
|
func NewExecutionService(exec ServiceExecutor, l *logger.Logger) Server {
|
|
return &executorSvc{
|
|
exec: exec,
|
|
log: l,
|
|
}
|
|
}
|
|
|
|
func (s *executorSvc) Create(ctx context.Context, req *session.CreateRequest) (*session.CreateResponse, error) {
|
|
s.log.Debug("serving request...",
|
|
zap.String("component", "SessionService"),
|
|
zap.String("request", "Create"),
|
|
)
|
|
|
|
respBody, err := s.exec.Create(ctx, req.GetBody())
|
|
if err != nil {
|
|
return nil, fmt.Errorf("could not execute Create request: %w", err)
|
|
}
|
|
|
|
resp := new(session.CreateResponse)
|
|
resp.SetBody(respBody)
|
|
|
|
return resp, nil
|
|
}
|