1
0
Fork 0
mirror of https://github.com/external-secrets/external-secrets.git synced 2024-12-14 11:57:59 +00:00

Enable the New() method on the Prodiver interface to receive a GenericStore instead of a SecretStoreProvider)

This commit is contained in:
Jonatas Baldin 2021-01-07 11:51:16 +01:00
parent 87ed4ed118
commit 8ee64d918e
5 changed files with 8 additions and 10 deletions

View file

@ -79,9 +79,7 @@ func (r *ExternalSecretReconciler) Reconcile(req ctrl.Request) (ctrl.Result, err
return fmt.Errorf("could not get store provider: %w", err) return fmt.Errorf("could not get store provider: %w", err)
} }
// TODO: Does the * work? providerClient, err := storeProvider.New(ctx, store, r.Client, req.Namespace)
// If not, should I change the Provider interface?
providerClient, err := storeProvider.New(ctx, *store.GetProvider(), r.Client, req.Namespace)
if err != nil { if err != nil {
return fmt.Errorf("could not get provider client: %w", err) return fmt.Errorf("could not get provider client: %w", err)
} }

View file

@ -27,7 +27,7 @@ import (
type SecretsManager struct{} type SecretsManager struct{}
// New constructs a SecretsManager Provider. // New constructs a SecretsManager Provider.
func (sm *SecretsManager) New(ctx context.Context, store esv1alpha1.SecretStoreProvider, kube client.Client, namespace string) (provider.Provider, error) { func (sm *SecretsManager) New(ctx context.Context, store esv1alpha1.GenericStore, kube client.Client, namespace string) (provider.Provider, error) {
return sm, nil // stub return sm, nil // stub
} }

View file

@ -28,7 +28,7 @@ var _ provider.Provider = &Client{}
// Client is a fake client for testing. // Client is a fake client for testing.
type Client struct { type Client struct {
NewFn func(context.Context, esv1alpha1.SecretStoreProvider, client.Client, NewFn func(context.Context, esv1alpha1.GenericStore, client.Client,
string) (provider.Provider, error) string) (provider.Provider, error)
GetSecretFn func(context.Context, esv1alpha1.ExternalSecretDataRemoteRef) ([]byte, error) GetSecretFn func(context.Context, esv1alpha1.ExternalSecretDataRemoteRef) ([]byte, error)
GetSecretMapFn func(context.Context, esv1alpha1.ExternalSecretDataRemoteRef) (map[string][]byte, error) GetSecretMapFn func(context.Context, esv1alpha1.ExternalSecretDataRemoteRef) (map[string][]byte, error)
@ -45,7 +45,7 @@ func New() *Client {
}, },
} }
v.NewFn = func(context.Context, esv1alpha1.SecretStoreProvider, client.Client, string) (provider.Provider, error) { v.NewFn = func(context.Context, esv1alpha1.GenericStore, client.Client, string) (provider.Provider, error) {
return nil, nil return nil, nil
} }
@ -84,14 +84,14 @@ func (v *Client) WithGetSecretMap(secData map[string][]byte, err error) *Client
} }
// WithNew wraps the fake provider factory function. // WithNew wraps the fake provider factory function.
func (v *Client) WithNew(f func(context.Context, esv1alpha1.SecretStoreProvider, client.Client, func (v *Client) WithNew(f func(context.Context, esv1alpha1.GenericStore, client.Client,
string) (provider.Provider, error)) *Client { string) (provider.Provider, error)) *Client {
v.NewFn = f v.NewFn = f
return v return v
} }
// New returns a new fake provider. // New returns a new fake provider.
func (v *Client) New(ctx context.Context, store esv1alpha1.SecretStoreProvider, kube client.Client, namespace string) (provider.Provider, error) { func (v *Client) New(ctx context.Context, store esv1alpha1.GenericStore, kube client.Client, namespace string) (provider.Provider, error) {
client, err := v.NewFn(ctx, store, kube, namespace) client, err := v.NewFn(ctx, store, kube, namespace)
if err != nil { if err != nil {
return nil, err return nil, err

View file

@ -25,7 +25,7 @@ import (
// Provider is a common interface for interacting with secret backends. // Provider is a common interface for interacting with secret backends.
type Provider interface { type Provider interface {
// New constructs a SecretsManager Provider // New constructs a SecretsManager Provider
New(ctx context.Context, store esv1alpha1.SecretStoreProvider, kube client.Client, namespace string) (Provider, error) New(ctx context.Context, store esv1alpha1.GenericStore, kube client.Client, namespace string) (Provider, error)
// GetSecret returns a single secret from the provider // GetSecret returns a single secret from the provider
GetSecret(ctx context.Context, ref esv1alpha1.ExternalSecretDataRemoteRef) ([]byte, error) GetSecret(ctx context.Context, ref esv1alpha1.ExternalSecretDataRemoteRef) ([]byte, error)

View file

@ -27,7 +27,7 @@ import (
type PP struct{} type PP struct{}
// New constructs a SecretsManager Provider. // New constructs a SecretsManager Provider.
func (p *PP) New(ctx context.Context, store esv1alpha1.SecretStoreProvider, kube client.Client, namespace string) (provider.Provider, error) { func (p *PP) New(ctx context.Context, store esv1alpha1.GenericStore, kube client.Client, namespace string) (provider.Provider, error) {
return p, nil return p, nil
} }