provider.go 3.4 KB

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