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

Add get role by ID

parent 4d3fd039
No related branches found
No related tags found
3 merge requests!376Add additional example application hostname-checker,!344Enhance northbound interface to get user and roles by id,!343Add basic application framework and example application to show interaction between events an NBI
Pipeline #107497 failed
This commit is part of merge request !343. Comments created here will be created in the context of that merge request.
...@@ -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
uuid uuid.UUID
} }
tests := []struct { tests := []struct {
name string name string
...@@ -97,7 +98,7 @@ func TestGetRole(t *testing.T) { ...@@ -97,7 +98,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.uuid)
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
......
...@@ -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
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment