-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
62 lines (52 loc) · 1014 Bytes
/
config.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"os"
"strings"
"github.com/dwtechnologies/kmsdecrypt"
)
const (
autoEnv = "KMS_AUTO_DECRYPT"
markerEnv = "KMS_MARKER"
defMarker = "KMS_DECRYPT"
regionEnv = "KMS_AWS_REGION"
outputVal = "KMS_OUTPUT"
defOutput = "{KEY}={VAL}{LF}"
)
type decrypter struct {
decrypter *kmsdecrypt.KmsDecrypter
auto *bool
marker *string
output *string
}
func config() (*decrypter, error) {
// Get AWS Region and create kmsdecrypt
r := os.Getenv(regionEnv)
if r == "" {
r = "eu-west-1" // Default to eu-west-1 if no region is specified.
}
decrypt, err := kmsdecrypt.New(r)
if err != nil {
return nil, err
}
// Get KMS Marker
m := os.Getenv(markerEnv)
if m == "" {
m = defMarker
}
// Get AUTO value
a := false
if strings.ToLower(os.Getenv(autoEnv)) == "true" {
a = true
}
// Get Output format
o := os.Getenv(outputVal)
if o == "" {
o = defOutput
}
return &decrypter{
decrypter: decrypt,
auto: &a,
marker: &m,
output: &o,
}, nil
}