github.com/orange-cloudfoundry/cli@v7.1.0+incompatible/api/cloudcontroller/ccv3/organization.go (about)

     1  package ccv3
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/internal"
     5  	"code.cloudfoundry.org/cli/resources"
     6  )
     7  
     8  func (client *Client) CreateOrganization(orgName string) (resources.Organization, Warnings, error) {
     9  	org := resources.Organization{Name: orgName}
    10  	var responseBody resources.Organization
    11  
    12  	_, warnings, err := client.MakeRequest(RequestParams{
    13  		RequestName:  internal.PostOrganizationRequest,
    14  		RequestBody:  org,
    15  		ResponseBody: &responseBody,
    16  	})
    17  
    18  	return responseBody, warnings, err
    19  }
    20  
    21  // DeleteOrganization deletes the organization with the given GUID.
    22  func (client *Client) DeleteOrganization(orgGUID string) (JobURL, Warnings, error) {
    23  	jobURL, warnings, err := client.MakeRequest(RequestParams{
    24  		RequestName: internal.DeleteOrganizationRequest,
    25  		URIParams:   internal.Params{"organization_guid": orgGUID},
    26  	})
    27  
    28  	return jobURL, warnings, err
    29  }
    30  
    31  // GetDefaultDomain gets the default domain for the organization with the given GUID.
    32  func (client *Client) GetDefaultDomain(orgGUID string) (resources.Domain, Warnings, error) {
    33  	var responseBody resources.Domain
    34  
    35  	_, warnings, err := client.MakeRequest(RequestParams{
    36  		RequestName:  internal.GetDefaultDomainRequest,
    37  		URIParams:    internal.Params{"organization_guid": orgGUID},
    38  		ResponseBody: &responseBody,
    39  	})
    40  
    41  	return responseBody, warnings, err
    42  }
    43  
    44  // GetIsolationSegmentOrganizations lists organizations
    45  // entitled to an isolation segment.
    46  func (client *Client) GetIsolationSegmentOrganizations(isolationSegmentGUID string) ([]resources.Organization, Warnings, error) {
    47  	var organizations []resources.Organization
    48  
    49  	_, warnings, err := client.MakeListRequest(RequestParams{
    50  		RequestName:  internal.GetIsolationSegmentOrganizationsRequest,
    51  		URIParams:    internal.Params{"isolation_segment_guid": isolationSegmentGUID},
    52  		ResponseBody: resources.Organization{},
    53  		AppendToList: func(item interface{}) error {
    54  			organizations = append(organizations, item.(resources.Organization))
    55  			return nil
    56  		},
    57  	})
    58  
    59  	return organizations, warnings, err
    60  }
    61  
    62  // GetOrganization gets an organization by the given guid.
    63  func (client *Client) GetOrganization(orgGUID string) (resources.Organization, Warnings, error) {
    64  	var responseBody resources.Organization
    65  
    66  	_, warnings, err := client.MakeRequest(RequestParams{
    67  		RequestName:  internal.GetOrganizationRequest,
    68  		URIParams:    internal.Params{"organization_guid": orgGUID},
    69  		ResponseBody: &responseBody,
    70  	})
    71  
    72  	return responseBody, warnings, err
    73  }
    74  
    75  // GetOrganizations lists organizations with optional filters.
    76  func (client *Client) GetOrganizations(query ...Query) ([]resources.Organization, Warnings, error) {
    77  	var organizations []resources.Organization
    78  
    79  	_, warnings, err := client.MakeListRequest(RequestParams{
    80  		RequestName:  internal.GetOrganizationsRequest,
    81  		Query:        query,
    82  		ResponseBody: resources.Organization{},
    83  		AppendToList: func(item interface{}) error {
    84  			organizations = append(organizations, item.(resources.Organization))
    85  			return nil
    86  		},
    87  	})
    88  
    89  	return organizations, warnings, err
    90  }
    91  
    92  // UpdateOrganization updates an organization with the given properties.
    93  func (client *Client) UpdateOrganization(org resources.Organization) (resources.Organization, Warnings, error) {
    94  	orgGUID := org.GUID
    95  	org.GUID = ""
    96  
    97  	var responseBody resources.Organization
    98  
    99  	_, warnings, err := client.MakeRequest(RequestParams{
   100  		RequestName:  internal.PatchOrganizationRequest,
   101  		URIParams:    internal.Params{"organization_guid": orgGUID},
   102  		RequestBody:  org,
   103  		ResponseBody: &responseBody,
   104  	})
   105  
   106  	return responseBody, warnings, err
   107  }