github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+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  	Name string `json:"name"`
    11  	GUID string `json:"guid"`
    12  }
    13  
    14  // GetOrganizations lists organizations with optional filters.
    15  func (client *Client) GetOrganizations(query ...Query) ([]Organization, Warnings, error) {
    16  	request, err := client.newHTTPRequest(requestOptions{
    17  		RequestName: internal.GetOrgsRequest,
    18  		Query:       query,
    19  	})
    20  	if err != nil {
    21  		return nil, nil, err
    22  	}
    23  
    24  	var fullOrgsList []Organization
    25  	warnings, err := client.paginate(request, Organization{}, func(item interface{}) error {
    26  		if app, ok := item.(Organization); ok {
    27  			fullOrgsList = append(fullOrgsList, app)
    28  		} else {
    29  			return ccerror.UnknownObjectInListError{
    30  				Expected:   Organization{},
    31  				Unexpected: item,
    32  			}
    33  		}
    34  		return nil
    35  	})
    36  
    37  	return fullOrgsList, warnings, err
    38  }
    39  
    40  // GetIsolationSegmentOrganizationsByIsolationSegment lists organizations
    41  // entitled to an isolation segment
    42  func (client *Client) GetIsolationSegmentOrganizationsByIsolationSegment(isolationSegmentGUID string) ([]Organization, Warnings, error) {
    43  	request, err := client.newHTTPRequest(requestOptions{
    44  		RequestName: internal.GetIsolationSegmentOrganizationsRequest,
    45  		URIParams:   map[string]string{"isolation_segment_guid": isolationSegmentGUID},
    46  	})
    47  	if err != nil {
    48  		return nil, nil, err
    49  	}
    50  
    51  	var fullOrgsList []Organization
    52  	warnings, err := client.paginate(request, Organization{}, func(item interface{}) error {
    53  		if app, ok := item.(Organization); ok {
    54  			fullOrgsList = append(fullOrgsList, app)
    55  		} else {
    56  			return ccerror.UnknownObjectInListError{
    57  				Expected:   Organization{},
    58  				Unexpected: item,
    59  			}
    60  		}
    61  		return nil
    62  	})
    63  
    64  	return fullOrgsList, warnings, err
    65  }