diff options
author | Mike Crute <mike@crute.us> | 2022-11-27 22:01:27 -0800 |
---|---|---|
committer | Mike Crute <mike@crute.us> | 2022-11-27 22:01:27 -0800 |
commit | 07034d66f08a0e205868c8ff09f4360dbd758854 (patch) | |
tree | 7fd1e41feccf1451b2531418a0f4d242e7b2a042 | |
parent | 111c9fe48f216d023530952df44559304bc9f2e7 (diff) | |
download | golib-07034d66f08a0e205868c8ff09f4360dbd758854.tar.bz2 golib-07034d66f08a0e205868c8ff09f4360dbd758854.tar.xz golib-07034d66f08a0e205868c8ff09f4360dbd758854.zip |
secrets: add convenience methodssecrets/v0.2.0
-rw-r--r-- | secrets/convenience.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/secrets/convenience.go b/secrets/convenience.go new file mode 100644 index 0000000..058ffc1 --- /dev/null +++ b/secrets/convenience.go | |||
@@ -0,0 +1,27 @@ | |||
1 | package secrets | ||
2 | |||
3 | // This file contains convenience functions for working with a secrets | ||
4 | // client. These will be mostly only useful in the main method of | ||
5 | // a program because most of them are designed to terminate the | ||
6 | // application with a log message or panic. | ||
7 | |||
8 | import ( | ||
9 | "context" | ||
10 | "log" | ||
11 | ) | ||
12 | |||
13 | func MustGetApiKey(c Client, ctx context.Context, path string) *ApiKey { | ||
14 | key := &ApiKey{} | ||
15 | if _, err := c.Secret(ctx, path, key); err != nil { | ||
16 | log.Fatalf("Error fetching API key secret %s: %s", path, err) | ||
17 | } | ||
18 | return key | ||
19 | } | ||
20 | |||
21 | func MustGetCredential(c Client, ctx context.Context, path string) *Credential { | ||
22 | cred := &Credential{} | ||
23 | if _, err := c.Secret(ctx, path, cred); err != nil { | ||
24 | log.Fatalf("Error fetching credential secret %s: %s", path, err) | ||
25 | } | ||
26 | return cred | ||
27 | } | ||