Skip to content

Commit

Permalink
Merge pull request #749 from cloudxxx8/issue-747
Browse files Browse the repository at this point in the history
feat: Add new env to support -o flag
  • Loading branch information
jinlinGuan authored Aug 23, 2024
2 parents b2f41d9 + e434cfd commit 6f7163b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
16 changes: 9 additions & 7 deletions bootstrap/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ type Processor struct {
wg *sync.WaitGroup
configUpdated UpdatedStream
dic *di.Container
overwriteConfig bool
providerHasConfig bool
commonConfigClient configuration.Client
appConfigClient configuration.Client
Expand Down Expand Up @@ -134,7 +133,6 @@ func (cp *Processor) Process(
secretProvider interfaces.SecretProviderExt,
jwtSecretProvider clientinterfaces.AuthenticationInjector) error {

cp.overwriteConfig = cp.flags.OverwriteConfig()
configProviderUrl := cp.flags.ConfigProviderUrl()
remoteHosts := environment.GetRemoteServiceHosts(cp.lc, cp.flags.RemoteServiceHosts())

Expand Down Expand Up @@ -201,7 +199,7 @@ func (cp *Processor) Process(
return fmt.Errorf("failed check for Configuration Provider has private configiuration: %s", err.Error())
}

if cp.providerHasConfig && !cp.overwriteConfig {
if cp.providerHasConfig && !cp.overwriteConfig() {
privateServiceConfig, err = copyConfigurationStruct(serviceConfig)
if err != nil {
return err
Expand Down Expand Up @@ -247,7 +245,7 @@ func (cp *Processor) Process(
}

// Now load the private config from a local file if any of these conditions are true
if !useProvider || !cp.providerHasConfig || cp.overwriteConfig {
if !useProvider || !cp.providerHasConfig || cp.overwriteConfig() {
filePath := GetConfigFileLocation(cp.lc, cp.flags)
configMap, err := cp.loadConfigYamlFromFile(filePath)
if err != nil {
Expand All @@ -266,7 +264,7 @@ func (cp *Processor) Process(
}

if useProvider {
if err := privateConfigClient.PutConfigurationMap(configMap, cp.overwriteConfig); err != nil {
if err := privateConfigClient.PutConfigurationMap(configMap, cp.overwriteConfig()); err != nil {
return fmt.Errorf("could not push private configuration into Configuration Provider: %s", err.Error())
}

Expand Down Expand Up @@ -334,6 +332,10 @@ func (cp *Processor) Process(
return err
}

func (cp *Processor) overwriteConfig() bool {
return environment.OverwriteConfig() || cp.flags.OverwriteConfig()
}

func getLocalIP() string {
// Because of how UDP works, the connection is not established - no handshake is performed, no data is sent.
// The purpose of this is to get the local IP address that a UDP connection would use if it were sending data to
Expand Down Expand Up @@ -593,7 +595,7 @@ func (cp *Processor) LoadCustomConfigSection(updatableConfig interfaces.Updatabl
err.Error())
}

if exists && !cp.flags.OverwriteConfig() {
if exists && !cp.overwriteConfig() {
rawConfig, err := configClient.GetConfiguration(updatableConfig)
if err != nil {
return fmt.Errorf(
Expand Down Expand Up @@ -637,7 +639,7 @@ func (cp *Processor) LoadCustomConfigSection(updatableConfig interfaces.Updatabl
}

var overwriteMessage = ""
if exists && cp.flags.OverwriteConfig() {
if exists && cp.overwriteConfig() {
overwriteMessage = "(overwritten)"
}
cp.lc.Infof("Custom Config loaded from file and pushed to Configuration Provider %s", overwriteMessage)
Expand Down
16 changes: 16 additions & 0 deletions bootstrap/environment/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const (
envKeyConfigFile = "EDGEX_CONFIG_FILE"
envKeyFileURITimeout = "EDGEX_FILE_URI_TIMEOUT"
envKeyRemoteServiceHosts = "EDGEX_REMOTE_SERVICE_HOSTS"
envOverwriteConfig = "EDGEX_OVERWRITE_CONFIG"

noConfigProviderValue = "none"

Expand Down Expand Up @@ -491,3 +492,18 @@ func GetRemoteServiceHosts(lc logger.LoggingClient, remoteHosts []string) []stri

return strings.Split(envValue, ",")
}

// OverwriteConfig returns whether the local configuration should be pushed (overwrite) into the Configuration provider
func OverwriteConfig() bool {
envValue := os.Getenv(envOverwriteConfig)
if len(envValue) == 0 {
return false
}

boolValue, err := strconv.ParseBool(envValue)
if err != nil {
return false
}

return boolValue
}

0 comments on commit 6f7163b

Please sign in to comment.