Skip to content

Commit

Permalink
fixup! vendor credentials is env-vars for execute
Browse files Browse the repository at this point in the history
  • Loading branch information
davidcheung committed Jun 25, 2020
1 parent 86647a8 commit 112779b
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
11 changes: 9 additions & 2 deletions internal/apply/apply.go
Expand Up @@ -77,11 +77,18 @@ func applyAll(dir string, projectConfig projectconfig.ZeroProjectConfig, applyEn
modulePath = filepath.Join(dir, modulePath)
}

// TODO: in the case user lost the `/tmp` (module source dir), this will fail
// and we should redownload the module for the user
modConfig, err := module.ParseModuleConfig(modulePath)
if err != nil {
exit.Fatal("Failed to load module config, credentials cannot be injected properly")
}

// Get project credentials for the makefile
credentials := globalconfig.GetProjectCredentials(projectConfig.Name)

credentialEnvs := credentials.SelectedVendorsCredentialsAsEnv(modConfig.RequiredCredentials)
envList = util.AppendProjectEnvToCmdEnv(mod.Parameters, envList)
envList = util.AppendProjectEnvToCmdEnv(credentials.AsEnvVars(), envList)
envList = util.AppendProjectEnvToCmdEnv(credentialEnvs, envList)
util.ExecuteCommand(exec.Command("make"), modulePath, envList)
return nil
})
Expand Down
5 changes: 5 additions & 0 deletions internal/config/globalconfig/global_config_test.go
Expand Up @@ -161,4 +161,9 @@ func TestMarshalSelectedVendorsCredentialsAsEnv(t *testing.T) {
assert.Equal(t, false, hasCircleCIKey)
})

t.Run("omits vendors not selected", func(t *testing.T) {
envs := pc.SelectedVendorsCredentialsAsEnv([]string{})
assert.Equal(t, 0, len(envs))
})

}
19 changes: 19 additions & 0 deletions tests/test_data/apply/project1/zero-module.yml
@@ -0,0 +1,19 @@
name: project1
description: 'project1'
author: 'Commit'

template:
strictMode: true
delimiters:
- "<%"
- "%>"
inputDir: '.'
outputDir: 'test'

requiredCredentials:
- aws
- github

parameters:
- field: foo
label: foo
19 changes: 19 additions & 0 deletions tests/test_data/apply/project2/zero-module.yml
@@ -0,0 +1,19 @@
name: project2
description: 'project2'
author: 'Commit'

template:
strictMode: true
delimiters:
- "<%"
- "%>"
inputDir: '.'
outputDir: 'test'

requiredCredentials:
- aws
- github

parameters:
- field: baz
label: baz

0 comments on commit 112779b

Please sign in to comment.