provider.go 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 configured 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. // Capabilities returns the provider Capabilities (Read, Write, ReadWrite)
  42. Capabilities() SecretStoreCapabilities
  43. }
  44. // +kubebuilder:object:root=false
  45. // +kubebuilder:object:generate:false
  46. // +k8s:deepcopy-gen:interfaces=nil
  47. // +k8s:deepcopy-gen=nil
  48. // SecretsClient provides access to secrets.
  49. type SecretsClient interface {
  50. // GetSecret returns a single secret from the provider
  51. // if GetSecret returns an error with type NoSecretError
  52. // then the secret entry will be deleted depending on the deletionPolicy.
  53. GetSecret(ctx context.Context, ref ExternalSecretDataRemoteRef) ([]byte, error)
  54. // PushSecret will write a single secret into the provider
  55. PushSecret(ctx context.Context, value []byte, remoteRef PushRemoteRef) error
  56. // DeleteSecret will delete the secret from a provider
  57. DeleteSecret(ctx context.Context, remoteRef PushRemoteRef) error
  58. // Validate checks if the client is configured correctly
  59. // and is able to retrieve secrets from the provider.
  60. // If the validation result is unknown it will be ignored.
  61. Validate() (ValidationResult, error)
  62. // GetSecretMap returns multiple k/v pairs from the provider
  63. GetSecretMap(ctx context.Context, ref ExternalSecretDataRemoteRef) (map[string][]byte, error)
  64. // GetAllSecrets returns multiple k/v pairs from the provider
  65. GetAllSecrets(ctx context.Context, ref ExternalSecretFind) (map[string][]byte, error)
  66. Close(ctx context.Context) error
  67. }
  68. var NoSecretErr = NoSecretError{}
  69. // NoSecretError shall be returned when a GetSecret can not find the
  70. // desired secret. This is used for deletionPolicy.
  71. type NoSecretError struct{}
  72. func (NoSecretError) Error() string {
  73. return "Secret does not exist"
  74. }