-
Notifications
You must be signed in to change notification settings - Fork 22
/
proxy.go
48 lines (38 loc) · 937 Bytes
/
proxy.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
package test_helpers
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"os"
)
func ActiveProxyBackend() (string, error) {
client := &http.Client{}
var proxyUsername = os.Getenv("PROXY_USERNAME")
var proxyPassword = os.Getenv("PROXY_PASSWORD")
req, err := http.NewRequest("GET", fmt.Sprintf("http://%s:8080/v0/cluster", BoshEnvironment()), nil)
if err != nil {
return "", err
}
req.SetBasicAuth(proxyUsername, proxyPassword)
resp, err := client.Do(req)
if err != nil {
return "", err
}
if resp.StatusCode != 200 {
return "", fmt.Errorf("ERROR: Non-200 received from proxy. Status: %s", resp.Status)
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", err
}
var cluster struct {
ActiveBackend struct {
Host string `json:"host"`
} `json:"activeBackend`
}
if err := json.Unmarshal(body, &cluster); err != nil {
return "", err
}
return cluster.ActiveBackend.Host, nil
}