scaleway.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. Copyright © 2025 ESO Maintainer Team
  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 scaleway
  14. import (
  15. "context"
  16. "sync"
  17. "github.com/external-secrets/external-secrets-e2e/framework"
  18. "github.com/external-secrets/external-secrets-e2e/suites/provider/cases/common"
  19. esv1 "github.com/external-secrets/external-secrets/apis/externalsecrets/v1"
  20. esmeta "github.com/external-secrets/external-secrets/apis/meta/v1"
  21. . "github.com/onsi/ginkgo/v2"
  22. . "github.com/onsi/gomega"
  23. v1 "k8s.io/api/core/v1"
  24. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  25. )
  26. var cleanupOnce sync.Once
  27. var _ = Describe("[scaleway]", Label("scaleway"), func() {
  28. f := framework.New("eso-scaleway")
  29. f.MakeRemoteRefKey = func(base string) string {
  30. return "name:" + base
  31. }
  32. // Initialization is deferred so that assertions work.
  33. provider := &secretStoreProvider{}
  34. BeforeEach(func() {
  35. cfg, err := loadConfigFromEnv()
  36. Expect(err).ToNot(HaveOccurred())
  37. provider.init(cfg)
  38. cleanupOnce.Do(provider.cleanup)
  39. createResources(GinkgoT().Context(), f, cfg)
  40. })
  41. DescribeTable("sync secrets", framework.TableFuncWithExternalSecret(f, provider),
  42. //Entry(common.SyncV1Alpha1(f)), // not supported
  43. Entry(common.SimpleDataSync(f)),
  44. Entry(common.SyncWithoutTargetName(f)),
  45. Entry(common.JSONDataWithProperty(f)),
  46. Entry(common.JSONDataWithoutTargetName(f)),
  47. Entry(common.JSONDataWithTemplate(f)),
  48. Entry(common.JSONDataWithTemplateFromLiteral(f)),
  49. Entry(common.TemplateFromConfigmaps(f)),
  50. Entry(common.JSONDataFromSync(f)),
  51. Entry(common.JSONDataFromRewrite(f)),
  52. Entry(common.NestedJSONWithGJSON(f)),
  53. Entry(common.DockerJSONConfig(f)),
  54. Entry(common.DataPropertyDockerconfigJSON(f)),
  55. Entry(common.SSHKeySync(f)),
  56. Entry(common.SSHKeySyncDataProperty(f)),
  57. Entry(common.DeletionPolicyDelete(f)),
  58. //Entry(common.DecodingPolicySync(f)), // not supported
  59. Entry(common.FindByName(f)),
  60. Entry(common.FindByNameAndRewrite(f)),
  61. //Entry(common.FindByNameWithPath(f)), // not supported
  62. Entry(common.FindByTag(f)),
  63. //Entry(common.FindByTagWithPath(f)), // not supported
  64. )
  65. })
  66. func createResources(ctx context.Context, f *framework.Framework, cfg *config) {
  67. apiKeySecretName := "scw-api-key"
  68. apiKeySecretKey := "secret-key"
  69. // Creating a secret to hold the API key.
  70. secretSpec := v1.Secret{
  71. ObjectMeta: metav1.ObjectMeta{
  72. Name: apiKeySecretName,
  73. Namespace: f.Namespace.Name,
  74. },
  75. StringData: map[string]string{
  76. "secret-key": cfg.secretKey,
  77. },
  78. }
  79. err := f.CRClient.Create(ctx, &secretSpec)
  80. Expect(err).ToNot(HaveOccurred())
  81. // Creating SecretStore.
  82. secretStoreSpec := esv1.SecretStore{
  83. ObjectMeta: metav1.ObjectMeta{
  84. Name: f.Namespace.Name,
  85. Namespace: f.Namespace.Name,
  86. },
  87. Spec: esv1.SecretStoreSpec{
  88. Provider: &esv1.SecretStoreProvider{
  89. Scaleway: &esv1.ScalewayProvider{
  90. Region: cfg.region,
  91. ProjectID: cfg.projectId,
  92. AccessKey: &esv1.ScalewayProviderSecretRef{
  93. Value: cfg.accessKey, // TODO: test with secretRef as well
  94. },
  95. SecretKey: &esv1.ScalewayProviderSecretRef{
  96. SecretRef: &esmeta.SecretKeySelector{
  97. Name: apiKeySecretName,
  98. Key: apiKeySecretKey,
  99. },
  100. },
  101. },
  102. },
  103. },
  104. }
  105. if cfg.apiUrl != nil {
  106. secretStoreSpec.Spec.Provider.Scaleway.APIURL = *cfg.apiUrl
  107. }
  108. err = f.CRClient.Create(ctx, &secretStoreSpec)
  109. Expect(err).ToNot(HaveOccurred())
  110. }