provider.go 2.8 KB

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