mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-12 10:55:20 +02:00
(fix) match regexes in sliceContains to support vaultSecretNames (#3618)
* (fix) match regexes in sliceContains to support vaultSecretNames * add test for regex matching in sliceContains Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
This commit is contained in:
parent
504f076613
commit
9f2d8a70b1
@ -9,6 +9,7 @@ import (
|
||||
"net/url"
|
||||
"os"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
piperhttp "github.com/SAP/jenkins-library/pkg/http"
|
||||
@ -508,7 +509,8 @@ func merge(base, overlay map[string]interface{}) map[string]interface{} {
|
||||
|
||||
func sliceContains(slice []string, find string) bool {
|
||||
for _, elem := range slice {
|
||||
if elem == find {
|
||||
matches, _ := regexp.MatchString(elem, find)
|
||||
if matches {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
@ -821,13 +821,19 @@ func TestMerge(t *testing.T) {
|
||||
MergeData: map[string]interface{}{"key1": map[string]interface{}{"key1_2": "value2"}},
|
||||
ExpectedOutput: map[string]interface{}{"key1": map[string]interface{}{"key1_1": "value1", "key1_2": "value2"}},
|
||||
},
|
||||
{
|
||||
Source: map[string]interface{}{"key1": "value1"},
|
||||
Filter: []string{"key1", ".+Key$"},
|
||||
MergeData: map[string]interface{}{"regexKey": "value2", "regexKeyIgnored": "value3", "Key": "value3"},
|
||||
ExpectedOutput: map[string]interface{}{"key1": "value1", "regexKey": "value2"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, row := range testTable {
|
||||
t.Run(fmt.Sprintf("Merging %v into %v", row.MergeData, row.Source), func(t *testing.T) {
|
||||
stepConfig := StepConfig{Config: row.Source}
|
||||
stepConfig.mixIn(row.MergeData, row.Filter)
|
||||
assert.Equal(t, row.ExpectedOutput, stepConfig.Config, "Mixin was incorrect")
|
||||
assert.Equal(t, row.ExpectedOutput, stepConfig.Config, "Mixin was incorrect")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ const (
|
||||
vaultCredentialEnvPrefix = "vaultCredentialEnvPrefix"
|
||||
vaultTestCredentialEnvPrefixDefault = "PIPER_TESTCREDENTIAL_"
|
||||
vaultCredentialEnvPrefixDefault = "PIPER_VAULTCREDENTIAL_"
|
||||
vaultSecretName = ".+VaultSecretName$"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -53,6 +54,7 @@ var (
|
||||
vaultCredentialPath,
|
||||
vaultCredentialKeys,
|
||||
vaultCredentialEnvPrefix,
|
||||
vaultSecretName,
|
||||
}
|
||||
|
||||
// VaultRootPaths are the lookup paths piper tries to use during the vault lookup.
|
||||
|
Loading…
Reference in New Issue
Block a user