forked from cloudfoundry-community/cloudfoundry-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.go
78 lines (63 loc) · 1.81 KB
/
build.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
package ccv3
import (
"bytes"
"encoding/json"
"code.cloudfoundry.org/cli/api/cloudcontroller"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/internal"
)
type BuildState string
const (
BuildStateFailed BuildState = "FAILED"
BuildStateStaged BuildState = "STAGED"
BuildStateStaging BuildState = "STAGING"
)
type Build struct {
GUID string `json:"guid,omitempty"`
Error string `json:"error"`
Package Package `json:"package"`
State BuildState `json:"state,omitempty"`
Droplet Droplet `json:"droplet"`
}
func (b Build) MarshalJSON() ([]byte, error) {
var ccBuild struct {
Package struct {
GUID string `json:"guid"`
} `json:"package"`
}
ccBuild.Package.GUID = b.Package.GUID
return json.Marshal(ccBuild)
}
// CreateBuild creates the given build, requires Package GUID to be set on the
// build.
func (client *Client) CreateBuild(build Build) (Build, Warnings, error) {
bodyBytes, err := json.Marshal(build)
if err != nil {
return Build{}, nil, err
}
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.PostBuildRequest,
Body: bytes.NewReader(bodyBytes),
})
var responseBuild Build
response := cloudcontroller.Response{
Result: &responseBuild,
}
err = client.connection.Make(request, &response)
return responseBuild, response.Warnings, err
}
// GetBuild gets the build with the given GUID.
func (client *Client) GetBuild(guid string) (Build, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetBuildRequest,
URIParams: internal.Params{"guid": guid},
})
if err != nil {
return Build{}, nil, err
}
var responseBuild Build
response := cloudcontroller.Response{
Result: &responseBuild,
}
err = client.connection.Make(request, &response)
return responseBuild, response.Warnings, err
}