From 63c9423827b5eeae000f93dd0510e2b210164f1d Mon Sep 17 00:00:00 2001 From: Gulsum Atici Date: Tue, 16 Apr 2024 01:37:17 +0300 Subject: [PATCH] chore: Parameterise webui url (#97) Signed-off-by: gatici --- factory/config.go | 1 + factory/factory.go | 3 ++ factory/pcf_config_test.go | 34 +++++++++++++++++++++++ factory/pcfcfg.yaml | 13 +++++++++ factory/pcfcfg_with_custom_webui_url.yaml | 14 ++++++++++ service/init.go | 2 +- 6 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 factory/pcf_config_test.go create mode 100644 factory/pcfcfg.yaml create mode 100644 factory/pcfcfg_with_custom_webui_url.yaml diff --git a/factory/config.go b/factory/config.go index f8d98f1..6d32253 100644 --- a/factory/config.go +++ b/factory/config.go @@ -42,6 +42,7 @@ type Configuration struct { TimeFormat string `yaml:"timeFormat,omitempty"` DefaultBdtRefId string `yaml:"defaultBdtRefId,omitempty"` NrfUri string `yaml:"nrfUri,omitempty"` + WebuiUri string `yaml:"webuiUri"` ServiceList []Service `yaml:"serviceList,omitempty"` Mongodb *Mongodb `yaml:"mongodb"` diff --git a/factory/factory.go b/factory/factory.go index 48ff26d..7a2d951 100644 --- a/factory/factory.go +++ b/factory/factory.go @@ -30,6 +30,9 @@ func InitConfigFactory(f string) error { if yamlErr := yaml.Unmarshal(content, &PcfConfig); yamlErr != nil { return yamlErr } + if PcfConfig.Configuration.WebuiUri == "" { + PcfConfig.Configuration.WebuiUri = "webui:9876" + } } return nil diff --git a/factory/pcf_config_test.go b/factory/pcf_config_test.go new file mode 100644 index 0000000..1436be5 --- /dev/null +++ b/factory/pcf_config_test.go @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2024 Canonical Ltd. +/* + * Tests for PCF Configuration Factory + */ + +package factory + +import ( + "fmt" + "testing" + + "github.com/stretchr/testify/assert" +) + +// Webui URL is not set then default Webui URL value is returned +func TestGetDefaultWebuiUrl(t *testing.T) { + if err := InitConfigFactory("pcfcfg.yaml"); err != nil { + fmt.Printf("Error in InitConfigFactory: %v\n", err) + } + got := PcfConfig.Configuration.WebuiUri + want := "webui:9876" + assert.Equal(t, got, want, "The webui URL is not correct.") +} + +// Webui URL is set to a custom value then custom Webui URL is returned +func TestGetCustomWebuiUrl(t *testing.T) { + if err := InitConfigFactory("pcfcfg_with_custom_webui_url.yaml"); err != nil { + fmt.Printf("Error in InitConfigFactory: %v\n", err) + } + got := PcfConfig.Configuration.WebuiUri + want := "myspecialwebui:9872" + assert.Equal(t, got, want, "The webui URL is not correct.") +} diff --git a/factory/pcfcfg.yaml b/factory/pcfcfg.yaml new file mode 100644 index 0000000..33c4c12 --- /dev/null +++ b/factory/pcfcfg.yaml @@ -0,0 +1,13 @@ +# SPDX-License-Identifier: Apache-2.0 +# SPDX-FileCopyrightText: 2024 Canonical Ltd. + +configuration: + defaultBdtRefId: BdtPolicyId- + mongodb: + name: free5gc + url: http://1.1.1.1 + nrfUri: https://nrf:443 + pcfName: PCF +info: + description: PCF initial local configuration + version: 1.0.0 diff --git a/factory/pcfcfg_with_custom_webui_url.yaml b/factory/pcfcfg_with_custom_webui_url.yaml new file mode 100644 index 0000000..ec68ce4 --- /dev/null +++ b/factory/pcfcfg_with_custom_webui_url.yaml @@ -0,0 +1,14 @@ +# SPDX-License-Identifier: Apache-2.0 +# SPDX-FileCopyrightText: 2024 Canonical Ltd. + +configuration: + defaultBdtRefId: BdtPolicyId- + mongodb: + name: free5gc + url: http://1.1.1.1 + nrfUri: https://nrf:443 + webuiUri: myspecialwebui:9872 # a valid URI of Webui + pcfName: PCF +info: + description: PCF initial local configuration + version: 1.0.0 diff --git a/service/init.go b/service/init.go index 235de9f..5a98b3f 100644 --- a/service/init.go +++ b/service/init.go @@ -114,7 +114,7 @@ func (pcf *PCF) Initialize(c *cli.Context) error { roc := os.Getenv("MANAGED_BY_CONFIG_POD") if roc == "true" { initLog.Infoln("MANAGED_BY_CONFIG_POD is true") - gClient := client.ConnectToConfigServer("webui:9876") + gClient := client.ConnectToConfigServer(factory.PcfConfig.Configuration.WebuiUri) commChannel := gClient.PublishOnConfigChange(true) go pcf.updateConfig(commChannel) } else {