-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.go
49 lines (40 loc) · 1.06 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
package mfa
import (
"context"
"encoding/json"
"fmt"
"log"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
)
var 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"`
AWSConfig aws.Config `json:"-"`
}
func (e *EnvConfig) InitAWS() {
cfg, err := config.LoadDefaultConfig(
context.Background(),
config.WithRegion(e.AwsDefaultRegion),
config.WithBaseEndpoint(e.AwsEndpoint),
)
if err != nil {
panic("InitAWS failed at LoadDefaultConfig: " + err.Error())
}
e.AWSConfig = cfg
}
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())
}