provider.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. "sigs.k8s.io/controller-runtime/pkg/client"
  16. )
  17. // +kubebuilder:object:root=false
  18. // +kubebuilder:object:generate:false
  19. // +k8s:deepcopy-gen:interfaces=nil
  20. // +k8s:deepcopy-gen=nil
  21. // Provider is a common interface for interacting with secret backends.
  22. type Provider interface {
  23. // NewClient constructs a SecretsManager Provider
  24. NewClient(ctx context.Context, store GenericStore, kube client.Client, namespace string) (SecretsClient, error)
  25. // ValidateStore checks if the provided store is valid
  26. ValidateStore(store GenericStore) error
  27. }
  28. // +kubebuilder:object:root=false
  29. // +kubebuilder:object:generate:false
  30. // +k8s:deepcopy-gen:interfaces=nil
  31. // +k8s:deepcopy-gen=nil
  32. // SecretsClient provides access to secrets.
  33. type SecretsClient interface {
  34. // GetSecret returns a single secret from the provider
  35. // if GetSecret returns an error with type NoSecretError
  36. // then the secret entry will be deleted depending on the deletionPolicy.
  37. GetSecret(ctx context.Context, ref ExternalSecretDataRemoteRef) ([]byte, error)
  38. // Validate checks if the client is configured correctly
  39. // and is able to retrieve secrets from the provider
  40. Validate() error
  41. // GetSecretMap returns multiple k/v pairs from the provider
  42. GetSecretMap(ctx context.Context, ref ExternalSecretDataRemoteRef) (map[string][]byte, error)
  43. // GetAllSecrets returns multiple k/v pairs from the provider
  44. GetAllSecrets(ctx context.Context, ref ExternalSecretFind) (map[string][]byte, error)
  45. Close(ctx context.Context) error
  46. }
  47. var NoSecretErr = NoSecretError{}
  48. // NoSecretError shall be returned when a GetSecret can not find the
  49. // desired secret. This is used for deletionPolicy.
  50. type NoSecretError struct{}
  51. func (NoSecretError) Error() string {
  52. return "Secret does not exist"
  53. }