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
import (
"code.fbi.h-da.de/danet/gosdn/controller/api"
"github.com/google/uuid"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
......@@ -45,7 +46,12 @@ var userGetCmd = &cobra.Command{
Long: `Requests one user using the provided name to search for it in the stored users.`,
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 {
return err
}
......
......@@ -6,6 +6,7 @@ import (
apb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/rbac"
nbi "code.fbi.h-da.de/danet/gosdn/controller/northbound/client"
"github.com/google/uuid"
)
// CreateRoles creates roles with provided data
......@@ -24,7 +25,7 @@ func CreateRoles(ctx context.Context, addr string, roles []*apb.Role) (*apb.Crea
}
// 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...)
if err != nil {
return nil, err
......@@ -33,6 +34,7 @@ func GetRole(ctx context.Context, addr, name string) (*apb.GetRoleResponse, erro
r := &apb.GetRoleRequest{
Timestamp: time.Now().UnixNano(),
RoleName: name,
Id: uuid.String(),
}
return roleClient.GetRole(ctx, r)
......
......@@ -61,6 +61,7 @@ func TestGetRole(t *testing.T) {
ctx context.Context
addr string
name string
uuid uuid.UUID
}
tests := []struct {
name string
......@@ -97,7 +98,7 @@ func TestGetRole(t *testing.T) {
}
for _, tt := range tests {
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 {
t.Errorf("GetRole() error = %v, wantErr %v", err, tt.wantErr)
return
......
......@@ -2,6 +2,7 @@ package server
import (
"context"
"fmt"
"time"
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
start := metrics.StartHook(labels, grpcRequestsTotal)
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 {
return nil, err
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment