github.com/jenspinney/cli@v6.42.1-0.20190207184520-7450c600020e+incompatible/api/cloudcontroller/ccv3/organization.go (about) 1 package ccv3 2 3 import ( 4 "code.cloudfoundry.org/cli/api/cloudcontroller/ccerror" 5 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/internal" 6 ) 7 8 // Organization represents a Cloud Controller V3 Organization. 9 type Organization struct { 10 // GUID is the unique organization identifier. 11 GUID string `json:"guid"` 12 // Name is the name of the organization. 13 Name string `json:"name"` 14 } 15 16 // GetIsolationSegmentOrganizations lists organizations 17 // entitled to an isolation segment. 18 func (client *Client) GetIsolationSegmentOrganizations(isolationSegmentGUID string) ([]Organization, Warnings, error) { 19 request, err := client.newHTTPRequest(requestOptions{ 20 RequestName: internal.GetIsolationSegmentOrganizationsRequest, 21 URIParams: map[string]string{"isolation_segment_guid": isolationSegmentGUID}, 22 }) 23 if err != nil { 24 return nil, nil, err 25 } 26 27 var fullOrgsList []Organization 28 warnings, err := client.paginate(request, Organization{}, func(item interface{}) error { 29 if app, ok := item.(Organization); ok { 30 fullOrgsList = append(fullOrgsList, app) 31 } else { 32 return ccerror.UnknownObjectInListError{ 33 Expected: Organization{}, 34 Unexpected: item, 35 } 36 } 37 return nil 38 }) 39 40 return fullOrgsList, warnings, err 41 } 42 43 // GetOrganizations lists organizations with optional filters. 44 func (client *Client) GetOrganizations(query ...Query) ([]Organization, Warnings, error) { 45 request, err := client.newHTTPRequest(requestOptions{ 46 RequestName: internal.GetOrganizationsRequest, 47 Query: query, 48 }) 49 if err != nil { 50 return nil, nil, err 51 } 52 53 var fullOrgsList []Organization 54 warnings, err := client.paginate(request, Organization{}, func(item interface{}) error { 55 if app, ok := item.(Organization); ok { 56 fullOrgsList = append(fullOrgsList, app) 57 } else { 58 return ccerror.UnknownObjectInListError{ 59 Expected: Organization{}, 60 Unexpected: item, 61 } 62 } 63 return nil 64 }) 65 66 return fullOrgsList, warnings, err 67 }