provider_v2.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. Copyright © The ESO Authors
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. https://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package aws
  14. import (
  15. "fmt"
  16. "time"
  17. . "github.com/onsi/ginkgo/v2"
  18. corev1 "k8s.io/api/core/v1"
  19. "github.com/external-secrets/external-secrets-e2e/framework"
  20. "github.com/external-secrets/external-secrets-e2e/suites/provider/cases/common"
  21. esapi "github.com/external-secrets/external-secrets/apis/externalsecrets/v1"
  22. )
  23. var _ = Describe("[aws] v2 namespaced provider", Label("aws", "parameterstore", "v2", "namespaced-provider"), func() {
  24. f := framework.New("eso-aws-ps-v2")
  25. prov := NewProviderV2(f)
  26. BeforeEach(func() {
  27. if !framework.IsV2ProviderMode() {
  28. Skip("v2 mode only")
  29. }
  30. })
  31. DescribeTable("namespaced provider",
  32. framework.TableFuncWithExternalSecret(f, prov),
  33. framework.Compose(withStaticAuth, f, func(_ *framework.Framework) (string, func(*framework.TestCase)) {
  34. return common.NamespacedProviderSync(f, common.NamespacedProviderSyncConfig{
  35. Description: "[aws] should sync an ExternalSecret through a namespaced ParameterStore Provider using static credentials",
  36. ExternalSecretName: "aws-v2-ps-static-es",
  37. TargetSecretName: "aws-v2-ps-static-target",
  38. RemoteKey: f.MakeRemoteRefKey("aws-v2-ps-static-remote"),
  39. RemoteSecretValue: "aws-v2-ps-static-value",
  40. SecretKey: "value",
  41. ExpectedValue: "aws-v2-ps-static-value",
  42. })
  43. }, useV2StaticAuth(prov)),
  44. framework.Compose(withStaticAuth, f, func(_ *framework.Framework) (string, func(*framework.TestCase)) {
  45. return common.NamespacedProviderRefresh(f, common.NamespacedProviderRefreshConfig{
  46. Description: "[aws] should refresh synced ParameterStore secrets after the remote parameter changes",
  47. ExternalSecretName: "aws-v2-ps-refresh-es",
  48. TargetSecretName: "aws-v2-ps-refresh-target",
  49. RemoteKey: f.MakeRemoteRefKey("aws-v2-ps-refresh-remote"),
  50. InitialSecretValue: "aws-v2-ps-initial",
  51. UpdatedSecretValue: "aws-v2-ps-updated",
  52. SecretKey: "value",
  53. InitialExpectedData: "aws-v2-ps-initial",
  54. UpdatedExpectedData: "aws-v2-ps-updated",
  55. RefreshInterval: 10 * time.Second,
  56. WaitTimeout: 30 * time.Second,
  57. })
  58. }, useV2StaticAuth(prov)),
  59. framework.Compose(withStaticAuth, f, FindByName, useV2StaticAuth(prov)),
  60. framework.Compose(withStaticAuth, f, FindByTag, useV2StaticAuth(prov)),
  61. framework.Compose(withStaticAuth, f, versionedParameterV2(prov), useV2StaticAuth(prov)),
  62. framework.Compose(withStaticAuth, f, common.StatusNotUpdatedAfterSuccessfulSync, useV2StaticAuth(prov)),
  63. )
  64. })
  65. func versionedParameterV2(prov framework.SecretStoreProvider) func(*framework.Framework) (string, func(*framework.TestCase)) {
  66. return func(f *framework.Framework) (string, func(*framework.TestCase)) {
  67. return "[common] should read versioned secrets", func(tc *framework.TestCase) {
  68. secretKey := fmt.Sprintf("/e2e/versioned/%s/%s", f.Namespace.Name, "one")
  69. versions := []int{1, 2, 3, 4, 5}
  70. tc.ExpectedSecret = commonVersionedExpectedSecret(versions)
  71. tc.ExternalSecret.Spec.Data = commonVersionedExternalSecretData(secretKey, versions)
  72. tc.Cleanup = func() {
  73. prov.DeleteSecret(secretKey)
  74. }
  75. for _, version := range versions {
  76. prov.CreateSecret(secretKey, framework.SecretEntry{
  77. Value: fmt.Sprintf("value%d", version),
  78. })
  79. }
  80. }
  81. }
  82. }
  83. func commonVersionedExpectedSecret(versions []int) *corev1.Secret {
  84. data := make(map[string][]byte, len(versions))
  85. for _, version := range versions {
  86. data[fmt.Sprintf("v%d", version)] = []byte(fmt.Sprintf("value%d", version))
  87. }
  88. return &corev1.Secret{
  89. Type: corev1.SecretTypeOpaque,
  90. Data: data,
  91. }
  92. }
  93. func commonVersionedExternalSecretData(secretKey string, versions []int) []esapi.ExternalSecretData {
  94. data := make([]esapi.ExternalSecretData, 0, len(versions))
  95. for _, version := range versions {
  96. data = append(data, esapi.ExternalSecretData{
  97. SecretKey: fmt.Sprintf("v%d", version),
  98. RemoteRef: esapi.ExternalSecretDataRemoteRef{
  99. Key: secretKey,
  100. Version: fmt.Sprintf("%d", version),
  101. },
  102. })
  103. }
  104. return data
  105. }