[#12] Serve gRPC session service in neofs-node app

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-08-24 18:51:42 +03:00 committed by Alex Vanin
parent f5a0e354ef
commit c378c353d5
4 changed files with 35 additions and 10 deletions

View file

@ -9,6 +9,7 @@ import (
"github.com/nspcc-dev/neo-go/pkg/util"
crypto "github.com/nspcc-dev/neofs-crypto"
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
tokenStorage "github.com/nspcc-dev/neofs-node/pkg/services/session/storage"
"google.golang.org/grpc"
)
@ -26,6 +27,8 @@ type cfg struct {
cfgAccounting cfgAccounting
cfgContainer cfgContainer
privateTokenStore *tokenStorage.TokenStore
}
type cfgGRPC struct {

View file

@ -7,13 +7,10 @@ import (
containerGRPC "github.com/nspcc-dev/neofs-api-go/v2/container"
objectGRPC "github.com/nspcc-dev/neofs-api-go/v2/object"
"github.com/nspcc-dev/neofs-api-go/v2/session"
"github.com/pkg/errors"
"google.golang.org/grpc"
)
type sessionSvc struct{}
type containerSvc struct{}
type objectSvc struct{}
@ -22,10 +19,6 @@ func unimplementedErr(srv, call string) error {
return errors.Errorf("unimplemented API service call %s.%s", srv, call)
}
func (s *sessionSvc) Create(context.Context, *session.CreateRequest) (*session.CreateResponse, error) {
return nil, unimplementedErr("Session", "Create")
}
func (s *containerSvc) Put(context.Context, *containerGRPC.PutRequest) (*containerGRPC.PutResponse, error) {
return nil, unimplementedErr("Container", "Put")
}

View file

@ -5,9 +5,7 @@ import (
"log"
object "github.com/nspcc-dev/neofs-api-go/v2/object/grpc"
session "github.com/nspcc-dev/neofs-api-go/v2/session/grpc"
objectGRPC "github.com/nspcc-dev/neofs-node/pkg/network/transport/object/grpc"
sessionGRPC "github.com/nspcc-dev/neofs-node/pkg/network/transport/session/grpc"
"github.com/nspcc-dev/neofs-node/pkg/util/grace"
)
@ -36,8 +34,8 @@ func init_(c *cfg) {
initAccountingService(c)
initContainerService(c)
initSessionService(c)
session.RegisterSessionServiceServer(c.cfgGRPC.server, sessionGRPC.New(new(sessionSvc)))
object.RegisterObjectServiceServer(c.cfgGRPC.server, objectGRPC.New(new(objectSvc)))
}

31
cmd/neofs-node/session.go Normal file
View file

@ -0,0 +1,31 @@
package main
import (
"github.com/nspcc-dev/neofs-api-go/v2/session"
sessionGRPC "github.com/nspcc-dev/neofs-api-go/v2/session/grpc"
sessionTransportGRPC "github.com/nspcc-dev/neofs-node/pkg/network/transport/session/grpc"
sessionSvc "github.com/nspcc-dev/neofs-node/pkg/services/session"
"github.com/nspcc-dev/neofs-node/pkg/services/session/storage"
)
func initSessionService(c *cfg) {
c.privateTokenStore = storage.New()
metaHdr := new(session.ResponseMetaHeader)
xHdr := new(session.XHeader)
xHdr.SetKey("test X-Header key")
xHdr.SetValue("test X-Header value")
metaHdr.SetXHeaders([]*session.XHeader{xHdr})
sessionGRPC.RegisterSessionServiceServer(c.cfgGRPC.server,
sessionTransportGRPC.New(
sessionSvc.NewSignService(
c.key,
sessionSvc.NewExecutionService(
c.privateTokenStore,
metaHdr,
),
),
),
)
}