-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathenvironment.go
56 lines (43 loc) · 955 Bytes
/
environment.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
package main
import (
"encoding/json"
"io/ioutil"
"os"
"github.com/fern4lvarez/goexport"
)
type Environment struct {
Name string `json:"name"`
Type string `json:"type"`
}
type Environments []Environment
func (environments *Environments) Fetch(envs interface{}) error {
environmentsFile := ENVIRONMENTS_FILE
if envs != nil {
environmentsFile = envs.(string)
}
b, err := ioutil.ReadFile(environmentsFile)
if err != nil {
return err
}
if err = json.Unmarshal(b, &environments); err != nil {
return err
}
return nil
}
func (environment *Environment) Prepare(file string) error {
if environment.getBackend() == "gsutil" {
if err := os.Setenv("BOTO_CONFIG", file); err != nil {
return err
}
}
if err := goexport.Do(file); err != nil {
return err
}
return nil
}
func (environment *Environment) getBackend() string {
if environment.Type == "s3" || environment.Type == "gs" {
return "gsutil"
}
return "swift"
}