-
Notifications
You must be signed in to change notification settings - Fork 162
/
diff.go
62 lines (47 loc) · 1.37 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
51
52
53
54
55
56
57
58
59
60
61
62
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{}
type DeploymentDiff struct {
context map[string]interface{}
Diff [][]interface{}
}
func NewDeploymentDiff(diff [][]interface{}, context map[string]interface{}) DeploymentDiff {
return DeploymentDiff{
context: context,
Diff: diff,
}
}
func (d DeploymentImpl) Diff(manifest []byte, doNotRedact bool) (DeploymentDiff, error) {
resp, err := d.client.Diff(manifest, d.name, doNotRedact)
if err != nil {
return DeploymentDiff{}, err
}
return NewDeploymentDiff(resp.Diff, resp.Context), 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
}