Skip to content

Commit

Permalink
chore: allow vendor overrides for env var variables (#100)
Browse files Browse the repository at this point in the history
## 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
  • Loading branch information
Racer159 authored May 23, 2024
1 parent 1a3541e commit 849a3b3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()}
)

Expand Down

0 comments on commit 849a3b3

Please sign in to comment.