-
Notifications
You must be signed in to change notification settings - Fork 0
/
space.go
60 lines (52 loc) · 1.46 KB
/
space.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
package ccv2
import (
"encoding/json"
"code.cloudfoundry.org/cli/api/cloudcontroller"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv2/internal"
)
// Space represents a Cloud Controller Space.
type Space struct {
GUID string
Name string
AllowSSH bool
}
// UnmarshalJSON helps unmarshal a Cloud Controller Space response.
func (space *Space) UnmarshalJSON(data []byte) error {
var ccSpace struct {
Metadata internal.Metadata `json:"metadata"`
Entity struct {
Name string `json:"name"`
AllowSSH bool `json:"allow_ssh"`
} `json:"entity"`
}
if err := json.Unmarshal(data, &ccSpace); err != nil {
return err
}
space.GUID = ccSpace.Metadata.GUID
space.Name = ccSpace.Entity.Name
space.AllowSSH = ccSpace.Entity.AllowSSH
return nil
}
// GetSpaces returns back a list of Spaces based off of the provided queries.
func (client *Client) GetSpaces(queries []Query) ([]Space, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.SpacesRequest,
Query: FormatQueryParameters(queries),
})
if err != nil {
return nil, nil, err
}
var fullSpacesList []Space
warnings, err := client.paginate(request, Space{}, func(item interface{}) error {
if space, ok := item.(Space); ok {
fullSpacesList = append(fullSpacesList, space)
} else {
return cloudcontroller.UnknownObjectInListError{
Expected: Space{},
Unexpected: item,
}
}
return nil
})
return fullSpacesList, warnings, err
}