From 187444738dbaa3892366e51aed94b28671c216c2 Mon Sep 17 00:00:00 2001 From: Mike Crute Date: Mon, 5 Dec 2022 22:34:20 -0800 Subject: secrets: add noop client --- secrets/noop_client.go | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 secrets/noop_client.go (limited to 'secrets') diff --git a/secrets/noop_client.go b/secrets/noop_client.go new file mode 100644 index 0000000..85bd736 --- /dev/null +++ b/secrets/noop_client.go @@ -0,0 +1,67 @@ +package secrets + +import ( + "context" + "sync" +) + +type NoopHandle struct{} + +func (h *NoopHandle) Reference() string { return "NOOP" } + +var _ Handle = (*NoopHandle)(nil) + +// NoopClient does nothing and will never fail. It returns empty but +// non-nil credentials and handles where needed. This is useful for when +// code paths expect a secret client but using one is not needed. +type NoopClient struct { + c chan Renewal +} + +var _ Client = (*NoopClient)(nil) +var _ ClientManager = (*NoopClient)(nil) + +func NewNoopClient() (ClientManager, error) { + return &NoopClient{make(chan Renewal)}, nil +} + +func (c *NoopClient) DatabaseCredential(ctx context.Context, path string) (*Credential, Handle, error) { + return &Credential{}, &NoopHandle{}, nil +} + +func (c *NoopClient) Secret(ctx context.Context, path string, out any) (Handle, error) { + return &NoopHandle{}, nil +} + +func (c *NoopClient) WriteSecret(ctx context.Context, path string, in any) error { + return nil +} + +func (c *NoopClient) Destroy(h Handle) error { + return nil +} + +func (c *NoopClient) MakeNonCritical(h Handle) error { + return nil +} + +func (c *NoopClient) Authenticate(ctx context.Context) error { + return nil +} + +func (c *NoopClient) Notifications() <-chan Renewal { + return c.c +} + +func (c *NoopClient) Run(ctx context.Context, wg *sync.WaitGroup) error { + wg.Add(1) + defer wg.Done() + + for { + select { + case <-ctx.Done(): + close(c.c) + return nil + } + } +} -- cgit v1.2.3