find_by_name.go 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. esapi "github.com/external-secrets/external-secrets/apis/externalsecrets/v1beta1"
  16. "github.com/external-secrets/external-secrets/e2e/framework"
  17. )
  18. // This case creates multiple secrets with simple key/value pairs
  19. // this is special because parameter store requires a leading "/" in the name.
  20. func FindByName(f *framework.Framework) (string, func(*framework.TestCase)) {
  21. return "[common] should find secrets by name using .DataFrom[]", func(tc *framework.TestCase) {
  22. const namePrefix = "/e2e/find/name/%s/%s"
  23. secretKeyOne := fmt.Sprintf(namePrefix, f.Namespace.Name, "one")
  24. secretKeyTwo := fmt.Sprintf(namePrefix, f.Namespace.Name, "two")
  25. secretKeyThree := fmt.Sprintf(namePrefix, f.Namespace.Name, "three")
  26. secretValue := "{\"foo1\":\"foo1-val\"}"
  27. tc.Secrets = map[string]framework.SecretEntry{
  28. secretKeyOne: {Value: secretValue},
  29. secretKeyTwo: {Value: secretValue},
  30. secretKeyThree: {Value: secretValue},
  31. }
  32. const secNamePrefix = "_e2e_find_name_%s_%s"
  33. tc.ExpectedSecret = &v1.Secret{
  34. Type: v1.SecretTypeOpaque,
  35. Data: map[string][]byte{
  36. fmt.Sprintf(secNamePrefix, f.Namespace.Name, "one"): []byte(secretValue),
  37. fmt.Sprintf(secNamePrefix, f.Namespace.Name, "two"): []byte(secretValue),
  38. fmt.Sprintf(secNamePrefix, f.Namespace.Name, "three"): []byte(secretValue),
  39. },
  40. }
  41. tc.ExternalSecret.Spec.DataFrom = []esapi.ExternalSecretDataFromRemoteRef{
  42. {
  43. Find: &esapi.ExternalSecretFind{
  44. Name: &esapi.FindName{
  45. RegExp: fmt.Sprintf("/e2e/find/name/%s.+", f.Namespace.Name),
  46. },
  47. },
  48. },
  49. }
  50. }
  51. }
  52. // This case creates multiple secrets with simple key/value pairs
  53. // this is special because parameter store requires a leading "/" in the name.
  54. func FindByNameWithPath(f *framework.Framework) (string, func(*framework.TestCase)) {
  55. return "[common] should find secrets by name using .DataFrom[]", func(tc *framework.TestCase) {
  56. secretKeyOne := fmt.Sprintf("/e2e/find/name/%s/one", f.Namespace.Name)
  57. secretKeyTwo := fmt.Sprintf("/%s/two", f.Namespace.Name)
  58. secretKeythree := fmt.Sprintf("/%s/three", f.Namespace.Name)
  59. secretValue := "{\"foo1\":\"foo1-val\"}"
  60. tc.Secrets = map[string]framework.SecretEntry{
  61. secretKeyOne: {Value: secretValue},
  62. secretKeyTwo: {Value: secretValue},
  63. secretKeythree: {Value: secretValue},
  64. }
  65. tc.ExpectedSecret = &v1.Secret{
  66. Type: v1.SecretTypeOpaque,
  67. Data: map[string][]byte{
  68. fmt.Sprintf("_%s_two", f.Namespace.Name): []byte(secretValue),
  69. fmt.Sprintf("_%s_three", f.Namespace.Name): []byte(secretValue),
  70. },
  71. }
  72. pathPrefix := fmt.Sprintf("/%s", f.Namespace.Name)
  73. tc.ExternalSecret.Spec.DataFrom = []esapi.ExternalSecretDataFromRemoteRef{
  74. {
  75. Find: &esapi.ExternalSecretFind{
  76. Path: &pathPrefix,
  77. Name: &esapi.FindName{
  78. RegExp: ".+",
  79. },
  80. },
  81. },
  82. }
  83. }
  84. }