2020-08-22 10:18:50 +00:00
|
|
|
package container
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-api-go/v2/container"
|
|
|
|
containerGRPC "github.com/nspcc-dev/neofs-api-go/v2/container/grpc"
|
2021-03-15 10:53:08 +00:00
|
|
|
containersvc "github.com/nspcc-dev/neofs-node/pkg/services/container"
|
2020-08-22 10:18:50 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Server wraps NeoFS API Container service and
|
|
|
|
// provides gRPC Container service server interface.
|
|
|
|
type Server struct {
|
2021-03-15 10:53:08 +00:00
|
|
|
srv containersvc.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 containersvc.Server) *Server {
|
2020-08-22 10:18:50 +00:00
|
|
|
return &Server{
|
|
|
|
srv: c,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Put converts gRPC PutRequest message and passes it to internal Container service.
|
|
|
|
func (s *Server) Put(ctx context.Context, req *containerGRPC.PutRequest) (*containerGRPC.PutResponse, error) {
|
2021-03-15 10:59:28 +00:00
|
|
|
putReq := new(container.PutRequest)
|
|
|
|
if err := putReq.FromGRPCMessage(req); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := s.srv.Put(ctx, putReq)
|
2020-08-22 10:18:50 +00:00
|
|
|
if err != nil {
|
|
|
|
// TODO: think about how we transport errors through gRPC
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-03-15 10:59:28 +00:00
|
|
|
return resp.ToGRPCMessage().(*containerGRPC.PutResponse), nil
|
2020-08-22 10:18:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Delete converts gRPC DeleteRequest message and passes it to internal Container service.
|
|
|
|
func (s *Server) Delete(ctx context.Context, req *containerGRPC.DeleteRequest) (*containerGRPC.DeleteResponse, error) {
|
2021-03-15 10:59:28 +00:00
|
|
|
delReq := new(container.DeleteRequest)
|
|
|
|
if err := delReq.FromGRPCMessage(req); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := s.srv.Delete(ctx, delReq)
|
2020-08-22 10:18:50 +00:00
|
|
|
if err != nil {
|
|
|
|
// TODO: think about how we transport errors through gRPC
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-03-15 10:59:28 +00:00
|
|
|
return resp.ToGRPCMessage().(*containerGRPC.DeleteResponse), nil
|
2020-08-22 10:18:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get converts gRPC GetRequest message and passes it to internal Container service.
|
|
|
|
func (s *Server) Get(ctx context.Context, req *containerGRPC.GetRequest) (*containerGRPC.GetResponse, error) {
|
2021-03-15 10:59:28 +00:00
|
|
|
getReq := new(container.GetRequest)
|
|
|
|
if err := getReq.FromGRPCMessage(req); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := s.srv.Get(ctx, getReq)
|
2020-08-22 10:18:50 +00:00
|
|
|
if err != nil {
|
|
|
|
// TODO: think about how we transport errors through gRPC
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-03-15 10:59:28 +00:00
|
|
|
return resp.ToGRPCMessage().(*containerGRPC.GetResponse), nil
|
2020-08-22 10:18:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// List converts gRPC ListRequest message and passes it to internal Container service.
|
|
|
|
func (s *Server) List(ctx context.Context, req *containerGRPC.ListRequest) (*containerGRPC.ListResponse, error) {
|
2021-03-15 10:59:28 +00:00
|
|
|
listReq := new(container.ListRequest)
|
|
|
|
if err := listReq.FromGRPCMessage(req); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := s.srv.List(ctx, listReq)
|
2020-08-22 10:18:50 +00:00
|
|
|
if err != nil {
|
|
|
|
// TODO: think about how we transport errors through gRPC
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-03-15 10:59:28 +00:00
|
|
|
return resp.ToGRPCMessage().(*containerGRPC.ListResponse), nil
|
2020-08-22 10:18:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetExtendedACL converts gRPC SetExtendedACLRequest message and passes it to internal Container service.
|
|
|
|
func (s *Server) SetExtendedACL(ctx context.Context, req *containerGRPC.SetExtendedACLRequest) (*containerGRPC.SetExtendedACLResponse, error) {
|
2021-03-15 10:59:28 +00:00
|
|
|
setEACLReq := new(container.SetExtendedACLRequest)
|
|
|
|
if err := setEACLReq.FromGRPCMessage(req); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := s.srv.SetExtendedACL(ctx, setEACLReq)
|
2020-08-22 10:18:50 +00:00
|
|
|
if err != nil {
|
|
|
|
// TODO: think about how we transport errors through gRPC
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-03-15 10:59:28 +00:00
|
|
|
return resp.ToGRPCMessage().(*containerGRPC.SetExtendedACLResponse), nil
|
2020-08-22 10:18:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetExtendedACL converts gRPC GetExtendedACLRequest message and passes it to internal Container service.
|
|
|
|
func (s *Server) GetExtendedACL(ctx context.Context, req *containerGRPC.GetExtendedACLRequest) (*containerGRPC.GetExtendedACLResponse, error) {
|
2021-03-15 10:59:28 +00:00
|
|
|
getEACLReq := new(container.GetExtendedACLRequest)
|
|
|
|
if err := getEACLReq.FromGRPCMessage(req); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := s.srv.GetExtendedACL(ctx, getEACLReq)
|
2020-08-22 10:18:50 +00:00
|
|
|
if err != nil {
|
|
|
|
// TODO: think about how we transport errors through gRPC
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-03-15 10:59:28 +00:00
|
|
|
return resp.ToGRPCMessage().(*containerGRPC.GetExtendedACLResponse), nil
|
2020-08-22 10:18:50 +00:00
|
|
|
}
|
2021-02-01 12:31:40 +00:00
|
|
|
|
|
|
|
// AnnounceUsedSpace converts gRPC AnnounceUsedSpaceRequest message and passes it to internal Container service.
|
|
|
|
func (s *Server) AnnounceUsedSpace(ctx context.Context, req *containerGRPC.AnnounceUsedSpaceRequest) (*containerGRPC.AnnounceUsedSpaceResponse, error) {
|
2021-03-15 10:59:28 +00:00
|
|
|
announceReq := new(container.AnnounceUsedSpaceRequest)
|
|
|
|
if err := announceReq.FromGRPCMessage(req); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := s.srv.AnnounceUsedSpace(ctx, announceReq)
|
2021-02-01 12:31:40 +00:00
|
|
|
if err != nil {
|
|
|
|
// TODO: think about how we transport errors through gRPC
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-03-15 10:59:28 +00:00
|
|
|
return resp.ToGRPCMessage().(*containerGRPC.AnnounceUsedSpaceResponse), nil
|
2021-02-01 12:31:40 +00:00
|
|
|
}
|