-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathget_app_config.go
More file actions
51 lines (41 loc) · 1.07 KB
/
get_app_config.go
File metadata and controls
51 lines (41 loc) · 1.07 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
package gitreceive
import (
"bytes"
"encoding/json"
"net/http"
"github.com/deis/builder/pkg"
)
func getAppConfig(conf *Config, builderKey, userName, appName string) (*pkg.Config, error) {
data, err := json.Marshal(&pkg.ConfigHook{
ReceiveUser: userName,
ReceiveRepo: appName,
})
if err != nil {
return nil, err
}
b := bytes.NewReader(data)
url := controllerURLStr(conf, "v2", "hooks", "config")
req, err := http.NewRequest("POST", url, b)
if err != nil {
return nil, err
}
req.Header.Add("Content-Type", contentType)
req.Header.Add("Accept", contentType)
req.Header.Add("User-Agent", userAgent)
req.Header.Add("X-Deis-Builder-Auth", builderKey)
res, err := http.DefaultClient.Do(req)
if err != nil {
return nil, err
}
defer res.Body.Close()
if res.StatusCode == 404 {
return nil, errControllerNotFound
} else if res.StatusCode != 200 {
return nil, unexpectedControllerStatusCode{expected: 200, actual: res.StatusCode}
}
ret := &pkg.Config{}
if err := json.NewDecoder(res.Body).Decode(ret); err != nil {
return nil, err
}
return ret, nil
}