diff --git a/cmd/core-command/res/configuration.toml b/cmd/core-command/res/configuration.toml index c87a3147d2..00a655db23 100644 --- a/cmd/core-command/res/configuration.toml +++ b/cmd/core-command/res/configuration.toml @@ -11,6 +11,7 @@ clientkey = "" [Service] +Host = "localhost" Port = 59882 StartupMsg = "This is the Core Command Microservice" diff --git a/cmd/core-common-config-bootstrapper/res/configuration.yaml b/cmd/core-common-config-bootstrapper/res/configuration.yaml index ba8decf45e..661d06ab4d 100644 --- a/cmd/core-common-config-bootstrapper/res/configuration.yaml +++ b/cmd/core-common-config-bootstrapper/res/configuration.yaml @@ -19,7 +19,7 @@ all-services: SecuritySecretsStored: false SecurityConsulTokensRequested: false SecurityConsulTokenDuration: false - Tags: # Contains the service level tags to be attached to all the service's metrics +# Tags: # Contains the service level tags to be attached to all the service's metrics # Gateway: "my-iot-gateway" # Tag must be added here or via Consul Env Override can only change existing value, not added new ones. Service: diff --git a/cmd/core-data/res/configuration.toml b/cmd/core-data/res/configuration.toml index c760ac14d0..2e9491f0ea 100644 --- a/cmd/core-data/res/configuration.toml +++ b/cmd/core-data/res/configuration.toml @@ -11,6 +11,7 @@ PersistData = true # Gateway="my-iot-gateway" # Tag must be added here or via Consul Env Override can only change existing value, not added new ones. [Service] +Host = "localhost" Port = 59880 StartupMsg = "This is the Core Data Microservice" diff --git a/cmd/core-metadata/res/configuration.toml b/cmd/core-metadata/res/configuration.toml index 9754022fb4..918b2ed79c 100644 --- a/cmd/core-metadata/res/configuration.toml +++ b/cmd/core-metadata/res/configuration.toml @@ -7,6 +7,7 @@ LogLevel = "INFO" Validation = false [Service] +Host = "localhost" Port = 59881 StartupMsg = "This is the EdgeX Core Metadata Microservice" diff --git a/cmd/security-proxy-auth/res/configuration.toml b/cmd/security-proxy-auth/res/configuration.toml index c3253381e3..29069e3c27 100644 --- a/cmd/security-proxy-auth/res/configuration.toml +++ b/cmd/security-proxy-auth/res/configuration.toml @@ -2,5 +2,6 @@ LogLevel = "INFO" [Service] +Host = "localhost" Port = 59842 StartupMsg = "This is the proxy authentication microservice" diff --git a/cmd/security-spiffe-token-provider/res/configuration.toml b/cmd/security-spiffe-token-provider/res/configuration.toml index 268ac908ad..762b9e86de 100644 --- a/cmd/security-spiffe-token-provider/res/configuration.toml +++ b/cmd/security-spiffe-token-provider/res/configuration.toml @@ -2,6 +2,7 @@ LogLevel = "DEBUG" [Service] +Host = "localhost" Port = 59841 StartupMsg = "This is the SPIFFE token provider microservice" diff --git a/cmd/support-notifications/res/configuration.toml b/cmd/support-notifications/res/configuration.toml index a95eba2c0a..273884d8aa 100644 --- a/cmd/support-notifications/res/configuration.toml +++ b/cmd/support-notifications/res/configuration.toml @@ -10,6 +10,7 @@ ResendInterval = "5s" password = "" [Service] +Host = "localhost" Port = 59860 StartupMsg = "This is the Support Notifications Microservice" diff --git a/cmd/support-scheduler/res/configuration.toml b/cmd/support-scheduler/res/configuration.toml index 1ebdeaec3e..20882f5bc6 100644 --- a/cmd/support-scheduler/res/configuration.toml +++ b/cmd/support-scheduler/res/configuration.toml @@ -4,6 +4,7 @@ ScheduleIntervalTime = 500 LogLevel = "INFO" [Service] +Host = "localhost" Port = 59861 StartupMsg = "This is the Support Scheduler Microservice" diff --git a/go.mod b/go.mod index a17480dd2b..8ffac7f2ad 100644 --- a/go.mod +++ b/go.mod @@ -4,10 +4,10 @@ go 1.20 require ( github.com/eclipse/paho.mqtt.golang v1.4.2 - github.com/edgexfoundry/go-mod-bootstrap/v3 v3.0.0-dev.46 + github.com/edgexfoundry/go-mod-bootstrap/v3 v3.0.0-dev.50 github.com/edgexfoundry/go-mod-configuration/v3 v3.0.0-dev.7 - github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.27 - github.com/edgexfoundry/go-mod-messaging/v3 v3.0.0-dev.16 + github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.30 + github.com/edgexfoundry/go-mod-messaging/v3 v3.0.0-dev.18 github.com/edgexfoundry/go-mod-secrets/v3 v3.0.0-dev.9 github.com/fxamacker/cbor/v2 v2.4.0 github.com/gomodule/redigo v1.8.9 diff --git a/go.sum b/go.sum index 31a860031f..3a7b4fabf3 100644 --- a/go.sum +++ b/go.sum @@ -25,14 +25,14 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/eclipse/paho.mqtt.golang v1.4.2 h1:66wOzfUHSSI1zamx7jR6yMEI5EuHnT1G6rNA5PM12m4= github.com/eclipse/paho.mqtt.golang v1.4.2/go.mod h1:JGt0RsEwEX+Xa/agj90YJ9d9DH2b7upDZMK9HRbFvCA= -github.com/edgexfoundry/go-mod-bootstrap/v3 v3.0.0-dev.46 h1:A15UzeUgFfQM+R27LvXeoUJAbVFgY41NEhMcDF8XOQU= -github.com/edgexfoundry/go-mod-bootstrap/v3 v3.0.0-dev.46/go.mod h1:nweayvPW3G+nBZwwdRB6lWq3u0e1rWGvReEWEjDQjFE= +github.com/edgexfoundry/go-mod-bootstrap/v3 v3.0.0-dev.50 h1:iP/2tKszlM6Ud1El3kY9wdB7lnsvuIHWquYNLDXwvQw= +github.com/edgexfoundry/go-mod-bootstrap/v3 v3.0.0-dev.50/go.mod h1:oz5+G3SImWqKvRIcKrh/ErXae9nNapmDNnlXsdykpGg= github.com/edgexfoundry/go-mod-configuration/v3 v3.0.0-dev.7 h1:pOH2GLDg1KB4EmAzo6IEvl4NEVFAw3ywxPUMa5Wi1Vw= github.com/edgexfoundry/go-mod-configuration/v3 v3.0.0-dev.7/go.mod h1:ZZbOu7K0/P8B1VKhZygVujLQyhvWuPe0E2vC/k2yscw= -github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.27 h1:lKM/NwRBL/pddoSnlXbFIlpgu+XozWbqz608EeB7S94= -github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.27/go.mod h1:QBzXOAoyLzBm5k9CshgH9CR9nWMNXxZjknBFMnGJN/A= -github.com/edgexfoundry/go-mod-messaging/v3 v3.0.0-dev.16 h1:JdZiqZ6CAboZ3+GuWZLyXc42y8HfsH1CmsIKNPY+0PY= -github.com/edgexfoundry/go-mod-messaging/v3 v3.0.0-dev.16/go.mod h1:3q+Ys51HwpR9/kOv6sT7+EwAANgOfFWi509sEP5iPEo= +github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.30 h1:diarfNbfUeSYD7Hq8pOqHzxMtIbaPO6W8nWq34W8X6g= +github.com/edgexfoundry/go-mod-core-contracts/v3 v3.0.0-dev.30/go.mod h1:SYoD+tmUP/zwWuuIySmsQSjPx6MHP+2w9FsLgm0IR7A= +github.com/edgexfoundry/go-mod-messaging/v3 v3.0.0-dev.18 h1:8empqTOIVhKzebC3gnP9C0LGQvwXtHLJF8x8AqlTGLM= +github.com/edgexfoundry/go-mod-messaging/v3 v3.0.0-dev.18/go.mod h1:Sf7lvKtICWRy0Tmvw+bV6L1wdXKRaTSmKmJKw4Caxe4= github.com/edgexfoundry/go-mod-registry/v3 v3.0.0-dev.5 h1:FUUfsQUKHJqSwOXEj0j/qAn+uoWzM8nV7IOapGf7D80= github.com/edgexfoundry/go-mod-registry/v3 v3.0.0-dev.5/go.mod h1:MroNeX/i6ymRu8cyuRB4U5zdBusyUpFhUphko6pInTQ= github.com/edgexfoundry/go-mod-secrets/v3 v3.0.0-dev.9 h1:12UHZG/Nl+dfFOaNnC87ANP/FQ3rOXe0Z6NVlYdmYgU= diff --git a/internal/core/common_config/main.go b/internal/core/common_config/main.go index c4f8096d9a..be412bc255 100644 --- a/internal/core/common_config/main.go +++ b/internal/core/common_config/main.go @@ -34,6 +34,7 @@ import ( "github.com/edgexfoundry/go-mod-core-contracts/v3/clients/logger" "github.com/edgexfoundry/go-mod-core-contracts/v3/common" "github.com/edgexfoundry/go-mod-core-contracts/v3/models" + "github.com/pelletier/go-toml" "gopkg.in/yaml.v3" ) @@ -44,7 +45,7 @@ const ( func Main(ctx context.Context, cancel context.CancelFunc) { startupTimer := startup.NewStartUpTimer(common.CoreCommonConfigServiceKey) - // All common command-line flags have been moved to DefaultCommonFlags. Service specific flags can be add here, + // All common command-line flags have been moved to DefaultCommonFlags. Service specific flags can be added here, // by inserting service specific flag prior to call to commonFlags.Parse(). // Example: // flags.FlagSet.StringVar(&myvar, "m", "", "Specify a ....") @@ -117,17 +118,18 @@ func Main(ctx context.Context, cancel context.CancelFunc) { os.Exit(1) } - lc.Infof("configuration exists: %v", hasConfig) - // load the yaml file and push it using the config client if !hasConfig || f.OverwriteConfig() { + lc.Info("Pushing common configuration. It doesn't exists or overwrite flag is set") + yamlFile := config.GetConfigLocation(lc, f) - lc.Infof("parsing %s for configuration", yamlFile) - err = loadYaml(lc, yamlFile, configClient) + err = pushConfiguration(lc, yamlFile, configClient) if err != nil { lc.Error(err.Error()) os.Exit(1) } + } else { + lc.Info("Skipped pushing common configuration. It already exists and overwrite flag not set") } lc.Info("Core Common Config exiting") @@ -157,13 +159,13 @@ func translateInterruptToCancel(ctx context.Context, wg *sync.WaitGroup, cancel }() } -func loadYaml(lc logger.LoggingClient, yamlFile string, configClient configuration.Client) error { +func pushConfiguration(lc logger.LoggingClient, yamlFile string, configClient configuration.Client) error { // push not done flag to configClient err := configClient.PutConfigurationValue(commonConfigDone, []byte("false")) if err != nil { return fmt.Errorf("failed to push %s on startup: %s", commonConfigDone, err.Error()) } - lc.Infof("reading %s", yamlFile) + lc.Infof("Using common configuration from %s", yamlFile) contents, err := os.ReadFile(yamlFile) if err != nil { return fmt.Errorf("failed to read common configuration file %s: %s", yamlFile, err.Error()) @@ -179,6 +181,11 @@ func loadYaml(lc logger.LoggingClient, yamlFile string, configClient configurati kv = buildKeyValues(data, kv, "") + kv, err = applyEnvOverrides(kv, lc) + if err != nil { + return fmt.Errorf("failed to apply env overrides to common configuration: %s", err.Error()) + } + keys := make([]string, 0, len(kv)) for k := range kv { @@ -203,6 +210,9 @@ func loadYaml(lc logger.LoggingClient, yamlFile string, configClient configurati if err != nil { return fmt.Errorf("failed to push %s on completion: %s", commonConfigDone, err.Error()) } + + lc.Info("Common configuration has been pushed to into Configuration Provider with overrides applied") + return nil } @@ -229,3 +239,21 @@ func buildKeyValues(data map[string]interface{}, kv map[string]interface{}, orig return kv } + +func applyEnvOverrides(keyValues map[string]any, lc logger.LoggingClient) (map[string]any, error) { + env := environment.NewVariables(lc) + tomlTree, err := toml.TreeFromMap(keyValues) + if err != nil { + return nil, err + } + + overrideCount, err := env.OverrideTomlValues(tomlTree) + if err != nil { + return nil, err + } + + keyValues = tomlTree.ToMap() + lc.Infof("Common configuration loaded from file with %d overrides applied", overrideCount) + + return keyValues, nil +}