-
Notifications
You must be signed in to change notification settings - Fork 162
/
cpi_configs.go
81 lines (60 loc) · 1.67 KB
/
cpi_configs.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
70
71
72
73
74
75
76
77
78
79
80
81
package director
import (
"fmt"
"net/http"
gourl "net/url"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
)
type CPIConfig struct {
Properties string
}
func (d DirectorImpl) LatestCPIConfig() (CPIConfig, error) {
resps, err := d.client.CPIConfigs()
if err != nil {
return CPIConfig{}, err
}
if len(resps) == 0 {
return CPIConfig{}, bosherr.Error("No CPI config")
}
return resps[0], nil
}
func (d DirectorImpl) UpdateCPIConfig(manifest []byte) error {
return d.client.UpdateCPIConfig(manifest)
}
func (c Client) CPIConfigs() ([]CPIConfig, error) {
var resps []CPIConfig
err := c.clientRequest.Get("/cpi_configs?limit=1", &resps)
if err != nil {
return resps, bosherr.WrapErrorf(err, "Finding CPI configs")
}
return resps, nil
}
func (c Client) UpdateCPIConfig(manifest []byte) error {
path := "/cpi_configs"
setHeaders := func(req *http.Request) {
req.Header.Add("Content-Type", "text/yaml")
}
_, _, err := c.clientRequest.RawPost(path, manifest, setHeaders)
if err != nil {
return bosherr.WrapErrorf(err, "Updating CPI config")
}
return nil
}
func (d DirectorImpl) DiffCPIConfig(manifest []byte, noRedact bool) (ConfigDiff, error) {
resp, err := d.client.DiffCPIConfig(manifest, noRedact)
if err != nil {
return ConfigDiff{}, err
}
return NewConfigDiff(resp.Diff), nil
}
func (c Client) DiffCPIConfig(manifest []byte, noRedact bool) (ConfigDiffResponse, error) {
query := gourl.Values{}
if noRedact {
query.Add("redact", "false")
}
path := fmt.Sprintf("/cpi_configs/diff?%s", query.Encode())
setHeaders := func(req *http.Request) {
req.Header.Add("Content-Type", "text/yaml")
}
return c.postConfigDiff(path, manifest, setHeaders)
}