forked from cloudfoundry/bosh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
packages.go
64 lines (47 loc) · 1.38 KB
/
packages.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
package director
import (
"net/http"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
"gopkg.in/yaml.v2"
)
func (d DirectorImpl) MatchPackages(manifest interface{}, compiled bool) ([]string, error) {
var matches []string
if compiled {
matches, _ = d.client.MatchCompiledPackages(manifest)
} else {
matches, _ = d.client.MatchPackages(manifest)
}
return matches, nil
}
func (c Client) MatchPackages(manifest interface{}) ([]string, error) {
path := "/packages/matches"
reqBody, err := yaml.Marshal(manifest)
if err != nil {
return nil, bosherr.WrapErrorf(err, "Marshaling request body")
}
setHeaders := func(req *http.Request) {
req.Header.Add("Content-Type", "text/yaml")
}
var resp []string
err = c.clientRequest.Post(path, reqBody, setHeaders, &resp)
if err != nil {
return nil, bosherr.WrapError(err, "Matching packages")
}
return resp, nil
}
func (c Client) MatchCompiledPackages(manifest interface{}) ([]string, error) {
path := "/packages/matches_compiled"
reqBody, err := yaml.Marshal(manifest)
if err != nil {
return nil, bosherr.WrapErrorf(err, "Marshaling request body")
}
setHeaders := func(req *http.Request) {
req.Header.Add("Content-Type", "text/yaml")
}
var resp []string
err = c.clientRequest.Post(path, reqBody, setHeaders, &resp)
if err != nil {
return nil, bosherr.WrapError(err, "Matching compiled packages")
}
return resp, nil
}