-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
53 lines (42 loc) · 1.09 KB
/
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
package mfa
import (
"encoding/json"
"fmt"
"log"
"github.com/aws/aws-sdk-go/aws"
)
var (
storage *Storage
envConfig EnvConfig
)
// EnvConfig holds environment specific configurations and is populated on init
type EnvConfig struct {
ApiKeyTable string `required:"true" split_words:"true"`
WebauthnTable string `required:"true" split_words:"true"`
AwsEndpoint string `default:"" split_words:"true"`
AwsDefaultRegion string `default:"" split_words:"true"`
AwsDisableSSL bool `default:"false" split_words:"true"`
AWSConfig *aws.Config `json:"-"`
}
func (e *EnvConfig) InitAWS() {
e.AWSConfig = &aws.Config{
DisableSSL: aws.Bool(e.AwsDisableSSL),
}
if e.AwsEndpoint != "" {
e.AWSConfig.Endpoint = aws.String(e.AwsEndpoint)
}
if e.AwsDefaultRegion != "" {
e.AWSConfig.Region = aws.String(e.AwsDefaultRegion)
}
}
func (e *EnvConfig) String() string {
b, err := json.Marshal(e)
if err != nil {
return fmt.Sprintf("error stringifying envConfig: %s", err)
}
return string(b)
}
func SetConfig(c EnvConfig) {
envConfig = c
log.Println("config:", envConfig.String())
}