Skip to content
Snippets Groups Projects
Commit 66f5db30 authored by André Sterba's avatar André Sterba
Browse files

Update nbi servers

parent 201c1e69
No related branches found
No related tags found
6 merge requests!376Add additional example application hostname-checker,!349Northbound refactoring to implement NIB concept for devices,!343Add basic application framework and example application to show interaction between events an NBI,!339Create basic venv-manager for use with arista,!327Remove NBI package global services and refactor NBI servers,!324Provide prototype implementation for topology handling
Pipeline #103487 failed
...@@ -142,9 +142,7 @@ func bootstrapUnitTest() { ...@@ -142,9 +142,7 @@ func bootstrapUnitTest() {
jwtManager := rbacImpl.NewJWTManager("", (10000 * time.Hour)) jwtManager := rbacImpl.NewJWTManager("", (10000 * time.Hour))
northbound := nbi.NewNBI(pndStore, userService, roleService) northbound := nbi.NewNBI(pndStore, userService, roleService, *jwtManager)
northbound.Auth = nbi.NewAuthServer(jwtManager)
northbound.User = nbi.NewUserServer(jwtManager)
cpb.RegisterCoreServiceServer(s, northbound.Core) cpb.RegisterCoreServiceServer(s, northbound.Core)
ppb.RegisterPndServiceServer(s, northbound.Pnd) ppb.RegisterPndServiceServer(s, northbound.Pnd)
......
package server package server
import ( import (
rbacInterfaces "code.fbi.h-da.de/danet/gosdn/controller/interfaces/rbac"
"context" "context"
"time" "time"
rbacInterfaces "code.fbi.h-da.de/danet/gosdn/controller/interfaces/rbac"
csbipb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/csbi" csbipb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/csbi"
apb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/rbac" apb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/rbac"
"code.fbi.h-da.de/danet/gosdn/controller/rbac" "code.fbi.h-da.de/danet/gosdn/controller/rbac"
...@@ -23,9 +24,15 @@ type AuthInterceptor struct { ...@@ -23,9 +24,15 @@ type AuthInterceptor struct {
} }
// NewAuthInterceptor receives a JWTManager and a rbacMand returns a new AuthInterceptor provding gRPC Interceptor functionality. // NewAuthInterceptor receives a JWTManager and a rbacMand returns a new AuthInterceptor provding gRPC Interceptor functionality.
func NewAuthInterceptor(jwtManager *rbac.JWTManager) *AuthInterceptor { func NewAuthInterceptor(
jwtManager *rbac.JWTManager,
userService rbacInterfaces.UserService,
roleService rbacInterfaces.RoleService,
) *AuthInterceptor {
return &AuthInterceptor{ return &AuthInterceptor{
jwtManager: jwtManager, jwtManager: jwtManager,
userService: userService,
roleService: roleService,
} }
} }
......
...@@ -19,6 +19,13 @@ type core struct { ...@@ -19,6 +19,13 @@ type core struct {
pndStore networkdomain.PndStore pndStore networkdomain.PndStore
} }
// NewCoreServer receives a pndStore and returns a new coreServer.
func NewCoreServer(pndStore networkdomain.PndStore) *core {
return &core{
pndStore: pndStore,
}
}
func (s core) GetPnd(ctx context.Context, request *pb.GetPndRequest) (*pb.GetPndResponse, error) { func (s core) GetPnd(ctx context.Context, request *pb.GetPndRequest) (*pb.GetPndResponse, error) {
labels := prometheus.Labels{"service": "core", "rpc": "get"} labels := prometheus.Labels{"service": "core", "rpc": "get"}
start := metrics.StartHook(labels, grpcRequestsTotal) start := metrics.StartHook(labels, grpcRequestsTotal)
......
...@@ -24,6 +24,14 @@ type csbi struct { ...@@ -24,6 +24,14 @@ type csbi struct {
pndStore networkdomain.PndStore pndStore networkdomain.PndStore
} }
// NewCsbiServer receives a pndStore and returns a new csbiServer.
func NewCsbiServer(pndStore networkdomain.PndStore) *csbi {
return &csbi{
pndStore: pndStore,
}
}
func (s csbi) Hello(ctx context.Context, syn *cpb.Syn) (*cpb.Ack, error) { func (s csbi) Hello(ctx context.Context, syn *cpb.Syn) (*cpb.Ack, error) {
labels := prometheus.Labels{"service": "csbi", "rpc": "hello"} labels := prometheus.Labels{"service": "csbi", "rpc": "hello"}
start := metrics.StartHook(labels, grpcRequestsTotal) start := metrics.StartHook(labels, grpcRequestsTotal)
......
...@@ -27,28 +27,13 @@ type NorthboundInterface struct { ...@@ -27,28 +27,13 @@ type NorthboundInterface struct {
// NewNBI receives a PndStore and returns a new gRPC *NorthboundInterface // NewNBI receives a PndStore and returns a new gRPC *NorthboundInterface
func NewNBI(pnds networkdomain.PndStore, users rbacInterfaces.UserService, roles rbacInterfaces.RoleService, jwt rbac.JWTManager) *NorthboundInterface { func NewNBI(pnds networkdomain.PndStore, users rbacInterfaces.UserService, roles rbacInterfaces.RoleService, jwt rbac.JWTManager) *NorthboundInterface {
return &NorthboundInterface{ return &NorthboundInterface{
Pnd: &pndServer{ Pnd: NewPndServer(pnds),
pndStore: pnds, Core: NewCoreServer(pnds),
}, Csbi: NewCsbiServer(pnds),
Core: &core{ Sbi: NewSbiServer(pnds),
pndStore: pnds, Auth: NewAuthServer(&jwt, users),
}, User: NewUserServer(&jwt, users),
Csbi: &csbi{ Role: NewRoleServer(&jwt, roles),
pndStore: pnds,
},
Sbi: &sbiServer{
pndStore: pnds,
},
Auth: &Auth{
jwtManager: &jwt,
userService: users,
},
User: &User{
jwtManager: &jwt,
},
Role: &Role{
jwtManager: &jwt,
},
} }
} }
......
...@@ -28,6 +28,13 @@ type pndServer struct { ...@@ -28,6 +28,13 @@ type pndServer struct {
pndStore networkdomain.PndStore pndStore networkdomain.PndStore
} }
// NewPndServer receives a pndStore and returns a new pndServer.
func NewPndServer(pndStore networkdomain.PndStore) *pndServer {
return &pndServer{
pndStore: pndStore,
}
}
func (p pndServer) GetOnd(ctx context.Context, request *ppb.GetOndRequest) (*ppb.GetOndResponse, error) { func (p pndServer) GetOnd(ctx context.Context, request *ppb.GetOndRequest) (*ppb.GetOndResponse, error) {
labels := prometheus.Labels{"service": "pnd", "rpc": "get"} labels := prometheus.Labels{"service": "pnd", "rpc": "get"}
start := metrics.StartHook(labels, grpcRequestsTotal) start := metrics.StartHook(labels, grpcRequestsTotal)
......
...@@ -28,6 +28,14 @@ type sbiServer struct { ...@@ -28,6 +28,14 @@ type sbiServer struct {
pndStore networkdomain.PndStore pndStore networkdomain.PndStore
} }
// NewSbiServer receives a pndStore and returns a new sbiServer.
func NewSbiServer(pndStore networkdomain.PndStore) *sbiServer {
return &sbiServer{
pndStore: pndStore,
}
}
func (s sbiServer) GetSchema(request *spb.GetSchemaRequest, stream spb.SbiService_GetSchemaServer) error { func (s sbiServer) GetSchema(request *spb.GetSchemaRequest, stream spb.SbiService_GetSchemaServer) error {
labels := prometheus.Labels{"service": "pnd", "rpc": "get schema"} labels := prometheus.Labels{"service": "pnd", "rpc": "get schema"}
start := metrics.StartHook(labels, grpcRequestsTotal) start := metrics.StartHook(labels, grpcRequestsTotal)
......
...@@ -6,6 +6,8 @@ import ( ...@@ -6,6 +6,8 @@ import (
"log" "log"
"testing" "testing"
rbacInterfaces "code.fbi.h-da.de/danet/gosdn/controller/interfaces/rbac"
"code.fbi.h-da.de/danet/gosdn/controller/rbac" "code.fbi.h-da.de/danet/gosdn/controller/rbac"
"code.fbi.h-da.de/danet/gosdn/controller/store" "code.fbi.h-da.de/danet/gosdn/controller/store"
"github.com/google/uuid" "github.com/google/uuid"
...@@ -23,9 +25,8 @@ const randomRoleName = "bertram" ...@@ -23,9 +25,8 @@ const randomRoleName = "bertram"
var adminRoleMap = map[string]string{pndID: "adminTestRole"} var adminRoleMap = map[string]string{pndID: "adminTestRole"}
var userRoleMap = map[string]string{pndID: "userTestRole"} var userRoleMap = map[string]string{pndID: "userTestRole"}
var jwt *rbac.JWTManager
func clearAndCreateAuthTestSetup() error { func clearAndCreateAuthTestSetup(userService rbacInterfaces.UserService, roleService rbacInterfaces.RoleService) error {
//clear setup if changed //clear setup if changed
storedUsers, err := userService.GetAll() storedUsers, err := userService.GetAll()
if err != nil { if err != nil {
...@@ -50,12 +51,12 @@ func clearAndCreateAuthTestSetup() error { ...@@ -50,12 +51,12 @@ func clearAndCreateAuthTestSetup() error {
} }
// create dataset // create dataset
err = createTestUsers() err = createTestUsers(userService)
if err != nil { if err != nil {
return err return err
} }
err = createTestRoles() err = createTestRoles(roleService)
if err != nil { if err != nil {
return err return err
} }
...@@ -63,7 +64,7 @@ func clearAndCreateAuthTestSetup() error { ...@@ -63,7 +64,7 @@ func clearAndCreateAuthTestSetup() error {
return nil return nil
} }
func createTestUsers() error { func createTestUsers(userService rbacInterfaces.UserService) error {
randomRoleMap := map[string]string{pndID: randomRoleName} randomRoleMap := map[string]string{pndID: randomRoleName}
// Generate a salt that is 16 characters long with 3 digits, 0 symbols, // Generate a salt that is 16 characters long with 3 digits, 0 symbols,
...@@ -93,7 +94,7 @@ func createTestUsers() error { ...@@ -93,7 +94,7 @@ func createTestUsers() error {
return nil return nil
} }
func createTestRoles() error { func createTestRoles(roleService rbacInterfaces.RoleService) error {
roles := []rbac.Role{ roles := []rbac.Role{
{ {
RoleID: uuid.MustParse(adminRoleID), RoleID: uuid.MustParse(adminRoleID),
...@@ -153,7 +154,7 @@ func patchLogger(t *testing.T) { ...@@ -153,7 +154,7 @@ func patchLogger(t *testing.T) {
// Creates a token to be used in auth interceptor tests. If validTokenRequired is set as true, the generated token will also // Creates a token to be used in auth interceptor tests. If validTokenRequired is set as true, the generated token will also
// be attached to the provided user. Else the user won't have the token and can not be authorized. // be attached to the provided user. Else the user won't have the token and can not be authorized.
func createTestUserToken(userName string, validTokenRequired bool) (string, error) { func createTestUserToken(userName string, validTokenRequired bool, userService rbacInterfaces.UserService, jwt *rbac.JWTManager) (string, error) {
token, err := jwt.GenerateToken(rbac.User{UserName: userName}) token, err := jwt.GenerateToken(rbac.User{UserName: userName})
if err != nil { if err != nil {
return token, err return token, err
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment