diff --git a/controller/api/initialise_test.go b/controller/api/initialise_test.go index 8638d200c325aef24fe3d8dac48c67bc20191bc1..21fc210175207bc3ccd3a766c040aada357f9184 100644 --- a/controller/api/initialise_test.go +++ b/controller/api/initialise_test.go @@ -142,9 +142,7 @@ func bootstrapUnitTest() { jwtManager := rbacImpl.NewJWTManager("", (10000 * time.Hour)) - northbound := nbi.NewNBI(pndStore, userService, roleService) - northbound.Auth = nbi.NewAuthServer(jwtManager) - northbound.User = nbi.NewUserServer(jwtManager) + northbound := nbi.NewNBI(pndStore, userService, roleService, *jwtManager) cpb.RegisterCoreServiceServer(s, northbound.Core) ppb.RegisterPndServiceServer(s, northbound.Pnd) diff --git a/controller/northbound/server/auth_interceptor.go b/controller/northbound/server/auth_interceptor.go index d4f73ec7ef7e0c5cbe9cf1ba3073d3c1aa7f647f..11338596bbb311850260f1c610809ed1f5f895cc 100644 --- a/controller/northbound/server/auth_interceptor.go +++ b/controller/northbound/server/auth_interceptor.go @@ -1,10 +1,11 @@ package server import ( - rbacInterfaces "code.fbi.h-da.de/danet/gosdn/controller/interfaces/rbac" "context" "time" + rbacInterfaces "code.fbi.h-da.de/danet/gosdn/controller/interfaces/rbac" + csbipb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/csbi" apb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/rbac" "code.fbi.h-da.de/danet/gosdn/controller/rbac" @@ -23,9 +24,15 @@ type AuthInterceptor struct { } // 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{ - jwtManager: jwtManager, + jwtManager: jwtManager, + userService: userService, + roleService: roleService, } } diff --git a/controller/northbound/server/core.go b/controller/northbound/server/core.go index 4ef33b9b1f7dde90158981335857b89366798016..9b6e5485f6effbb3c43ada289349cd6b382ebc12 100644 --- a/controller/northbound/server/core.go +++ b/controller/northbound/server/core.go @@ -16,7 +16,14 @@ import ( type core struct { pb.UnimplementedCoreServiceServer - 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) { diff --git a/controller/northbound/server/csbi.go b/controller/northbound/server/csbi.go index 07811a87520cfefb320bd3f0074b672c460a10fe..f895803a07f192923d43bfaa4bf027a5d4ec0d09 100644 --- a/controller/northbound/server/csbi.go +++ b/controller/northbound/server/csbi.go @@ -24,6 +24,14 @@ type csbi struct { 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) { labels := prometheus.Labels{"service": "csbi", "rpc": "hello"} start := metrics.StartHook(labels, grpcRequestsTotal) diff --git a/controller/northbound/server/nbi.go b/controller/northbound/server/nbi.go index 5e4321d98e568f573d23f77712ae770beb1eeca5..91079e4e569694de8b562159d8e1b07dd660ff8c 100644 --- a/controller/northbound/server/nbi.go +++ b/controller/northbound/server/nbi.go @@ -27,28 +27,13 @@ type NorthboundInterface struct { // 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 { return &NorthboundInterface{ - Pnd: &pndServer{ - pndStore: pnds, - }, - Core: &core{ - pndStore: pnds, - }, - Csbi: &csbi{ - pndStore: pnds, - }, - Sbi: &sbiServer{ - pndStore: pnds, - }, - Auth: &Auth{ - jwtManager: &jwt, - userService: users, - }, - User: &User{ - jwtManager: &jwt, - }, - Role: &Role{ - jwtManager: &jwt, - }, + Pnd: NewPndServer(pnds), + Core: NewCoreServer(pnds), + Csbi: NewCsbiServer(pnds), + Sbi: NewSbiServer(pnds), + Auth: NewAuthServer(&jwt, users), + User: NewUserServer(&jwt, users), + Role: NewRoleServer(&jwt, roles), } } diff --git a/controller/northbound/server/pnd.go b/controller/northbound/server/pnd.go index 35364eb5d8e996d2be4bc9b03eb7f2850af2cdc7..fae7680bdb4e11aa37150fe38de604eb3c3c58fa 100644 --- a/controller/northbound/server/pnd.go +++ b/controller/northbound/server/pnd.go @@ -28,6 +28,13 @@ type pndServer struct { 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) { labels := prometheus.Labels{"service": "pnd", "rpc": "get"} start := metrics.StartHook(labels, grpcRequestsTotal) diff --git a/controller/northbound/server/sbi.go b/controller/northbound/server/sbi.go index d948cb30f7b9502cbf090dfbb5dc9302e578e876..057d82db1b2307d81ae081938b55db731cff17df 100644 --- a/controller/northbound/server/sbi.go +++ b/controller/northbound/server/sbi.go @@ -28,6 +28,14 @@ type sbiServer struct { 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 { labels := prometheus.Labels{"service": "pnd", "rpc": "get schema"} start := metrics.StartHook(labels, grpcRequestsTotal) diff --git a/controller/northbound/server/test_util_test.go b/controller/northbound/server/test_util_test.go index 6eb5c982b9ef030ec3a427ad5c780b10452f440c..1a9db343a734099692c00c824d6a1a1ca6b73f76 100644 --- a/controller/northbound/server/test_util_test.go +++ b/controller/northbound/server/test_util_test.go @@ -6,6 +6,8 @@ import ( "log" "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/store" "github.com/google/uuid" @@ -23,9 +25,8 @@ const randomRoleName = "bertram" var adminRoleMap = map[string]string{pndID: "adminTestRole"} 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 storedUsers, err := userService.GetAll() if err != nil { @@ -50,12 +51,12 @@ func clearAndCreateAuthTestSetup() error { } // create dataset - err = createTestUsers() + err = createTestUsers(userService) if err != nil { return err } - err = createTestRoles() + err = createTestRoles(roleService) if err != nil { return err } @@ -63,7 +64,7 @@ func clearAndCreateAuthTestSetup() error { return nil } -func createTestUsers() error { +func createTestUsers(userService rbacInterfaces.UserService) error { randomRoleMap := map[string]string{pndID: randomRoleName} // Generate a salt that is 16 characters long with 3 digits, 0 symbols, @@ -93,7 +94,7 @@ func createTestUsers() error { return nil } -func createTestRoles() error { +func createTestRoles(roleService rbacInterfaces.RoleService) error { roles := []rbac.Role{ { RoleID: uuid.MustParse(adminRoleID), @@ -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 // 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}) if err != nil { return token, err