-
Notifications
You must be signed in to change notification settings - Fork 13
/
helpers.go
94 lines (82 loc) · 2 KB
/
helpers.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package app
import (
"strconv"
"path/filepath"
"github.com/microsoft/commercial-marketplace-offer-deploy/internal/utils"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
)
func getJsonAsMap(path string) map[string]interface{} {
jsonMap, err := utils.ReadJson(path)
if err != nil {
log.Println(err)
}
return jsonMap
}
func getClientEndpoint() string {
// no real need for viper here as we are just pulling 1 environment variable for the test harness
endpoint := env.GetString("MODM_API_ENDPOINT")
if len(endpoint) > 0 {
return endpoint
}
return clientEndpoint
}
func getLocation() string {
loc := env.GetString("MODM_DEPLOYMENT_LOCATION")
if len(loc) > 0 {
return loc
}
return location
}
func getSubscription() string {
sub := env.GetString("MODM_SUBSCRIPTION")
if len(sub) > 0 {
return sub
}
return subscription
}
func getResourceGroup() string {
rg := env.GetString("MODM_RESOURCE_GROUP")
if len(rg) > 0 {
return rg
}
return resourceGroup
}
func getTemplatePath(caseName string) string {
path := env.GetString("TEMPLATE_PATH")
if len(path) > 0 {
log.Printf("Found TEMPLATE_PATH - %s", path)
} else {
path = "./templates"
}
return filepath.Join(path, caseName, "mainTemplate.json")
}
func getParamsPath(caseName string) string {
templateParams := env.GetString("TEMPLATEPARAMS_PATH")
if len(templateParams) > 0 {
log.Printf("Found TEMPLATEPARAMS_PATH - %s", templateParams)
} else {
templateParams = "./templates"
}
return filepath.Join(templateParams, caseName, "parameters.json")
}
func getCallback() string {
callback := env.GetString("CALLBACK_BASE_URL")
if len(callback) > 0 {
return callback
}
//TODO: use the value that's set on echo
return "http://localhost:" + strconv.Itoa(8280)
}
func loadEnvironmentVariables() *viper.Viper {
env := viper.New()
env.AddConfigPath("./")
env.SetConfigName(".env")
env.SetConfigType("env")
env.AutomaticEnv()
err := env.ReadInConfig()
if err != nil {
log.Errorf("Error reading config file, %s", err)
}
return env
}