github.com/cloudfoundry-attic/cli-with-i18n@v6.32.1-0.20171002233121-7401370d3b85+incompatible/api/cloudcontroller/ccv3/organization.go (about)

     1  package ccv3
     2  
     3  import (
     4  	"net/url"
     5  
     6  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccerror"
     7  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/internal"
     8  )
     9  
    10  // Organization represents a Cloud Controller V3 Organization.
    11  type Organization struct {
    12  	Name string `json:"name"`
    13  	GUID string `json:"guid"`
    14  }
    15  
    16  // GetOrganizations lists organizations with optional filters.
    17  func (client *Client) GetOrganizations(query url.Values) ([]Organization, Warnings, error) {
    18  	request, err := client.newHTTPRequest(requestOptions{
    19  		RequestName: internal.GetOrgsRequest,
    20  		Query:       query,
    21  	})
    22  	if err != nil {
    23  		return nil, nil, err
    24  	}
    25  
    26  	var fullOrgsList []Organization
    27  	warnings, err := client.paginate(request, Organization{}, func(item interface{}) error {
    28  		if app, ok := item.(Organization); ok {
    29  			fullOrgsList = append(fullOrgsList, app)
    30  		} else {
    31  			return ccerror.UnknownObjectInListError{
    32  				Expected:   Organization{},
    33  				Unexpected: item,
    34  			}
    35  		}
    36  		return nil
    37  	})
    38  
    39  	return fullOrgsList, warnings, err
    40  }
    41  
    42  // GetIsolationSegmentOrganizationsByIsolationSegment lists organizations
    43  // entitled to an isolation segment
    44  func (client *Client) GetIsolationSegmentOrganizationsByIsolationSegment(isolationSegmentGUID string) ([]Organization, Warnings, error) {
    45  	request, err := client.newHTTPRequest(requestOptions{
    46  		RequestName: internal.GetIsolationSegmentOrganizationsRequest,
    47  		URIParams:   map[string]string{"isolation_segment_guid": isolationSegmentGUID},
    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  }