From c378c353d50834a6cae8f6c43d50f28b36f6da76 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 24 Aug 2020 18:51:42 +0300 Subject: [PATCH] [#12] Serve gRPC session service in neofs-node app Signed-off-by: Leonard Lyubich --- cmd/neofs-node/config.go | 3 +++ cmd/neofs-node/grpc.go | 7 ------- cmd/neofs-node/main.go | 4 +--- cmd/neofs-node/session.go | 31 +++++++++++++++++++++++++++++++ 4 files changed, 35 insertions(+), 10 deletions(-) create mode 100644 cmd/neofs-node/session.go diff --git a/cmd/neofs-node/config.go b/cmd/neofs-node/config.go index 379f6ef7c..64b24ccde 100644 --- a/cmd/neofs-node/config.go +++ b/cmd/neofs-node/config.go @@ -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 { diff --git a/cmd/neofs-node/grpc.go b/cmd/neofs-node/grpc.go index e1a9552f8..b5f0436f3 100644 --- a/cmd/neofs-node/grpc.go +++ b/cmd/neofs-node/grpc.go @@ -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") } diff --git a/cmd/neofs-node/main.go b/cmd/neofs-node/main.go index c5d5e4346..1c77a466b 100644 --- a/cmd/neofs-node/main.go +++ b/cmd/neofs-node/main.go @@ -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))) } diff --git a/cmd/neofs-node/session.go b/cmd/neofs-node/session.go new file mode 100644 index 000000000..46f492ee4 --- /dev/null +++ b/cmd/neofs-node/session.go @@ -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, + ), + ), + ), + ) +}