Debian Codegraph @

runtimevar/awssecretsmanager/example_test.go

raw
1 // Copyright 2020 The Go Cloud Development Kit Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package awssecretsmanager_test
16
17 import (
18 "context"
19 "log"
20
21 "github.com/aws/aws-sdk-go-v2/config"
22 "github.com/aws/aws-sdk-go-v2/service/secretsmanager"
23 "gocloud.dev/runtimevar"
24 "gocloud.dev/runtimevar/awssecretsmanager"
25 )
26
27 func ExampleOpenVariable() {
28 // PRAGMA: This example is used on gocloud.dev; PRAGMA comments adjust how it is shown and can be ignored.
29
30 // Establish a AWS V2 Config.
31 // See https://aws.github.io/aws-sdk-go-v2/docs/configuring-sdk/ for more info.
32 ctx := context.Background()
33 cfg, err := config.LoadDefaultConfig(ctx)
34 if err != nil {
35 log.Fatal(err)
36 }
37
38 // Construct a *runtimevar.Variable that watches the variable.
39 // `secret-variable-name` must be a friendly name of the secret, NOT the Amazon Resource Name (ARN).
40 client := secretsmanager.NewFromConfig(cfg)
41 v, err := awssecretsmanager.OpenVariable(client, "secret-variable-name", runtimevar.StringDecoder, nil)
42 if err != nil {
43 log.Fatal(err)
44 }
45 defer v.Close()
46 }
47
48 func Example_openVariableFromURL() {
49 // PRAGMA: This example is used on gocloud.dev; PRAGMA comments adjust how it is shown and can be ignored.
50 // PRAGMA: On gocloud.dev, add a blank import: _ "gocloud.dev/runtimevar/awssecretsmanager"
51 // PRAGMA: On gocloud.dev, hide lines until the next blank line.
52 ctx := context.Background()
53
54 // runtimevar.OpenVariable creates a *runtimevar.Variable from a URL.
55 // `secret-variable-name` must be a friendly name of the secret, NOT the Amazon Resource Name (ARN).
56 v, err := runtimevar.OpenVariable(ctx, "awssecretsmanager://secret-variable-name?region=us-east-2&decoder=string")
57 if err != nil {
58 log.Fatal(err)
59 }
60 defer v.Close()
61 }