Skip to content

Commit

Permalink
copies templateData default variables to secretsData (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
samdfonseca committed Apr 1, 2021
1 parent 5627251 commit 59e4141
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,10 @@ func templateData(c *cli.Context, project string, vars map[string]interface{}, s
secretsData := map[string]interface{}{}
secretsDataRedacted := map[string]string{}

for k, v := range templateData {
secretsData[k] = v
}

// Add variables to data used for rendering both templates.
for k, v := range vars {
// Don't allow vars to be overridden.
Expand Down
26 changes: 23 additions & 3 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,14 @@ func TestTemplateData(t *testing.T) {
}, tmplData)

assert.Equal(t, map[string]interface{}{
"BRANCH": "master",
"BUILD_NUMBER": "2",
"COMMIT": "e0f21b90a",
"TAG": "v0.0.0",
"project": "test-project",
"zone": "us-east1-b",
"cluster": "cluster-0",
"namespace": "",
"key0": "val0",
"key1": "hello $USER",
"SECRET_TEST": "test_val",
Expand Down Expand Up @@ -298,6 +306,14 @@ func TestTemplateDataExpandingVars(t *testing.T) {
}, tmplData)

assert.Equal(t, map[string]interface{}{
"BRANCH": "master",
"BUILD_NUMBER": "2",
"COMMIT": "e0f21b90a",
"TAG": "v0.0.0",
"project": "test-project",
"zone": "us-east1-b",
"cluster": "cluster-0",
"namespace": "",
"key0": "val0",
"key1": "hello drone-user",
"SECRET_TEST": "test_val",
Expand Down Expand Up @@ -333,7 +349,11 @@ func TestRenderTemplates(t *testing.T) {
"COMMIT": "e0f21b90a",
"key0": "val0",
}
secretsData := map[string]interface{}{"SECRET_TEST": "test_sec_val"}
secretsData := map[string]interface{}{
"COMMIT": "e0f21b90a",
"key0": "val0",
"SECRET_TEST": "test_sec_val",
}

// No template file, should error
os.Remove(kubeTemplatePath)
Expand All @@ -346,7 +366,7 @@ func TestRenderTemplates(t *testing.T) {
tmplBuf := []byte("{{.COMMIT}}-{{.key0}}")
err = ioutil.WriteFile(kubeTemplatePath, tmplBuf, 0600)
assert.NoError(t, err)
tmplBuf = []byte("{{.SECRET_TEST}}")
tmplBuf = []byte("{{.COMMIT}}-{{.SECRET_TEST}}")
err = ioutil.WriteFile(secretTemplatePath, tmplBuf, 0600)
assert.NoError(t, err)

Expand All @@ -359,7 +379,7 @@ func TestRenderTemplates(t *testing.T) {
assert.Equal(t, "e0f21b90a-val0", string(buf))

buf, err = ioutil.ReadFile(manifestPaths[secretTemplatePath])
assert.Equal(t, "test_sec_val", string(buf))
assert.Equal(t, "e0f21b90a-test_sec_val", string(buf))

// Secret variables shouldn't be available in kube template
tmplBuf = []byte("{{.SECRET_TEST}}")
Expand Down

0 comments on commit 59e4141

Please sign in to comment.