From 2fcebe8309b8ac290724c35ae5d162b8b2737ed4 Mon Sep 17 00:00:00 2001 From: decentral1se Date: Wed, 4 Oct 2023 02:29:59 +0200 Subject: [PATCH] fix: don't export from within function Also, don't explode on command function which has "export" in the name! See https://git.coopcloud.tech/coop-cloud/organising/issues/498 --- pkg/config/env.go | 6 +++++- pkg/config/env_test.go | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/pkg/config/env.go b/pkg/config/env.go index 0874fb57..b43e22f6 100644 --- a/pkg/config/env.go +++ b/pkg/config/env.go @@ -153,7 +153,11 @@ func ReadAbraShEnvVars(abraSh string) (map[string]string, error) { scanner := bufio.NewScanner(file) for scanner.Scan() { line := scanner.Text() - if strings.Contains(line, "export") { + if strings.Contains(line, "export ") { + if len(strings.TrimLeft(line, " ")) < len(line) { + // NOTE(d1): indented lines are exports within functions + continue + } splitVals := strings.Split(line, "export ") envVarDef := splitVals[len(splitVals)-1] keyVal := strings.Split(envVarDef, "=") diff --git a/pkg/config/env_test.go b/pkg/config/env_test.go index 157d6ec9..bdfbdf7a 100644 --- a/pkg/config/env_test.go +++ b/pkg/config/env_test.go @@ -87,3 +87,25 @@ func TestReadEnv(t *testing.T) { ) } } + +func TestReadAbraShEnvVars(t *testing.T) { + if err := catalogue.EnsureCatalogue(); err != nil { + t.Fatal(err) + } + + offline := true + r, err := recipe.Get("abra-integration-test-recipe", offline) + if err != nil { + t.Fatal(err) + } + + abraShPath := fmt.Sprintf("%s/%s/%s", config.RECIPES_DIR, r.Name, "abra.sh") + abraShEnv, err := config.ReadAbraShEnvVars(abraShPath) + if err != nil { + t.Fatal(err) + } + + if _, ok := abraShEnv["INNER_FOO"]; ok { + t.Error("INNER_FOO should not be exported") + } +}