provider.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. See the License for the specific language governing permissions and
  10. limitations under the License.
  11. */
  12. package v1beta1
  13. import (
  14. "context"
  15. corev1 "k8s.io/api/core/v1"
  16. "sigs.k8s.io/controller-runtime/pkg/client"
  17. "sigs.k8s.io/controller-runtime/pkg/webhook/admission"
  18. esmeta "github.com/external-secrets/external-secrets/apis/meta/v1"
  19. )
  20. const (
  21. // Ready indicates that the client is configured correctly
  22. // and can be used.
  23. ValidationResultReady ValidationResult = iota
  24. // Unknown indicates that the client can be used
  25. // but information is missing and it can not be validated.
  26. ValidationResultUnknown
  27. // Error indicates that there is a misconfiguration.
  28. ValidationResultError
  29. )
  30. type ValidationResult uint8
  31. func (v ValidationResult) String() string {
  32. return [...]string{"Ready", "Unknown", "Error"}[v]
  33. }
  34. // +kubebuilder:object:root=false
  35. // +kubebuilder:object:generate:false
  36. // +k8s:deepcopy-gen:interfaces=nil
  37. // +k8s:deepcopy-gen=nil
  38. // Provider is a common interface for interacting with secret backends.
  39. type Provider interface {
  40. // NewClient based on a provider spec
  41. NewClientFromObj(ctx context.Context, obj client.Object, kube client.Client, namespace string) (SecretsClient, error)
  42. // ApplyReferent gets an object and changes namespace fields according to referent strategy
  43. ApplyReferent(spec client.Object, caller esmeta.ReferentCallOrigin, namespace string) (client.Object, error)
  44. // NewClient constructs a SecretsManager Provider
  45. NewClient(ctx context.Context, store GenericStore, kube client.Client, namespace string) (SecretsClient, error)
  46. Convert(store GenericStore) (client.Object, error)
  47. // ValidateStore checks if the provided store is valid
  48. // The provider may return a warning and an error.
  49. // The intended use of the warning to indicate a deprecation of behavior
  50. // or other type of message that is NOT a validation failure but should be noticed by the user.
  51. ValidateStore(store GenericStore) (admission.Warnings, error)
  52. // Capabilities returns the provider Capabilities (Read, Write, ReadWrite)
  53. Capabilities() SecretStoreCapabilities
  54. }
  55. // +kubebuilder:object:root=false
  56. // +kubebuilder:object:generate:false
  57. // +k8s:deepcopy-gen:interfaces=nil
  58. // +k8s:deepcopy-gen=nil
  59. // SecretsClient provides access to secrets.
  60. type SecretsClient interface {
  61. // GetSecret returns a single secret from the provider
  62. // if GetSecret returns an error with type NoSecretError
  63. // then the secret entry will be deleted depending on the deletionPolicy.
  64. GetSecret(ctx context.Context, ref ExternalSecretDataRemoteRef) ([]byte, error)
  65. // PushSecret will write a single secret into the provider
  66. PushSecret(ctx context.Context, secret *corev1.Secret, data PushSecretData) error
  67. // DeleteSecret will delete the secret from a provider
  68. DeleteSecret(ctx context.Context, remoteRef PushSecretRemoteRef) error
  69. // SecretExists checks if a secret is already present in the provider at the given location.
  70. SecretExists(ctx context.Context, remoteRef PushSecretRemoteRef) (bool, error)
  71. // Validate checks if the client is configured correctly
  72. // and is able to retrieve secrets from the provider.
  73. // If the validation result is unknown it will be ignored.
  74. Validate() (ValidationResult, error)
  75. // GetSecretMap returns multiple k/v pairs from the provider
  76. GetSecretMap(ctx context.Context, ref ExternalSecretDataRemoteRef) (map[string][]byte, error)
  77. // GetAllSecrets returns multiple k/v pairs from the provider
  78. GetAllSecrets(ctx context.Context, ref ExternalSecretFind) (map[string][]byte, error)
  79. Close(ctx context.Context) error
  80. }
  81. var NoSecretErr = NoSecretError{}
  82. // NoSecretError shall be returned when a GetSecret can not find the
  83. // desired secret. This is used for deletionPolicy.
  84. type NoSecretError struct{}
  85. func (NoSecretError) Error() string {
  86. return "Secret does not exist"
  87. }
  88. var NotModifiedErr = NotModifiedError{}
  89. // NotModifiedError to signal that the webhook received no changes,
  90. // and it should just return without doing anything.
  91. type NotModifiedError struct{}
  92. func (NotModifiedError) Error() string {
  93. return "not modified"
  94. }