-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathconfig.go
More file actions
77 lines (68 loc) · 2.3 KB
/
config.go
File metadata and controls
77 lines (68 loc) · 2.3 KB
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
package conf
import (
"fmt"
"io/ioutil"
"github.com/deis/builder/pkg/sys"
"github.com/kelseyhightower/envconfig"
)
const (
builderKeyLocation = "/var/run/secrets/api/auth/builder-key"
storageCredLocation = "/var/run/secrets/deis/objectstore/creds/"
minioHostEnvVar = "DEIS_MINIO_SERVICE_HOST"
minioPortEnvVar = "DEIS_MINIO_SERVICE_PORT"
gcsKey = "key.json"
)
type Parameters map[string]interface{}
// EnvConfig is a convenience function to process the envconfig (
// https://github.com/kelseyhightower/envconfig) based configuration environment variables into
// conf. Additional notes:
//
// - appName will be passed as the first parameter to envconfig.Process
// - conf should be a pointer to an envconfig compatible struct. If you'd like to use struct
// tags to customize your struct, see
// https://github.com/kelseyhightower/envconfig#struct-tag-support
func EnvConfig(appName string, conf interface{}) error {
if err := envconfig.Process(appName, conf); err != nil {
return err
}
return nil
}
// GetBuilderKey returns the key to be used as token to interact with deis-controller
func GetBuilderKey() (string, error) {
builderKeyBytes, err := ioutil.ReadFile(builderKeyLocation)
if err != nil {
return "", fmt.Errorf("couldn't get builder key from %s (%s)", builderKeyLocation, err)
}
builderKey := string(builderKeyBytes)
return builderKey, nil
}
func GetStorageParams(env sys.Env) (Parameters, error) {
params := make(map[string]interface{})
files, err := ioutil.ReadDir(storageCredLocation)
if err != nil {
return nil, err
}
for _, file := range files {
data, err := ioutil.ReadFile(storageCredLocation + file.Name())
if err != nil {
return nil, err
}
//GCS expect the to have the location of the service account credential json file
if file.Name() == gcsKey {
params["keyfile"] = storageCredLocation + file.Name()
} else {
params[file.Name()] = string(data)
}
}
params["bucket"] = params["builder-bucket"]
params["container"] = params["builder-container"]
if env.Get("BUILDER_STORAGE") == "minio" {
mHost := env.Get(minioHostEnvVar)
mPort := env.Get(minioPortEnvVar)
params["regionendpoint"] = fmt.Sprintf("http://%s:%s", mHost, mPort)
params["secure"] = false
params["region"] = "us-east-1"
params["bucket"] = "git"
}
return params, nil
}