-
Notifications
You must be signed in to change notification settings - Fork 162
/
diff_config.go
46 lines (36 loc) · 1.07 KB
/
diff_config.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
package director
import (
"encoding/json"
"net/http"
"strconv"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
)
type ID struct {
ID string `json:"id"`
}
type DiffConfigBody struct {
From ID `json:"from"`
To ID `json:"to"`
}
func (d DirectorImpl) DiffConfigByID(fromID string, toID string) (ConfigDiff, error) {
resp, err := d.client.DiffConfigByID(fromID, toID)
if err != nil {
return ConfigDiff{}, err
}
return NewConfigDiff(resp.Diff), nil
}
func (c Client) DiffConfigByID(fromID string, toID string) (ConfigDiffResponse, error) {
setHeaders := func(req *http.Request) {
req.Header.Add("Content-Type", "application/json")
}
_, errFromId := strconv.Atoi(fromID)
_, errToId := strconv.Atoi(toID)
if (errFromId != nil) || (errToId != nil) {
return ConfigDiffResponse{}, bosherr.Error("Config ID needs to be an integer.")
}
body, err := json.Marshal(DiffConfigBody{ID{fromID}, ID{toID}})
if err != nil {
return ConfigDiffResponse{}, bosherr.WrapError(err, "Can't marshal request body")
}
return c.postConfigDiff("/configs/diff", body, setHeaders)
}