Skip to content

Commit

Permalink
chore: Parameterise webui url (#97)
Browse files Browse the repository at this point in the history
Signed-off-by: gatici <[email protected]>
  • Loading branch information
gatici authored Apr 15, 2024
1 parent 533badc commit 63c9423
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 1 deletion.
1 change: 1 addition & 0 deletions factory/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`

Expand Down
3 changes: 3 additions & 0 deletions factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions factory/pcf_config_test.go
Original file line number Diff line number Diff line change
@@ -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.")
}
13 changes: 13 additions & 0 deletions factory/pcfcfg.yaml
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions factory/pcfcfg_with_custom_webui_url.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion service/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 63c9423

Please sign in to comment.