2020-08-24 09:40:04 +00:00
|
|
|
package session
|
2020-08-22 10:18:50 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/session"
|
|
|
|
sessionGRPC "github.com/nspcc-dev/neofs-api-go/v2/session/grpc"
|
2021-03-15 10:53:08 +00:00
|
|
|
sessionsvc "github.com/nspcc-dev/neofs-node/pkg/services/session"
|
2020-08-22 10:18:50 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Server wraps NeoFS API Session service and
|
|
|
|
// provides gRPC Session service server interface.
|
|
|
|
type Server struct {
|
2021-03-15 10:53:08 +00:00
|
|
|
srv sessionsvc.Server
|
2020-08-22 10:18:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// New creates, initializes and returns Server instance.
|
2021-03-15 10:53:08 +00:00
|
|
|
func New(c sessionsvc.Server) *Server {
|
2020-08-22 10:18:50 +00:00
|
|
|
return &Server{
|
|
|
|
srv: c,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create converts gRPC CreateRequest message and passes it to internal Session service.
|
|
|
|
func (s *Server) Create(ctx context.Context, req *sessionGRPC.CreateRequest) (*sessionGRPC.CreateResponse, error) {
|
|
|
|
resp, err := s.srv.Create(ctx, session.CreateRequestFromGRPCMessage(req))
|
|
|
|
if err != nil {
|
|
|
|
// TODO: think about how we transport errors through gRPC
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return session.CreateResponseToGRPCMessage(resp), nil
|
|
|
|
}
|