-
Notifications
You must be signed in to change notification settings - Fork 6
/
query.go
45 lines (36 loc) · 957 Bytes
/
query.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package secretsmanager
import (
"context"
"encoding/json"
"fmt"
"os"
secretsmanager_v2 "github.com/aws/aws-sdk-go-v2/service/secretsmanager"
)
const (
DATABASE_CREDENTIALS = "database_credentials"
AUTH_PRIVATE_KEY = "auth_private_key"
AUTH_PUBLIC_KEY = "auth_public_key"
)
func (s *SecretsManagerClient) GetSecretValue(id string, key string) (*string, error) {
envValue, exists := os.LookupEnv(key)
if exists {
return &envValue, nil
}
input := &secretsmanager_v2.GetSecretValueInput{
SecretId: &id,
}
result, err := s.Client.GetSecretValue(context.Background(), input)
if err != nil {
return nil, err
}
var data map[string]string
err = json.Unmarshal([]byte(*result.SecretString), &data)
if err != nil {
return nil, fmt.Errorf("error unmarshal secrets manager data %s", id)
}
value, ok := data[key]
if !ok {
return nil, fmt.Errorf("key %s not found in secrets manager %s", key, id)
}
return &value, nil
}