From b06e6cbf42e2467d241d2a7f4dedf113752d83c4 Mon Sep 17 00:00:00 2001 From: Fabian Seidl <fabian.seidl@h-da.de> Date: Mon, 19 Feb 2024 09:44:00 +0000 Subject: [PATCH] Resolve "Credentials returned after registering an app are hard coded, which causes problems if RabbitMQ is not hosted on localhost" See merge request danet/gosdn!755 --- controller/app/Service.go | 7 ++++++- integration-tests/application_tests/appUtility_test.go | 5 +++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/controller/app/Service.go b/controller/app/Service.go index 2f02f7743..5a8c62176 100644 --- a/controller/app/Service.go +++ b/controller/app/Service.go @@ -4,6 +4,7 @@ import ( "context" "fmt" + "code.fbi.h-da.de/danet/gosdn/controller/config" "code.fbi.h-da.de/danet/gosdn/controller/store" "github.com/google/uuid" ) @@ -66,7 +67,7 @@ func (a *Service) createNewApp(appName string) (*App, error) { app := App{ ID: uuid.New(), Name: appName, - EventSystemCredentials: "amqp://guest:guest@127.0.0.1:5672", + EventSystemCredentials: buildQueueCredentials(), } // generate app credentials @@ -77,3 +78,7 @@ func (a *Service) createNewApp(appName string) (*App, error) { return &app, nil } + +func buildQueueCredentials() string { + return fmt.Sprintf("%s%s:%s@%s:%s/", config.AMQPPrefix, config.AMQPUser, config.AMQPPassword, config.AMQPHost, config.AMQPPort) +} diff --git a/integration-tests/application_tests/appUtility_test.go b/integration-tests/application_tests/appUtility_test.go index 453907257..cf25f6c66 100644 --- a/integration-tests/application_tests/appUtility_test.go +++ b/integration-tests/application_tests/appUtility_test.go @@ -14,6 +14,7 @@ import ( ) const localhost = "127.0.0.1" +const rabbitmq = "rabbitmq" // Application is an example for a sdn application. type Application struct { @@ -33,8 +34,8 @@ func NewApplication(ctx context.Context, grpcClientConn *grpc.ClientConn, contro os.Exit(1) } - if rabbitMQAddress != "" { - queueCredentials = strings.ReplaceAll(queueCredentials, localhost, rabbitMQAddress) + if rabbitMQAddress == "" { + queueCredentials = strings.ReplaceAll(queueCredentials, rabbitmq, localhost) } eventService, err := event.NewEventService( -- GitLab