Skip to content

Commit

Permalink
added getDict method to valueReader interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillermo Fernández authored and ruiztulio committed Dec 23, 2023
1 parent 6345f36 commit 7d9ed67
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
15 changes: 9 additions & 6 deletions utils/odoo.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,13 @@ func DefaultConverter(list []string) map[string]string {
// will be replaced in the configuration file, returns them as a map of strings where the key is the key of the
// configuration.
func OdoorcConverter(list []string) map[string]string {
res := make(map[string]string)
env_list := SplitEnvVars(list)
for k, v := range env_list {
return OdoorcMapConverter(env_list)
}

func OdoorcMapConverter(m map[string]string) map[string]string {
res := make(map[string]string)
for k, v := range m {
if strings.HasPrefix(strings.ToLower(k), "odoorc_") {
key := strings.TrimPrefix(strings.ToLower(k), "odoorc_")
res[key] = v
Expand Down Expand Up @@ -202,10 +206,9 @@ func Odoo() error {
log.Errorf("Error loading Odoo config: %s", err.Error())
return err
}
fullEnv := os.Environ()
defaultVars := FilterStrings(fullEnv, DefaultConverter)
UpdateFromVars(odooCfg, defaultVars, false)
odooVars := FilterStrings(fullEnv, OdoorcConverter)
store := vr.getDict()
UpdateFromVars(odooCfg, store, false)
odooVars := OdoorcMapConverter(store)
UpdateFromVars(odooCfg, odooVars, true)

SetupWorker(odooCfg, vr.readValue("CONTAINER_TYPE"))
Expand Down
13 changes: 11 additions & 2 deletions utils/value_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

type valueReader interface {
readValue(string) string
getDict() map[string]string
}

type (
Expand All @@ -20,9 +21,17 @@ type (
func (eg *envGetter) readValue(key string) string {
return os.Getenv(key)
}
func (eg *envGetter) getDict() map[string]string {
fullEnv := os.Environ()
return DefaultConverter(fullEnv)
}

func (vs *valueStore) readValue(key string) string {
return vs.dict[key]
}

func (fg *valueStore) readValue(key string) string {
return fg.dict[key]
func (vs *valueStore) getDict() map[string]string {
return vs.dict
}

func (vs *valueStore) updateDict(f func(string) (map[string]string, error)) error {
Expand Down

0 comments on commit 7d9ed67

Please sign in to comment.