-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat: test workflow sensitive config parameter Signed-off-by: Vladislav Sukhin <vladislav@kubeshop.io> * fix: dep update Signed-off-by: Vladislav Sukhin <vladislav@kubeshop.io> * fix: update mapping Signed-off-by: Vladislav Sukhin <vladislav@kubeshop.io> * fix: add sensitive parameter processing Signed-off-by: Vladislav Sukhin <vladislav@kubeshop.io> * feat: add secret expression machine Signed-off-by: Vladislav Sukhin <vladislav@kubeshop.io> * fix: rename env var Signed-off-by: Vladislav Sukhin <vladislav@kubeshop.io> * fix: remove var Signed-off-by: Vladislav Sukhin <vladislav@kubeshop.io> * fix: use test workflow execution secret Signed-off-by: Vladislav Sukhin <vladislav@kubeshop.io> * fix: change reference Signed-off-by: Vladislav Sukhin <vladislav@kubeshop.io> * fix: use options Signed-off-by: Vladislav Sukhin <vladislav@kubeshop.io> * fix: unit test Signed-off-by: Vladislav Sukhin <vladislav@kubeshop.io> * fix: dep update Signed-off-by: Vladislav Sukhin <vladislav@kubeshop.io> * fix: unit test Signed-off-by: Vladislav Sukhin <vladislav@kubeshop.io> * fix: merge Signed-off-by: Vladislav Sukhin <vladislav@kubeshop.io> * fix: merge Signed-off-by: Vladislav Sukhin <vladislav@kubeshop.io> * chore: test Signed-off-by: Vladislav Sukhin <vladislav@kubeshop.io> * fix: escape secret name Signed-off-by: Vladislav Sukhin <vladislav@kubeshop.io> * remove fix Signed-off-by: Vladislav Sukhin <vladislav@kubeshop.io> * fix: template resolving Signed-off-by: Vladislav Sukhin <vladislav@kubeshop.io> * fix: go fmt Signed-off-by: Vladislav Sukhin <vladislav@kubeshop.io> * fix: go fmt Signed-off-by: Vladislav Sukhin <vladislav@kubeshop.io> * fix: unit test Signed-off-by: Vladislav Sukhin <vladislav@kubeshop.io> * fix: enable unit test Signed-off-by: Vladislav Sukhin <vladislav@kubeshop.io> * fix: unit test Signed-off-by: Vladislav Sukhin <vladislav@kubeshop.io> * fix: template unescaping Signed-off-by: Vladislav Sukhin <vladislav@kubeshop.io> * fix: increase iteration Signed-off-by: Vladislav Sukhin <vladislav@kubeshop.io> * fix: dedup code Signed-off-by: Vladislav Sukhin <vladislav@kubeshop.io> * fix: escape dots Signed-off-by: Vladislav Sukhin <vladislav@kubeshop.io> * fix: dep update Signed-off-by: Vladislav Sukhin <vladislav@kubeshop.io> --------- Signed-off-by: Vladislav Sukhin <vladislav@kubeshop.io>
- Loading branch information
Showing
27 changed files
with
311 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package libs | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
|
||
"github.com/kubeshop/testkube/pkg/expressions" | ||
) | ||
|
||
func NewSecretMachine(mapEnvs map[string]corev1.EnvVarSource) expressions.Machine { | ||
return expressions.NewMachine(). | ||
RegisterFunction("secret", func(values ...expressions.StaticValue) (interface{}, bool, error) { | ||
if len(values) != 2 { | ||
return nil, true, fmt.Errorf(`"secret" function expects 2 arguments, %d provided`, len(values)) | ||
} | ||
|
||
secretName, _ := values[0].StringValue() | ||
keyName, _ := values[1].StringValue() | ||
strs := []string{secretName, keyName} | ||
for i := range strs { | ||
j := 0 | ||
for _, char := range []string{"-", "."} { | ||
for ; strings.Contains(strs[i], char); j++ { | ||
strs[i] = strings.Replace(strs[i], char, fmt.Sprintf("_%d_", j), 1) | ||
} | ||
} | ||
} | ||
|
||
envName := fmt.Sprintf("S_N_%s_K_%s", strs[0], strs[1]) | ||
mapEnvs[envName] = corev1.EnvVarSource{ | ||
SecretKeyRef: &corev1.SecretKeySelector{ | ||
LocalObjectReference: corev1.LocalObjectReference{ | ||
Name: secretName, | ||
}, | ||
Key: keyName, | ||
}, | ||
} | ||
|
||
return expressions.NewValue(fmt.Sprintf("{{%senv.%s}}", expressions.InternalFnCall, envName)), true, nil | ||
}) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package libs | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
corev1 "k8s.io/api/core/v1" | ||
|
||
"github.com/kubeshop/testkube/pkg/expressions" | ||
) | ||
|
||
func TestSecret(t *testing.T) { | ||
mapEnvs := make(map[string]corev1.EnvVarSource) | ||
machine := NewSecretMachine(mapEnvs) | ||
assert.Equal(t, "{{"+expressions.InternalFnCall+"env.S_N_name_0_one_1_two_K_key_0_three_1_four}}", MustCall(machine, "secret", "name-one.two", "key-three.four")) | ||
assert.EqualValues(t, map[string]corev1.EnvVarSource{ | ||
"S_N_name_0_one_1_two_K_key_0_three_1_four": { | ||
SecretKeyRef: &corev1.SecretKeySelector{ | ||
LocalObjectReference: corev1.LocalObjectReference{ | ||
Name: "name-one.two", | ||
}, | ||
Key: "key-three.four", | ||
}, | ||
}, | ||
}, mapEnvs) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.