mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-01-16 05:16:08 +02:00
consider alias during secret resolving (#2327)
This commit is contained in:
parent
14d7196495
commit
9d461c6753
@ -151,7 +151,7 @@ func lookupPath(client vaultClient, path string, param *StepParameters) *string
|
||||
|
||||
// try parameter aliases
|
||||
for _, alias := range param.Aliases {
|
||||
field := secret[param.Name]
|
||||
field := secret[alias.Name]
|
||||
if field != "" {
|
||||
log.RegisterSecret(field)
|
||||
if alias.Deprecated {
|
||||
|
@ -6,10 +6,9 @@ import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/mock"
|
||||
|
||||
"github.com/SAP/jenkins-library/pkg/config/mocks"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/mock"
|
||||
)
|
||||
|
||||
func TestVaultConfigLoad(t *testing.T) {
|
||||
@ -64,6 +63,21 @@ func TestVaultConfigLoad(t *testing.T) {
|
||||
assert.Len(t, stepConfig.Config, 1)
|
||||
})
|
||||
|
||||
t.Run("Alias names should be considered", func(t *testing.T) {
|
||||
aliasName := "alias"
|
||||
vaultMock := &mocks.VaultMock{}
|
||||
stepConfig := StepConfig{Config: map[string]interface{}{
|
||||
"vaultBasePath": "team1",
|
||||
}}
|
||||
param := stepParam(secretName, "vaultSecret", "$(vaultBasePath)/pipelineA")
|
||||
addAlias(¶m, aliasName)
|
||||
stepParams := []StepParameters{param}
|
||||
vaultData := map[string]string{aliasName: "value1"}
|
||||
vaultMock.On("GetKvSecret", "team1/pipelineA").Return(vaultData, nil)
|
||||
resolveAllVaultReferences(&stepConfig, vaultMock, stepParams)
|
||||
assert.Equal(t, "value1", stepConfig.Config[secretName])
|
||||
})
|
||||
|
||||
t.Run("Search over multiple paths", func(t *testing.T) {
|
||||
vaultMock := &mocks.VaultMock{}
|
||||
stepConfig := StepConfig{Config: map[string]interface{}{
|
||||
@ -148,7 +162,8 @@ func TestVaultSecretFiles(t *testing.T) {
|
||||
|
||||
func stepParam(name string, refType string, refPaths ...string) StepParameters {
|
||||
return StepParameters{
|
||||
Name: name,
|
||||
Name: name,
|
||||
Aliases: []Alias{},
|
||||
ResourceRef: []ResourceReference{
|
||||
{
|
||||
Type: refType,
|
||||
@ -157,3 +172,8 @@ func stepParam(name string, refType string, refPaths ...string) StepParameters {
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func addAlias(param *StepParameters, aliasName string) {
|
||||
alias := Alias{Name: aliasName}
|
||||
param.Aliases = append(param.Aliases, alias)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user