Skip to content

Commit

Permalink
fix parsing vault placeholders (jenkins-x#3668)
Browse files Browse the repository at this point in the history
* switch upgrade platform to use public chartmuseum repo

* fix parsing vault placeholders
  • Loading branch information
rawlingsj authored and jenkins-x-bot committed Apr 18, 2019
1 parent 3c838f8 commit f0e892e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/jx/cmd/upgrade_platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ func (o *UpgradePlatformOptions) upgradePlatformViaGitOps(devEnv *v1.Environment
uopts.ReleaseName = JenkinsXPlatformRelease
uopts.GitOps = true
uopts.Version = targetVersion
uopts.Repo = opts.DefaultChartRepo
uopts.Repo = kube.DefaultChartMuseumURL
uopts.HelmUpdate = true

//opts.Chart = JenkinsXPlatformChartName
Expand Down
2 changes: 1 addition & 1 deletion pkg/vault/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const (
passwordKey = "Password"
)

var vaultURIRegex = regexp.MustCompile(`vault:[\w\/:]*`)
var vaultURIRegex = regexp.MustCompile(`vault:[-_\w\/:]*`)

// WriteYAMLFiles stores the given YAML files in vault. The final secret path is
// a concatenation of the 'path' with the file name.
Expand Down
28 changes: 28 additions & 0 deletions pkg/vault/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,31 @@ func TestReplaceURIs(t *testing.T) {
bar: %s
`, secret), result)
}

func TestReplaceRealExampleURI(t *testing.T) {
pegomock.RegisterMockTestingT(t)
vaultClient := vault_test.NewMockClient()
path := "secret/gitOps/jenkins-x/environment-tekton-mole-dev/connectors-github-config-clientid-secret"
key := "token-passthrough"
secret := uuid.New()
valuesyaml := fmt.Sprintf(`foo:
bar: vault:%s:%s
`, path, key)
valuesFile, err := ioutil.TempFile("", "values.yaml")
defer func() {
err := util.DeleteFile(valuesFile.Name())
assert.NoError(t, err)
}()
assert.NoError(t, err)
err = ioutil.WriteFile(valuesFile.Name(), []byte(valuesyaml), 0600)
assert.NoError(t, err)
pegomock.When(vaultClient.Read(pegomock.EqString(path))).ThenReturn(map[string]interface{}{
key: secret,
}, nil)
result, err := vault.ReplaceURIs(valuesyaml, vaultClient)
assert.NoError(t, err)
assert.NoError(t, err)
assert.Equal(t, fmt.Sprintf(`foo:
bar: %s
`, secret), result)
}

0 comments on commit f0e892e

Please sign in to comment.