diff options
-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 | } | ||