-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathutils.go
More file actions
111 lines (84 loc) · 2.17 KB
/
utils.go
File metadata and controls
111 lines (84 loc) · 2.17 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package builder
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"gopkg.in/yaml.v2"
)
// YamlToJson takes an input yaml string, parses it and returns a string formatted as json.
func YamlToJson(bytes []byte) (string, error) {
var anomaly map[string]string
if err := yaml.Unmarshal(bytes, &anomaly); err != nil {
return "", err
}
retVal, err := json.Marshal(&anomaly)
if err != nil {
return "", err
}
return string(retVal), nil
}
// ParseConfig takes a response body from the controller and returns a Config object.
func ParseConfig(res *http.Response) (*Config, error) {
body, err := ioutil.ReadAll(res.Body)
if err != nil {
return nil, err
}
var config Config
err = json.Unmarshal(body, &config)
return &config, err
}
func ParseDomain(bytes []byte) (string, error) {
var hook BuildHookResponse
if err := json.Unmarshal(bytes, &hook); err != nil {
return "", err
}
if hook.Domains == nil {
return "", fmt.Errorf("invalid application domain")
}
if len(hook.Domains) < 1 {
return "", fmt.Errorf("invalid application domain")
}
return hook.Domains[0], nil
}
func ParseReleaseVersion(bytes []byte) (int, error) {
var hook BuildHookResponse
if err := json.Unmarshal(bytes, &hook); err != nil {
return 0, fmt.Errorf("invalid application json configuration")
}
if hook.Release == nil {
return 0, fmt.Errorf("invalid application version")
}
return hook.Release["version"], nil
}
func GetDefaultType(bytes []byte) (string, error) {
type YamlTypeMap struct {
DefaultProcessTypes ProcessType
}
var p YamlTypeMap
if err := yaml.Unmarshal(bytes, &p); err != nil {
return "", err
}
retVal, err := json.Marshal(&p)
if err != nil {
return "", err
}
if len(p.DefaultProcessTypes) == 0 {
return "{}", nil
}
return string(retVal), nil
}
func ParseControllerConfig(bytes []byte) ([]string, error) {
var controllerConfig Config
if err := json.Unmarshal(bytes, &controllerConfig); err != nil {
return []string{}, err
}
if controllerConfig.Values == nil {
return []string{""}, nil
}
retVal := []string{}
for k, v := range controllerConfig.Values {
retVal = append(retVal, fmt.Sprintf(" -e %s=\"%v\"", k, v))
}
return retVal, nil
}