diff options
author | Mike Crute <mike@crute.us> | 2022-12-05 22:34:20 -0800 |
---|---|---|
committer | Mike Crute <mike@crute.us> | 2022-12-05 22:34:20 -0800 |
commit | 187444738dbaa3892366e51aed94b28671c216c2 (patch) | |
tree | ee330e106b9d7b6db2d97f2c562166a4c30eac00 | |
parent | de89b80ce4a9ee754435d340ad4a29c85cd9ea13 (diff) | |
download | golib-187444738dbaa3892366e51aed94b28671c216c2.tar.bz2 golib-187444738dbaa3892366e51aed94b28671c216c2.tar.xz golib-187444738dbaa3892366e51aed94b28671c216c2.zip |
secrets: add noop clientsecrets/v0.2.2
-rw-r--r-- | secrets/noop_client.go | 67 |
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 @@ | |||
1 | package secrets | ||
2 | |||
3 | import ( | ||
4 | "context" | ||
5 | "sync" | ||
6 | ) | ||
7 | |||
8 | type NoopHandle struct{} | ||
9 | |||
10 | func (h *NoopHandle) Reference() string { return "NOOP" } | ||
11 | |||
12 | var _ 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. | ||
17 | type NoopClient struct { | ||
18 | c chan Renewal | ||
19 | } | ||
20 | |||
21 | var _ Client = (*NoopClient)(nil) | ||
22 | var _ ClientManager = (*NoopClient)(nil) | ||
23 | |||
24 | func NewNoopClient() (ClientManager, error) { | ||
25 | return &NoopClient{make(chan Renewal)}, nil | ||
26 | } | ||
27 | |||
28 | func (c *NoopClient) DatabaseCredential(ctx context.Context, path string) (*Credential, Handle, error) { | ||
29 | return &Credential{}, &NoopHandle{}, nil | ||
30 | } | ||
31 | |||
32 | func (c *NoopClient) Secret(ctx context.Context, path string, out any) (Handle, error) { | ||
33 | return &NoopHandle{}, nil | ||
34 | } | ||
35 | |||
36 | func (c *NoopClient) WriteSecret(ctx context.Context, path string, in any) error { | ||
37 | return nil | ||
38 | } | ||
39 | |||
40 | func (c *NoopClient) Destroy(h Handle) error { | ||
41 | return nil | ||
42 | } | ||
43 | |||
44 | func (c *NoopClient) MakeNonCritical(h Handle) error { | ||
45 | return nil | ||
46 | } | ||
47 | |||
48 | func (c *NoopClient) Authenticate(ctx context.Context) error { | ||
49 | return nil | ||
50 | } | ||
51 | |||
52 | func (c *NoopClient) Notifications() <-chan Renewal { | ||
53 | return c.c | ||
54 | } | ||
55 | |||
56 | func (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 | } | ||