-
Notifications
You must be signed in to change notification settings - Fork 45
/
init.go
69 lines (56 loc) · 1.59 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright The Linux Foundation and each contributor to CommunityBridge.
// SPDX-License-Identifier: MIT
package init
import (
"fmt"
"github.com/communitybridge/easycla/cla-backend-go/config"
log "github.com/communitybridge/easycla/cla-backend-go/logging"
"github.com/spf13/viper"
)
const (
// ServiceName is the name of the service - this is used in logs and as a environment prefix
ServiceName = "CLA_SERVICE"
)
var (
stage string
configFile = ""
configVars config.Config
)
// CommonInit initializes the common properties
func CommonInit() {
stage = GetProperty("STAGE")
}
// GetProperty is a common routine to bind and return the specified environment variable
func GetProperty(property string) string {
err := viper.BindEnv(property)
if err != nil {
log.Fatalf("Unable to load property: %s - value not defined or empty", property)
}
value := viper.GetString(property)
if value == "" {
err := fmt.Errorf("%s environment variable cannot be empty", property)
log.Fatal(err.Error())
}
return value
}
// Init initialization logic for all the handlers
func Init() {
CommonInit()
AWSInit()
}
// ConfigVariable loads all the SSM values based on stage.
func ConfigVariable() {
var err error
configVars, err = config.LoadConfig(configFile, awsSession, stage)
if err != nil {
log.Panicf("Unable to load config - Error: %v", err)
}
}
// GetStage returns the deployment stage, e.g. dev, test, stage or prod
func GetStage() string {
return stage
}
// GetConfig returns the configuration SSM based on stage, e.g. dev, test, stage or prod
func GetConfig() config.Config {
return configVars
}