Skip to content

Commit

Permalink
Merge pull request Vauxoo#27 from vauxoo-dev/master-fix_append_vars-t…
Browse files Browse the repository at this point in the history
…ruiz

[FIX] Only add vars to the config file when requested.
  • Loading branch information
ruiztulio authored Oct 8, 2022
2 parents 1f12ebf + fc60f67 commit 44c5fa1
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions utils/odoo.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,12 @@ func SetupWorker(config *ini.File, containerType string) {
}
}

// UpdateFromVars will updae the odoo configuration from env vars wich should start with ODOORC_ prefix, if the exists
// the value will be updated else the parameter will be added to the 'options' section which is the default for Odoo.
// UpdateFromVars will update the odoo configuration from env vars wich should start with ODOORC_ prefix, if the exists
// the value will be updated else the parameter will be added to the 'options' section only when appendNew == true,
// which is the default for Odoo.
// If you wish to add it to another section add the desired section to '/external_files/openerp_serverrc' or add
// the file with only that section to '/external_files/odoocfg'
func UpdateFromVars(config *ini.File, odooVars map[string]string) {
func UpdateFromVars(config *ini.File, odooVars map[string]string, appendNew bool) {
sections := config.Sections()
for k, v := range odooVars {
k = strings.ToLower(k)
Expand All @@ -165,8 +166,8 @@ func UpdateFromVars(config *ini.File, odooVars map[string]string) {
break
}
}
// The key does not exist so we add it into the options section
if !updated {
// The key does not exist and we want to force append, so we add it into the options section
if !updated && appendNew {
config.Section("options").Key(k).SetValue(v)
}
}
Expand Down Expand Up @@ -203,9 +204,9 @@ func Odoo() error {
}
fullEnv := os.Environ()
defaultVars := FilterStrings(fullEnv, DefaultConverter)
UpdateFromVars(odooCfg, defaultVars)
UpdateFromVars(odooCfg, defaultVars, false)
odooVars := FilterStrings(fullEnv, OdoorcConverter)
UpdateFromVars(odooCfg, odooVars)
UpdateFromVars(odooCfg, odooVars, true)
SetupWorker(odooCfg, os.Getenv("CONTAINER_TYPE"))
instanceType, err := GetInstanceType()
if err != nil {
Expand Down

0 comments on commit 44c5fa1

Please sign in to comment.