/
space_summary.go
80 lines (68 loc) · 2.58 KB
/
space_summary.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
79
80
package ccv2
import (
"code.cloudfoundry.org/cli/api/cloudcontroller"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv2/internal"
)
// SpaceSummaryApplication represents an application inside a space
type SpaceSummaryApplication struct {
Name string `json:"name"`
ServiceNames []string `json:"service_names"`
}
// SpaceSummaryService represents a service inside a space
type SpaceSummaryService struct {
GUID string
Label string
ServiceBrokerName string
}
// SpaceSummaryServicePlan represents a service plan inside a space
type SpaceSummaryServicePlan struct {
GUID string `json:"guid"`
Name string `json:"name"`
Service SpaceSummaryService `json:"service"`
MaintenanceInfo MaintenanceInfo `json:"maintenance_info"`
}
// SpaceSummaryServiceInstance represents a service instance inside a space
type SpaceSummaryServiceInstance struct {
LastOperation LastOperation `json:"last_operation"`
Name string `json:"name"`
ServicePlan SpaceSummaryServicePlan `json:"service_plan"`
MaintenanceInfo MaintenanceInfo `json:"maintenance_info"`
}
// SpaceSummary represents a service instance inside a space
type SpaceSummary struct {
Applications []SpaceSummaryApplication
Name string
ServiceInstances []SpaceSummaryServiceInstance
}
// UnmarshalJSON helps unmarshal a Cloud Controller Space Summary response.
func (spaceSummary *SpaceSummary) UnmarshalJSON(data []byte) error {
var ccSpaceSummary struct {
Applications []SpaceSummaryApplication `json:"apps"`
Name string `json:"name"`
ServiceInstances []SpaceSummaryServiceInstance `json:"services"`
}
err := cloudcontroller.DecodeJSON(data, &ccSpaceSummary)
if err != nil {
return err
}
spaceSummary.Name = ccSpaceSummary.Name
spaceSummary.Applications = ccSpaceSummary.Applications
spaceSummary.ServiceInstances = ccSpaceSummary.ServiceInstances
return nil
}
// GetSpaceSummary returns the summary of the space with the given GUID.
func (client *Client) GetSpaceSummary(spaceGUID string) (SpaceSummary, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetSpaceSummaryRequest,
URIParams: Params{"space_guid": spaceGUID},
})
if err != nil {
return SpaceSummary{}, nil, err
}
var spaceSummary SpaceSummary
response := cloudcontroller.Response{
DecodeJSONResponseInto: &spaceSummary,
}
err = client.connection.Make(request, &response)
return spaceSummary, response.Warnings, err
}