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

Merge branch 'develop' into istaester/init-topology

parents d4dd40bb 22ec2f5e
Branches
No related tags found
5 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,!324Provide prototype implementation for topology handling
Pipeline #108109 passed
This commit is part of merge request !343. Comments created here will be created in the context of that merge request.
Showing
with 89 additions and 25 deletions
...@@ -5,6 +5,7 @@ artifacts/ ...@@ -5,6 +5,7 @@ artifacts/
# containerlab # containerlab
.gosdn.clab.yml .gosdn.clab.yml
clab-gosdn_csbi_arista_base/ clab-gosdn_csbi_arista_base/
.gosdn.clab.yml.bak
# non vimmers # non vimmers
.vscode/ .vscode/
......
...@@ -213,6 +213,7 @@ type GetRoleRequest struct { ...@@ -213,6 +213,7 @@ type GetRoleRequest struct {
Timestamp int64 `protobuf:"varint,1,opt,name=timestamp,proto3" json:"timestamp,omitempty"` Timestamp int64 `protobuf:"varint,1,opt,name=timestamp,proto3" json:"timestamp,omitempty"`
RoleName string `protobuf:"bytes,2,opt,name=role_name,json=roleName,proto3" json:"role_name,omitempty"` RoleName string `protobuf:"bytes,2,opt,name=role_name,json=roleName,proto3" json:"role_name,omitempty"`
Id string `protobuf:"bytes,3,opt,name=id,proto3" json:"id,omitempty"`
} }
func (x *GetRoleRequest) Reset() { func (x *GetRoleRequest) Reset() {
...@@ -261,6 +262,13 @@ func (x *GetRoleRequest) GetRoleName() string { ...@@ -261,6 +262,13 @@ func (x *GetRoleRequest) GetRoleName() string {
return "" return ""
} }
func (x *GetRoleRequest) GetId() string {
if x != nil {
return x.Id
}
return ""
}
type GetRoleResponse struct { type GetRoleResponse struct {
state protoimpl.MessageState state protoimpl.MessageState
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
...@@ -808,12 +816,13 @@ var file_gosdn_rbac_role_proto_rawDesc = []byte{ ...@@ -808,12 +816,13 @@ var file_gosdn_rbac_role_proto_rawDesc = []byte{
0x52, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x12, 0x2a, 0x0a, 0x06, 0x73, 0x52, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x12, 0x2a, 0x0a, 0x06, 0x73,
0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x12, 0x2e, 0x67, 0x6f, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x12, 0x2e, 0x67, 0x6f,
0x73, 0x64, 0x6e, 0x2e, 0x72, 0x62, 0x61, 0x63, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x73, 0x64, 0x6e, 0x2e, 0x72, 0x62, 0x61, 0x63, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52,
0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x22, 0x4b, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x52, 0x6f, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x22, 0x5b, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x52, 0x6f,
0x6c, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x69, 0x6d, 0x6c, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x69, 0x6d,
0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x74, 0x69, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x74, 0x69,
0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x12, 0x1b, 0x0a, 0x09, 0x72, 0x6f, 0x6c, 0x65, 0x5f, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x12, 0x1b, 0x0a, 0x09, 0x72, 0x6f, 0x6c, 0x65, 0x5f,
0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x72, 0x6f, 0x6c, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x72, 0x6f, 0x6c, 0x65,
0x4e, 0x61, 0x6d, 0x65, 0x22, 0x81, 0x01, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x52, 0x6f, 0x6c, 0x65, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09,
0x52, 0x02, 0x69, 0x64, 0x22, 0x81, 0x01, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x52, 0x6f, 0x6c, 0x65,
0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x69, 0x6d, 0x65,
0x73, 0x74, 0x61, 0x6d, 0x70, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x74, 0x69, 0x6d, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x74, 0x69, 0x6d,
0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x12, 0x2a, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x12, 0x2a, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73,
......
...@@ -221,6 +221,7 @@ type GetUserRequest struct { ...@@ -221,6 +221,7 @@ type GetUserRequest struct {
Timestamp int64 `protobuf:"varint,1,opt,name=timestamp,proto3" json:"timestamp,omitempty"` Timestamp int64 `protobuf:"varint,1,opt,name=timestamp,proto3" json:"timestamp,omitempty"`
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
Id string `protobuf:"bytes,3,opt,name=id,proto3" json:"id,omitempty"`
} }
func (x *GetUserRequest) Reset() { func (x *GetUserRequest) Reset() {
...@@ -269,6 +270,13 @@ func (x *GetUserRequest) GetName() string { ...@@ -269,6 +270,13 @@ func (x *GetUserRequest) GetName() string {
return "" return ""
} }
func (x *GetUserRequest) GetId() string {
if x != nil {
return x.Id
}
return ""
}
type GetUserResponse struct { type GetUserResponse struct {
state protoimpl.MessageState state protoimpl.MessageState
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
...@@ -703,11 +711,12 @@ var file_gosdn_rbac_user_proto_rawDesc = []byte{ ...@@ -703,11 +711,12 @@ var file_gosdn_rbac_user_proto_rawDesc = []byte{
0x73, 0x74, 0x61, 0x6d, 0x70, 0x12, 0x2a, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x12, 0x2a, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18,
0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x12, 0x2e, 0x67, 0x6f, 0x73, 0x64, 0x6e, 0x2e, 0x72, 0x62, 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x12, 0x2e, 0x67, 0x6f, 0x73, 0x64, 0x6e, 0x2e, 0x72, 0x62,
0x61, 0x63, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x61, 0x63, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75,
0x73, 0x22, 0x42, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x73, 0x22, 0x52, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75,
0x65, 0x73, 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x65, 0x73, 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70,
0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d,
0x70, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x70, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52,
0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x81, 0x01, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x55, 0x73, 0x65, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28,
0x09, 0x52, 0x02, 0x69, 0x64, 0x22, 0x81, 0x01, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x55, 0x73, 0x65,
0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x69, 0x6d, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x69, 0x6d,
0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x74, 0x69, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x74, 0x69,
0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x12, 0x2a, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x12, 0x2a, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75,
......
...@@ -994,6 +994,12 @@ ...@@ -994,6 +994,12 @@
"in": "query", "in": "query",
"required": false, "required": false,
"type": "string" "type": "string"
},
{
"name": "id",
"in": "query",
"required": false,
"type": "string"
} }
], ],
"tags": [ "tags": [
...@@ -1237,6 +1243,12 @@ ...@@ -1237,6 +1243,12 @@
"in": "query", "in": "query",
"required": false, "required": false,
"type": "string" "type": "string"
},
{
"name": "id",
"in": "query",
"required": false,
"type": "string"
} }
], ],
"tags": [ "tags": [
......
...@@ -4,7 +4,7 @@ deps: ...@@ -4,7 +4,7 @@ deps:
- remote: buf.build - remote: buf.build
owner: googleapis owner: googleapis
repository: googleapis repository: googleapis
commit: 7529bb85c9cd4c489dba05e04769c547 commit: 868034942d3c4d24b722f6a834dd7bb2
- remote: buf.build - remote: buf.build
owner: grpc-ecosystem owner: grpc-ecosystem
repository: grpc-gateway repository: grpc-gateway
......
...@@ -84,6 +84,7 @@ message CreateRolesResponse { ...@@ -84,6 +84,7 @@ message CreateRolesResponse {
message GetRoleRequest { message GetRoleRequest {
int64 timestamp = 1; int64 timestamp = 1;
string role_name = 2; string role_name = 2;
string id = 3;
} }
message GetRoleResponse { message GetRoleResponse {
......
...@@ -78,6 +78,7 @@ message CreateUsersResponse { ...@@ -78,6 +78,7 @@ message CreateUsersResponse {
message GetUserRequest { message GetUserRequest {
int64 timestamp = 1; int64 timestamp = 1;
string name = 2; string name = 2;
string id = 3;
} }
message GetUserResponse { message GetUserResponse {
......
...@@ -33,6 +33,7 @@ package cmd ...@@ -33,6 +33,7 @@ package cmd
import ( import (
"code.fbi.h-da.de/danet/gosdn/controller/api" "code.fbi.h-da.de/danet/gosdn/controller/api"
"github.com/google/uuid"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/viper" "github.com/spf13/viper"
...@@ -45,7 +46,12 @@ var userGetCmd = &cobra.Command{ ...@@ -45,7 +46,12 @@ var userGetCmd = &cobra.Command{
Long: `Requests one user using the provided name to search for it in the stored users.`, Long: `Requests one user using the provided name to search for it in the stored users.`,
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
resp, err := api.GetUser(createContextWithAuthorization(), viper.GetString("controllerAPIEndpoint"), nbUserName) resp, err := api.GetUser(
createContextWithAuthorization(),
viper.GetString("controllerAPIEndpoint"),
nbUserName,
uuid.Nil,
)
if err != nil { if err != nil {
return err return err
} }
......
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
apb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/rbac" apb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/rbac"
nbi "code.fbi.h-da.de/danet/gosdn/controller/northbound/client" nbi "code.fbi.h-da.de/danet/gosdn/controller/northbound/client"
"github.com/google/uuid"
) )
// CreateRoles creates roles with provided data // CreateRoles creates roles with provided data
...@@ -24,7 +25,7 @@ func CreateRoles(ctx context.Context, addr string, roles []*apb.Role) (*apb.Crea ...@@ -24,7 +25,7 @@ func CreateRoles(ctx context.Context, addr string, roles []*apb.Role) (*apb.Crea
} }
// GetRole returns one requested role found by name // GetRole returns one requested role found by name
func GetRole(ctx context.Context, addr, name string) (*apb.GetRoleResponse, error) { func GetRole(ctx context.Context, addr, name string, uuid uuid.UUID) (*apb.GetRoleResponse, error) {
roleClient, err := nbi.RoleClient(addr, dialOptions...) roleClient, err := nbi.RoleClient(addr, dialOptions...)
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -33,6 +34,7 @@ func GetRole(ctx context.Context, addr, name string) (*apb.GetRoleResponse, erro ...@@ -33,6 +34,7 @@ func GetRole(ctx context.Context, addr, name string) (*apb.GetRoleResponse, erro
r := &apb.GetRoleRequest{ r := &apb.GetRoleRequest{
Timestamp: time.Now().UnixNano(), Timestamp: time.Now().UnixNano(),
RoleName: name, RoleName: name,
Id: uuid.String(),
} }
return roleClient.GetRole(ctx, r) return roleClient.GetRole(ctx, r)
......
...@@ -61,6 +61,7 @@ func TestGetRole(t *testing.T) { ...@@ -61,6 +61,7 @@ func TestGetRole(t *testing.T) {
ctx context.Context ctx context.Context
addr string addr string
name string name string
id uuid.UUID
} }
tests := []struct { tests := []struct {
name string name string
...@@ -74,6 +75,7 @@ func TestGetRole(t *testing.T) { ...@@ -74,6 +75,7 @@ func TestGetRole(t *testing.T) {
ctx: context.TODO(), ctx: context.TODO(),
addr: testAPIEndpoint, addr: testAPIEndpoint,
name: "adminTestRole", name: "adminTestRole",
id: uuid.Nil,
}, },
want: &apb.GetRoleResponse{ want: &apb.GetRoleResponse{
Status: apb.Status_STATUS_OK, Status: apb.Status_STATUS_OK,
...@@ -90,6 +92,7 @@ func TestGetRole(t *testing.T) { ...@@ -90,6 +92,7 @@ func TestGetRole(t *testing.T) {
ctx: context.TODO(), ctx: context.TODO(),
addr: testAPIEndpoint, addr: testAPIEndpoint,
name: "not role", name: "not role",
id: uuid.Nil,
}, },
want: nil, want: nil,
wantErr: true, wantErr: true,
...@@ -97,7 +100,7 @@ func TestGetRole(t *testing.T) { ...@@ -97,7 +100,7 @@ func TestGetRole(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
got, err := GetRole(tt.args.ctx, tt.args.addr, tt.args.name) got, err := GetRole(tt.args.ctx, tt.args.addr, tt.args.name, tt.args.id)
if (err != nil) != tt.wantErr { if (err != nil) != tt.wantErr {
t.Errorf("GetRole() error = %v, wantErr %v", err, tt.wantErr) t.Errorf("GetRole() error = %v, wantErr %v", err, tt.wantErr)
return return
......
...@@ -6,6 +6,8 @@ import ( ...@@ -6,6 +6,8 @@ import (
apb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/rbac" apb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/rbac"
nbi "code.fbi.h-da.de/danet/gosdn/controller/northbound/client" nbi "code.fbi.h-da.de/danet/gosdn/controller/northbound/client"
"github.com/google/uuid"
) )
// CreateUsers creates users with provided data // CreateUsers creates users with provided data
...@@ -24,7 +26,7 @@ func CreateUsers(ctx context.Context, addr string, users []*apb.User) (*apb.Crea ...@@ -24,7 +26,7 @@ func CreateUsers(ctx context.Context, addr string, users []*apb.User) (*apb.Crea
} }
//GetUser returns one requested user found by name //GetUser returns one requested user found by name
func GetUser(ctx context.Context, addr, name string) (*apb.GetUserResponse, error) { func GetUser(ctx context.Context, addr, name string, uuid uuid.UUID) (*apb.GetUserResponse, error) {
userClient, err := nbi.UserClient(addr, dialOptions...) userClient, err := nbi.UserClient(addr, dialOptions...)
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -33,6 +35,7 @@ func GetUser(ctx context.Context, addr, name string) (*apb.GetUserResponse, erro ...@@ -33,6 +35,7 @@ func GetUser(ctx context.Context, addr, name string) (*apb.GetUserResponse, erro
r := &apb.GetUserRequest{ r := &apb.GetUserRequest{
Timestamp: time.Now().UnixNano(), Timestamp: time.Now().UnixNano(),
Name: name, Name: name,
Id: uuid.String(),
} }
return userClient.GetUser(ctx, r) return userClient.GetUser(ctx, r)
......
...@@ -65,6 +65,7 @@ func TestGetUser(t *testing.T) { ...@@ -65,6 +65,7 @@ func TestGetUser(t *testing.T) {
ctx context.Context ctx context.Context
addr string addr string
name string name string
id uuid.UUID
} }
tests := []struct { tests := []struct {
name string name string
...@@ -78,6 +79,7 @@ func TestGetUser(t *testing.T) { ...@@ -78,6 +79,7 @@ func TestGetUser(t *testing.T) {
ctx: context.TODO(), ctx: context.TODO(),
addr: testAPIEndpoint, addr: testAPIEndpoint,
name: "testAdmin", name: "testAdmin",
id: uuid.Nil,
}, },
want: &apb.GetUserResponse{ want: &apb.GetUserResponse{
Status: apb.Status_STATUS_OK, Status: apb.Status_STATUS_OK,
...@@ -94,6 +96,7 @@ func TestGetUser(t *testing.T) { ...@@ -94,6 +96,7 @@ func TestGetUser(t *testing.T) {
ctx: context.TODO(), ctx: context.TODO(),
addr: testAPIEndpoint, addr: testAPIEndpoint,
name: "foos", name: "foos",
id: uuid.Nil,
}, },
want: nil, want: nil,
wantErr: true, wantErr: true,
...@@ -102,7 +105,7 @@ func TestGetUser(t *testing.T) { ...@@ -102,7 +105,7 @@ func TestGetUser(t *testing.T) {
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
got, err := GetUser(tt.args.ctx, tt.args.addr, tt.args.name) got, err := GetUser(tt.args.ctx, tt.args.addr, tt.args.name, tt.args.id)
if (err != nil) != tt.wantErr { if (err != nil) != tt.wantErr {
t.Errorf("GetUser() error = %v, wantErr %v", err, tt.wantErr) t.Errorf("GetUser() error = %v, wantErr %v", err, tt.wantErr)
return return
......
...@@ -15,5 +15,5 @@ filesystemPathToStores = "stores" ...@@ -15,5 +15,5 @@ filesystemPathToStores = "stores"
amqpPrefix = "amqp://" amqpPrefix = "amqp://"
amqpUser = "guest" amqpUser = "guest"
amqpPassword = "guest" amqpPassword = "guest"
amqpHost = "localhost" amqpHost = "rabbitmq"
amqpPort = "5672" amqpPort = "5672"
...@@ -9,14 +9,16 @@ type Event struct { ...@@ -9,14 +9,16 @@ type Event struct {
Type string `json:"type,omitempty"` Type string `json:"type,omitempty"`
} }
// TypeAdd is an add event. const (
const TypeAdd = "add" // TypeAdd is an add event.
TypeAdd = "add"
// TypeUpdate is an update event. // TypeUpdate is an update event.
const TypeUpdate = "update" TypeUpdate = "update"
// TypeDelete is a delete event. // TypeDelete is a delete event.
const TypeDelete = "delete" TypeDelete = "delete"
)
// NewAddEvent creates a new add event. // NewAddEvent creates a new add event.
func NewAddEvent(entityID uuid.UUID) Event { func NewAddEvent(entityID uuid.UUID) Event {
......
...@@ -11,12 +11,6 @@ func amqpURIBuilder(prefix, user, pass, host, port string) string { ...@@ -11,12 +11,6 @@ func amqpURIBuilder(prefix, user, pass, host, port string) string {
return fmt.Sprintf("%s%s:%s@%s:%s/", prefix, user, pass, host, port) return fmt.Sprintf("%s%s:%s@%s:%s/", prefix, user, pass, host, port)
} }
// Service is the event service
type Service interface {
PublishEvent(topic string, event event.Event) error
CloseConnection()
}
// MockEventService is used to setup a connection to a broker and publish events to topics. // MockEventService is used to setup a connection to a broker and publish events to topics.
type MockEventService struct { type MockEventService struct {
Queue map[string][]event.Event Queue map[string][]event.Event
......
...@@ -2,6 +2,7 @@ package server ...@@ -2,6 +2,7 @@ package server
import ( import (
"context" "context"
"fmt"
"time" "time"
apb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/rbac" apb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/rbac"
...@@ -59,7 +60,12 @@ func (r Role) GetRole(ctx context.Context, request *apb.GetRoleRequest) (*apb.Ge ...@@ -59,7 +60,12 @@ func (r Role) GetRole(ctx context.Context, request *apb.GetRoleRequest) (*apb.Ge
start := metrics.StartHook(labels, grpcRequestsTotal) start := metrics.StartHook(labels, grpcRequestsTotal)
defer metrics.FinishHook(labels, start, grpcRequestDurationSecondsTotal, grpcRequestDurationSeconds) defer metrics.FinishHook(labels, start, grpcRequestDurationSecondsTotal, grpcRequestDurationSeconds)
roleData, err := r.roleService.Get(store.Query{Name: request.RoleName}) roleID, err := uuid.Parse(request.Id)
if err != nil {
return nil, fmt.Errorf("could not parse role uuid")
}
roleData, err := r.roleService.Get(store.Query{Name: request.RoleName, ID: roleID})
if err != nil { if err != nil {
return nil, err return nil, err
} }
......
...@@ -93,6 +93,7 @@ func TestRole_GetRole(t *testing.T) { ...@@ -93,6 +93,7 @@ func TestRole_GetRole(t *testing.T) {
ctx: context.TODO(), ctx: context.TODO(),
request: &apb.GetRoleRequest{ request: &apb.GetRoleRequest{
RoleName: "adminTestRole", RoleName: "adminTestRole",
Id: uuid.Nil.String(),
}, },
}, },
want: &apb.GetRoleResponse{ want: &apb.GetRoleResponse{
...@@ -110,6 +111,7 @@ func TestRole_GetRole(t *testing.T) { ...@@ -110,6 +111,7 @@ func TestRole_GetRole(t *testing.T) {
ctx: context.TODO(), ctx: context.TODO(),
request: &apb.GetRoleRequest{ request: &apb.GetRoleRequest{
RoleName: "not role", RoleName: "not role",
Id: uuid.Nil.String(),
}, },
}, },
want: nil, want: nil,
......
...@@ -3,6 +3,7 @@ package server ...@@ -3,6 +3,7 @@ package server
import ( import (
"context" "context"
"encoding/base64" "encoding/base64"
"fmt"
"time" "time"
apb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/rbac" apb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/rbac"
...@@ -82,7 +83,12 @@ func (u User) GetUser(ctx context.Context, request *apb.GetUserRequest) (*apb.Ge ...@@ -82,7 +83,12 @@ func (u User) GetUser(ctx context.Context, request *apb.GetUserRequest) (*apb.Ge
start := metrics.StartHook(labels, grpcRequestsTotal) start := metrics.StartHook(labels, grpcRequestsTotal)
defer metrics.FinishHook(labels, start, grpcRequestDurationSecondsTotal, grpcRequestDurationSeconds) defer metrics.FinishHook(labels, start, grpcRequestDurationSecondsTotal, grpcRequestDurationSeconds)
userData, err := u.userService.Get(store.Query{Name: request.Name}) userID, err := uuid.Parse(request.Id)
if err != nil {
return nil, fmt.Errorf("could not parse user uuid")
}
userData, err := u.userService.Get(store.Query{Name: request.Name, ID: userID})
if err != nil { if err != nil {
return nil, err return nil, err
} }
......
...@@ -95,6 +95,7 @@ func TestUser_GetUser(t *testing.T) { ...@@ -95,6 +95,7 @@ func TestUser_GetUser(t *testing.T) {
ctx: context.TODO(), ctx: context.TODO(),
request: &apb.GetUserRequest{ request: &apb.GetUserRequest{
Name: "testAdmin", Name: "testAdmin",
Id: uuid.Nil.String(),
}, },
}, },
want: &apb.GetUserResponse{Status: apb.Status_STATUS_OK, want: &apb.GetUserResponse{Status: apb.Status_STATUS_OK,
...@@ -108,6 +109,7 @@ func TestUser_GetUser(t *testing.T) { ...@@ -108,6 +109,7 @@ func TestUser_GetUser(t *testing.T) {
ctx: context.TODO(), ctx: context.TODO(),
request: &apb.GetUserRequest{ request: &apb.GetUserRequest{
Name: "nope", Name: "nope",
Id: uuid.Nil.String(),
}, },
}, },
want: nil, want: nil,
......
...@@ -98,7 +98,9 @@ func TestNewDevice(t *testing.T) { ...@@ -98,7 +98,9 @@ func TestNewDevice(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
t.Parallel()
resp, err := NewDevice(tt.args.name, uuid.Nil, tt.args.opts, tt.args.sbi) resp, err := NewDevice(tt.args.name, uuid.Nil, tt.args.opts, tt.args.sbi)
if (err != nil) != tt.wantErr { if (err != nil) != tt.wantErr {
t.Errorf("NewDevice() error = %v, wantErr %v", err, tt.wantErr) t.Errorf("NewDevice() error = %v, wantErr %v", err, tt.wantErr)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment