forked from blockpane/ephemera
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.go
54 lines (48 loc) · 1.46 KB
/
init.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
package sharedpw
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/kms"
"log"
"os"
)
var (
Region string
AwsSession *session.Session
KMS *kms.KMS
AwsAccount string
KmsKeyId string
Application string
)
// Headers are added to all outgoing responses from lambda
var Headers = map[string]string{
`Content-Type`: `application/json`,
`Cache-Control`: `max-age = 0, private, must-revalidate, no-store`,
`Pragma`: `no-cache`,
`X-Content-Type-Options`: `nosniff`,
`X-Frame-Options`: `DENY`,
`X-Xss-Protection`: `1; mode = block`,
`Strict-Transport-Security`: `max-age = 31536000`,
}
func init() {
log.SetFlags(log.Lshortfile | log.LstdFlags | log.LUTC)
switch "" {
case os.Getenv("CORS"):
log.Fatal("Need CORS env var for access-control-allow-origin header")
case os.Getenv("REGION"):
log.Fatal("Need REGION env var")
case os.Getenv("ACCOUNT"):
log.Fatal("Need ACCOUNT env var")
case os.Getenv("KMS"):
log.Fatal("Need KMS env var")
case os.Getenv("APPLICATION"):
log.Fatal("Need APPLICATION env var")
}
Headers["Access-Control-Allow-Origin"] = os.Getenv("CORS")
Region = os.Getenv("REGION")
KmsKeyId = os.Getenv("KMS")
AwsAccount = os.Getenv("ACCOUNT")
Application = os.Getenv("APPLICATION")
AwsSession = session.Must(session.NewSession(&aws.Config{Region: aws.String(Region)}))
KMS = kms.New(AwsSession)
}