vault.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 vault
  12. import (
  13. // nolint
  14. . "github.com/onsi/ginkgo"
  15. // nolint
  16. . "github.com/onsi/ginkgo/extensions/table"
  17. "github.com/external-secrets/external-secrets/e2e/framework"
  18. "github.com/external-secrets/external-secrets/e2e/suite/common"
  19. )
  20. const (
  21. withTokenAuth = "with token auth"
  22. withCertAuth = "with cert auth"
  23. withApprole = "with approle auth"
  24. withV1 = "with v1 provider"
  25. withJWT = "with jwt provider"
  26. withK8s = "with kubernetes provider"
  27. )
  28. var _ = Describe("[vault] ", func() {
  29. f := framework.New("eso-vault")
  30. DescribeTable("sync secrets",
  31. framework.TableFunc(f,
  32. newVaultProvider(f)),
  33. // uses token auth
  34. compose(withTokenAuth, f, common.JSONDataFromSync, useTokenAuth),
  35. compose(withTokenAuth, f, common.JSONDataWithProperty, useTokenAuth),
  36. compose(withTokenAuth, f, common.JSONDataWithTemplate, useTokenAuth),
  37. compose(withTokenAuth, f, common.DataPropertyDockerconfigJSON, useTokenAuth),
  38. compose(withTokenAuth, f, common.JSONDataWithoutTargetName, useTokenAuth),
  39. // use cert auth
  40. compose(withCertAuth, f, common.JSONDataFromSync, useCertAuth),
  41. compose(withCertAuth, f, common.JSONDataWithProperty, useCertAuth),
  42. compose(withCertAuth, f, common.JSONDataWithTemplate, useCertAuth),
  43. compose(withCertAuth, f, common.DataPropertyDockerconfigJSON, useCertAuth),
  44. compose(withCertAuth, f, common.JSONDataWithoutTargetName, useTokenAuth),
  45. // use approle auth
  46. compose(withApprole, f, common.JSONDataFromSync, useApproleAuth),
  47. compose(withApprole, f, common.JSONDataWithProperty, useApproleAuth),
  48. compose(withApprole, f, common.JSONDataWithTemplate, useApproleAuth),
  49. compose(withApprole, f, common.DataPropertyDockerconfigJSON, useApproleAuth),
  50. compose(withApprole, f, common.JSONDataWithoutTargetName, useTokenAuth),
  51. // use v1 provider
  52. compose(withV1, f, common.JSONDataFromSync, useV1Provider),
  53. compose(withV1, f, common.JSONDataWithProperty, useV1Provider),
  54. compose(withV1, f, common.JSONDataWithTemplate, useV1Provider),
  55. compose(withV1, f, common.DataPropertyDockerconfigJSON, useV1Provider),
  56. compose(withV1, f, common.JSONDataWithoutTargetName, useTokenAuth),
  57. // use jwt provider
  58. compose(withJWT, f, common.JSONDataFromSync, useJWTProvider),
  59. compose(withJWT, f, common.JSONDataWithProperty, useJWTProvider),
  60. compose(withJWT, f, common.JSONDataWithTemplate, useJWTProvider),
  61. compose(withJWT, f, common.DataPropertyDockerconfigJSON, useJWTProvider),
  62. compose(withJWT, f, common.JSONDataWithoutTargetName, useTokenAuth),
  63. // use kubernetes provider
  64. compose(withK8s, f, common.JSONDataFromSync, useKubernetesProvider),
  65. compose(withK8s, f, common.JSONDataWithProperty, useKubernetesProvider),
  66. compose(withK8s, f, common.JSONDataWithTemplate, useKubernetesProvider),
  67. compose(withK8s, f, common.DataPropertyDockerconfigJSON, useKubernetesProvider),
  68. compose(withK8s, f, common.JSONDataWithoutTargetName, useTokenAuth),
  69. )
  70. })
  71. func compose(descAppend string, f *framework.Framework, fn func(f *framework.Framework) (string, func(*framework.TestCase)), tweaks ...func(*framework.TestCase)) TableEntry {
  72. desc, tfn := fn(f)
  73. tweaks = append(tweaks, tfn)
  74. te := Entry(desc + " " + descAppend)
  75. // need to convert []func to []interface{}
  76. ifs := make([]interface{}, len(tweaks))
  77. for i := 0; i < len(tweaks); i++ {
  78. ifs[i] = tweaks[i]
  79. }
  80. te.Parameters = ifs
  81. return te
  82. }
  83. func useTokenAuth(tc *framework.TestCase) {
  84. tc.ExternalSecret.Spec.SecretStoreRef.Name = tc.Framework.Namespace.Name
  85. }
  86. func useCertAuth(tc *framework.TestCase) {
  87. tc.ExternalSecret.Spec.SecretStoreRef.Name = certAuthProviderName
  88. }
  89. func useApproleAuth(tc *framework.TestCase) {
  90. tc.ExternalSecret.Spec.SecretStoreRef.Name = appRoleAuthProviderName
  91. }
  92. func useV1Provider(tc *framework.TestCase) {
  93. tc.ExternalSecret.Spec.SecretStoreRef.Name = kvv1ProviderName
  94. }
  95. func useJWTProvider(tc *framework.TestCase) {
  96. tc.ExternalSecret.Spec.SecretStoreRef.Name = jwtProviderName
  97. }
  98. func useKubernetesProvider(tc *framework.TestCase) {
  99. tc.ExternalSecret.Spec.SecretStoreRef.Name = kubernetesProviderName
  100. }