From 121d301208018cadf885d9085094e81ca7c88157 Mon Sep 17 00:00:00 2001 From: Farshid Tavakolizadeh Date: Mon, 13 Mar 2023 16:38:12 +0100 Subject: [PATCH] Move env file to parent directory to avoid conflict with config provider --- options/env.go | 9 +++++++-- options/options_test.go | 8 ++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/options/env.go b/options/env.go index 6e88539..b4d1d06 100644 --- a/options/env.go +++ b/options/env.go @@ -78,9 +78,9 @@ func (cp *configProcessor) filename(service string) string { // include the service name in it's configuration path. var path string if env.SnapName == "edgex-app-service-configurable" { - path = fmt.Sprintf("%s/config/res/%s.env", env.SnapData, service) + path = fmt.Sprintf("%s/config/overrides.env", env.SnapData) } else { - path = fmt.Sprintf("%s/config/%s/res/%s.env", env.SnapData, service, service) + path = fmt.Sprintf("%s/config/%s/overrides.env", env.SnapData, service) } return path } @@ -99,6 +99,11 @@ func (cp *configProcessor) writeEnvFiles() error { continue } + // Add comment on top of the file + if _, err := fmt.Fprintln(&buffer, "# System-generated list of environment variables from snap options"); err != nil { + return err + } + // add env vars to buffer for k, v := range envVars { if _, err := fmt.Fprintf(&buffer, "%s=\"%s\"\n", k, v); err != nil { diff --git a/options/options_test.go b/options/options_test.go index 9742c95..257488c 100644 --- a/options/options_test.go +++ b/options/options_test.go @@ -42,12 +42,12 @@ func TestProcessConfig(t *testing.T) { // uncomment to cleanup previous mess // assert.NoError(t, snapctl.Unset("app-options", "config-enabled", "apps", "config").Run()) - configDir := fmt.Sprintf("%s/config/%s/res/", env.SnapData, testService) - envFile := path.Join(configDir, testService+".env") + configDir := fmt.Sprintf("%s/config/%s/", env.SnapData, testService) + envFile := path.Join(configDir, "overrides.env") os.MkdirAll(configDir, os.ModePerm) - configDir2 := fmt.Sprintf("%s/config/%s/res/", env.SnapData, testService2) - envFile2 := path.Join(configDir2, testService2+".env") + configDir2 := fmt.Sprintf("%s/config/%s/", env.SnapData, testService2) + envFile2 := path.Join(configDir2, "overrides.env") os.MkdirAll(configDir2, os.ModePerm) require.NoError(t, snapctl.Set("debug", "true").Run())