-
Notifications
You must be signed in to change notification settings - Fork 162
/
diff.go
50 lines (37 loc) · 1.09 KB
/
diff.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
package director
import (
"fmt"
"net/http"
gourl "net/url"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
)
type DeploymentDiffResponse struct {
Context map[string]interface{} `json:"context"`
Diff [][]interface{} `json:"diff"`
}
type DiffLines [][]interface{}
func (d DeploymentImpl) Diff(manifest []byte, doNotRedact bool) (DiffLines, error) {
resp, err := d.client.Diff(manifest, d.name, doNotRedact)
if err != nil {
return DiffLines{}, err
}
return DiffLines(resp.Diff), nil
}
func (c Client) Diff(manifest []byte, deploymentName string, doNotRedact bool) (DeploymentDiffResponse, error) {
setHeaders := func(req *http.Request) {
req.Header.Add("Content-Type", "text/yaml")
}
query := gourl.Values{}
if doNotRedact {
query.Add("redact", "false")
} else {
query.Add("redact", "true")
}
path := fmt.Sprintf("/deployments/%s/diff?%s", deploymentName, query.Encode())
var resp DeploymentDiffResponse
err := c.clientRequest.Post(path, manifest, setHeaders, &resp)
if err != nil {
return resp, bosherr.WrapErrorf(err, "Fetching diff result")
}
return resp, nil
}