From 849a3b3fece6658cc3901bc7062a081c7fceaf51 Mon Sep 17 00:00:00 2001 From: Wayne Starr Date: Thu, 23 May 2024 15:01:21 -0600 Subject: [PATCH] chore: allow vendor overrides for env var variables (#100) ## Description This allows env vars to be pulled in from a vendored prefix as well as MARU_ ## Related Issue Fixes #N/A ## Type of change - [X] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Other (security config, docs update, etc) ## Checklist before merging - [X] Test, docs, adr added or updated as needed - [X] [Contributor Guide Steps](https://github.com/defenseunicorns/maru-runner/blob/main/CONTRIBUTING.md) followed --- src/cmd/run.go | 6 +++++- src/config/config.go | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/cmd/run.go b/src/cmd/run.go index 746ec1e..0a83709 100644 --- a/src/cmd/run.go +++ b/src/cmd/run.go @@ -59,11 +59,15 @@ var runCmd = &cobra.Command{ // ensure vars are uppercase setRunnerVariables = helpers.TransformMapKeys(setRunnerVariables, strings.ToUpper) - // set any env vars that come from the environment + // set any env vars that come from the environment (taking MARU_ over VENDOR_) for _, variable := range tasksFile.Variables { if _, ok := setRunnerVariables[variable.Name]; !ok { if value := os.Getenv(fmt.Sprintf("%s_%s", strings.ToUpper(config.EnvPrefix), variable.Name)); value != "" { setRunnerVariables[variable.Name] = value + } else if config.VendorPrefix != "" { + if value := os.Getenv(fmt.Sprintf("%s_%s", strings.ToUpper(config.VendorPrefix), variable.Name)); value != "" { + setRunnerVariables[variable.Name] = value + } } } } diff --git a/src/config/config.go b/src/config/config.go index 56e2000..0a4a366 100644 --- a/src/config/config.go +++ b/src/config/config.go @@ -33,6 +33,9 @@ var ( // TempDirectory is the directory to store temporary files TempDirectory string + // VendorPrefix is the prefix for environment variables that an application vendoring Maru wants to use + VendorPrefix string + extraEnv = map[string]string{"MARU": "true", "MARU_ARCH": GetArch()} )