frostfs-node/pkg/network/transport/container/grpc/service.go

79 lines
1.7 KiB
Go
Raw Normal View History

package container
import (
2020-07-24 13:54:03 +00:00
"errors"
"github.com/nspcc-dev/neofs-api-go/container"
2020-07-24 13:54:03 +00:00
eacl "github.com/nspcc-dev/neofs-node/pkg/core/container/acl/extended/storage"
"github.com/nspcc-dev/neofs-node/pkg/core/container/storage"
"github.com/nspcc-dev/neofs-node/pkg/network/transport/grpc"
libgrpc "github.com/nspcc-dev/neofs-node/pkg/network/transport/grpc"
"go.uber.org/zap"
)
type (
// Service is an interface of the server of Container service.
Service interface {
grpc.Service
container.ServiceServer
}
// HealthChecker is an interface of node healthiness checking tool.
HealthChecker interface {
Healthy() error
}
// Params groups the parameters of Container service server's constructor.
Params struct {
Logger *zap.Logger
Healthy HealthChecker
2020-07-24 13:54:03 +00:00
Store storage.Storage
2020-07-24 13:54:03 +00:00
ExtendedACLStore eacl.Storage
}
cnrService struct {
log *zap.Logger
healthy HealthChecker
2020-07-24 13:54:03 +00:00
cnrStore storage.Storage
2020-07-24 13:54:03 +00:00
aclStore eacl.Storage
}
)
2020-07-24 13:54:03 +00:00
var (
errEmptyLogger = errors.New("empty log component")
errEmptyHealthChecker = errors.New("empty healthy component")
)
2020-07-24 13:54:03 +00:00
var requestVerifyFunc = libgrpc.VerifyRequestWithSignatures
// New is an Container service server's constructor.
func New(p Params) (Service, error) {
switch {
case p.Logger == nil:
return nil, errEmptyLogger
case p.Store == nil:
2020-07-24 13:54:03 +00:00
return nil, storage.ErrNilStorage
case p.Healthy == nil:
return nil, errEmptyHealthChecker
case p.ExtendedACLStore == nil:
2020-07-24 13:54:03 +00:00
return nil, eacl.ErrNilStorage
}
return &cnrService{
log: p.Logger,
healthy: p.Healthy,
cnrStore: p.Store,
aclStore: p.ExtendedACLStore,
}, nil
}
func (cnrService) Name() string { return "ContainerService" }
func (s cnrService) Register(g *grpc.Server) { container.RegisterServiceServer(g, s) }