version_secret.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. limitations under the License.
  10. */
  11. package aws
  12. import (
  13. "fmt"
  14. v1 "k8s.io/api/core/v1"
  15. "github.com/external-secrets/external-secrets-e2e/framework"
  16. esapi "github.com/external-secrets/external-secrets/apis/externalsecrets/v1"
  17. )
  18. // This case creates one secret secrets with multiple versions
  19. // the value contains the version number
  20. func VersionedParameter(prov *Provider) func(f *framework.Framework) (string, func(*framework.TestCase)) {
  21. return func(f *framework.Framework) (string, func(*framework.TestCase)) {
  22. return "[common] should read versioned secrets", func(tc *framework.TestCase) {
  23. const namePrefix = "/e2e/versioned/%s/%s"
  24. secretKeyOne := fmt.Sprintf(namePrefix, f.Namespace.Name, "one")
  25. versions := []int{1, 2, 3, 4, 5}
  26. valueStr := "value%d"
  27. tc.ExpectedSecret = &v1.Secret{
  28. Type: v1.SecretTypeOpaque,
  29. Data: map[string][]byte{}, // filled below
  30. }
  31. tc.ExternalSecret.Spec.Data = make([]esapi.ExternalSecretData, len(versions))
  32. // create many versions
  33. i := 0
  34. for _, v := range versions {
  35. secretKey := fmt.Sprintf("v%d", v)
  36. val := fmt.Sprintf(valueStr, v)
  37. prov.CreateSecret(secretKeyOne, framework.SecretEntry{
  38. Value: val,
  39. })
  40. tc.ExpectedSecret.Data[secretKey] = []byte(val)
  41. tc.ExternalSecret.Spec.Data[i] = esapi.ExternalSecretData{
  42. SecretKey: secretKey,
  43. RemoteRef: esapi.ExternalSecretDataRemoteRef{
  44. Key: secretKeyOne,
  45. Version: fmt.Sprintf("%d", v),
  46. },
  47. }
  48. i++
  49. }
  50. }
  51. }
  52. }