provider.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. )
  18. const (
  19. // Ready indicates that the client is configured correctly
  20. // and can be used.
  21. ValidationResultReady ValidationResult = iota
  22. // Unknown indicates that the client can be used
  23. // but information is missing and it can not be validated.
  24. ValidationResultUnknown
  25. // Error indicates that there is a misconfiguration.
  26. ValidationResultError
  27. )
  28. type ValidationResult uint8
  29. func (v ValidationResult) String() string {
  30. return [...]string{"Ready", "Unknown", "Error"}[v]
  31. }
  32. // +kubebuilder:object:root=false
  33. // +kubebuilder:object:generate:false
  34. // +k8s:deepcopy-gen:interfaces=nil
  35. // +k8s:deepcopy-gen=nil
  36. // Provider is a common interface for interacting with secret backends.
  37. type Provider interface {
  38. // NewClient constructs a SecretsManager Provider
  39. NewClient(ctx context.Context, store GenericStore, kube client.Client, namespace string) (SecretsClient, error)
  40. // ValidateStore checks if the provided store is valid
  41. ValidateStore(store GenericStore) error
  42. // Capabilities returns the provider Capabilities (Read, Write, ReadWrite)
  43. Capabilities() SecretStoreCapabilities
  44. }
  45. // +kubebuilder:object:root=false
  46. // +kubebuilder:object:generate:false
  47. // +k8s:deepcopy-gen:interfaces=nil
  48. // +k8s:deepcopy-gen=nil
  49. // SecretsClient provides access to secrets.
  50. type SecretsClient interface {
  51. // GetSecret returns a single secret from the provider
  52. // if GetSecret returns an error with type NoSecretError
  53. // then the secret entry will be deleted depending on the deletionPolicy.
  54. GetSecret(ctx context.Context, ref ExternalSecretDataRemoteRef) ([]byte, error)
  55. // PushSecret will write a single secret into the provider
  56. PushSecret(ctx context.Context, secret *corev1.Secret, data PushSecretData) error
  57. // DeleteSecret will delete the secret from a provider
  58. DeleteSecret(ctx context.Context, remoteRef PushSecretRemoteRef) error
  59. // Validate checks if the client is configured correctly
  60. // and is able to retrieve secrets from the provider.
  61. // If the validation result is unknown it will be ignored.
  62. Validate() (ValidationResult, error)
  63. // GetSecretMap returns multiple k/v pairs from the provider
  64. GetSecretMap(ctx context.Context, ref ExternalSecretDataRemoteRef) (map[string][]byte, error)
  65. // GetAllSecrets returns multiple k/v pairs from the provider
  66. GetAllSecrets(ctx context.Context, ref ExternalSecretFind) (map[string][]byte, error)
  67. Close(ctx context.Context) error
  68. }
  69. var NoSecretErr = NoSecretError{}
  70. // NoSecretError shall be returned when a GetSecret can not find the
  71. // desired secret. This is used for deletionPolicy.
  72. type NoSecretError struct{}
  73. func (NoSecretError) Error() string {
  74. return "Secret does not exist"
  75. }