forked from cloudfoundry-community/cloudfoundry-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spaces.go
49 lines (40 loc) · 1.56 KB
/
spaces.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
package resources
import "code.cloudfoundry.org/cli/cf/models"
type SpaceResource struct {
Resource
Entity SpaceEntity
}
type SpaceEntity struct {
Name string
Organization OrganizationResource
Applications []ApplicationResource `json:"apps"`
Domains []DomainResource
ServiceInstances []ServiceInstanceResource `json:"service_instances"`
SecurityGroups []SecurityGroupResource `json:"security_groups"`
SpaceQuotaGUID string `json:"space_quota_definition_guid"`
AllowSSH bool `json:"allow_ssh"`
}
func (resource SpaceResource) ToFields() (fields models.SpaceFields) {
fields.GUID = resource.Metadata.GUID
fields.Name = resource.Entity.Name
fields.AllowSSH = resource.Entity.AllowSSH
return
}
func (resource SpaceResource) ToModel() (space models.Space) {
space.SpaceFields = resource.ToFields()
for _, app := range resource.Entity.Applications {
space.Applications = append(space.Applications, app.ToFields())
}
for _, domainResource := range resource.Entity.Domains {
space.Domains = append(space.Domains, domainResource.ToFields())
}
for _, serviceResource := range resource.Entity.ServiceInstances {
space.ServiceInstances = append(space.ServiceInstances, serviceResource.ToFields())
}
for _, securityGroupResource := range resource.Entity.SecurityGroups {
space.SecurityGroups = append(space.SecurityGroups, securityGroupResource.ToFields())
}
space.Organization = resource.Entity.Organization.ToFields()
space.SpaceQuotaGUID = resource.Entity.SpaceQuotaGUID
return
}