-
Notifications
You must be signed in to change notification settings - Fork 44
/
config.go
69 lines (60 loc) · 1.95 KB
/
config.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
package conf
import (
"fmt"
"io/ioutil"
"strings"
"github.com/deis/builder/pkg/sys"
)
const (
storageCredLocation = "/var/run/secrets/deis/objectstore/creds/"
minioHostEnvVar = "DEIS_MINIO_SERVICE_HOST"
minioPortEnvVar = "DEIS_MINIO_SERVICE_PORT"
gcsKey = "key.json"
)
// BuilderKeyLocation holds the path of the builder key secret.
var BuilderKeyLocation = "/var/run/secrets/api/auth/builder-key"
// Parameters is map which contains storage params
type Parameters map[string]interface{}
// 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 := strings.Trim(string(builderKeyBytes), "\n")
return builderKey, nil
}
// GetStorageParams returns the credentials required for connecting to object storage
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 {
if file.IsDir() || file.Name() == "..data" {
continue
}
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
}