provider.go 2.6 KB

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