forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_resource.go
69 lines (59 loc) · 1.74 KB
/
build_resource.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
package resources
import (
"encoding/json"
"code.cloudfoundry.org/cli/api/cloudcontroller"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant"
)
// Build represent the process of staging an application package.
type Build struct {
// CreatedAt is the time with zone when the build was created.
CreatedAt string
// DropletGUID is the unique identifier for the resulting droplet from the
// staging process.
DropletGUID string
// Error describes errors during the build process.
Error string
// GUID is the unique build identifier.
GUID string
// PackageGUID is the unique identifier for package that is the input to the
// staging process.
PackageGUID string
// State is the state of the build.
State constant.BuildState
}
// MarshalJSON converts a Build into a Cloud Controller Application.
func (b Build) MarshalJSON() ([]byte, error) {
var ccBuild struct {
Package struct {
GUID string `json:"guid"`
} `json:"package"`
}
ccBuild.Package.GUID = b.PackageGUID
return json.Marshal(ccBuild)
}
// UnmarshalJSON helps unmarshal a Cloud Controller Build response.
func (b *Build) UnmarshalJSON(data []byte) error {
var ccBuild struct {
CreatedAt string `json:"created_at,omitempty"`
GUID string `json:"guid,omitempty"`
Error string `json:"error"`
Package struct {
GUID string `json:"guid"`
} `json:"package"`
State constant.BuildState `json:"state,omitempty"`
Droplet struct {
GUID string `json:"guid"`
} `json:"droplet"`
}
err := cloudcontroller.DecodeJSON(data, &ccBuild)
if err != nil {
return err
}
b.GUID = ccBuild.GUID
b.CreatedAt = ccBuild.CreatedAt
b.Error = ccBuild.Error
b.PackageGUID = ccBuild.Package.GUID
b.State = ccBuild.State
b.DropletGUID = ccBuild.Droplet.GUID
return nil
}