aboutsummaryrefslogtreecommitdiff
path: root/secrets
diff options
context:
space:
mode:
authorMike Crute <mike@crute.us>2022-12-05 22:34:20 -0800
committerMike Crute <mike@crute.us>2022-12-05 22:34:20 -0800
commit187444738dbaa3892366e51aed94b28671c216c2 (patch)
treeee330e106b9d7b6db2d97f2c562166a4c30eac00 /secrets
parentde89b80ce4a9ee754435d340ad4a29c85cd9ea13 (diff)
downloadgolib-187444738dbaa3892366e51aed94b28671c216c2.tar.bz2
golib-187444738dbaa3892366e51aed94b28671c216c2.tar.xz
golib-187444738dbaa3892366e51aed94b28671c216c2.zip
secrets: add noop clientsecrets/v0.2.2
Diffstat (limited to 'secrets')
-rw-r--r--secrets/noop_client.go67
1 files changed, 67 insertions, 0 deletions
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 @@
1package secrets
2
3import (
4 "context"
5 "sync"
6)
7
8type NoopHandle struct{}
9
10func (h *NoopHandle) Reference() string { return "NOOP" }
11
12var _ Handle = (*NoopHandle)(nil)
13
14// NoopClient does nothing and will never fail. It returns empty but
15// non-nil credentials and handles where needed. This is useful for when
16// code paths expect a secret client but using one is not needed.
17type NoopClient struct {
18 c chan Renewal
19}
20
21var _ Client = (*NoopClient)(nil)
22var _ ClientManager = (*NoopClient)(nil)
23
24func NewNoopClient() (ClientManager, error) {
25 return &NoopClient{make(chan Renewal)}, nil
26}
27
28func (c *NoopClient) DatabaseCredential(ctx context.Context, path string) (*Credential, Handle, error) {
29 return &Credential{}, &NoopHandle{}, nil
30}
31
32func (c *NoopClient) Secret(ctx context.Context, path string, out any) (Handle, error) {
33 return &NoopHandle{}, nil
34}
35
36func (c *NoopClient) WriteSecret(ctx context.Context, path string, in any) error {
37 return nil
38}
39
40func (c *NoopClient) Destroy(h Handle) error {
41 return nil
42}
43
44func (c *NoopClient) MakeNonCritical(h Handle) error {
45 return nil
46}
47
48func (c *NoopClient) Authenticate(ctx context.Context) error {
49 return nil
50}
51
52func (c *NoopClient) Notifications() <-chan Renewal {
53 return c.c
54}
55
56func (c *NoopClient) Run(ctx context.Context, wg *sync.WaitGroup) error {
57 wg.Add(1)
58 defer wg.Done()
59
60 for {
61 select {
62 case <-ctx.Done():
63 close(c.c)
64 return nil
65 }
66 }
67}