github.com/arunkumar7540/cli@v6.45.0+incompatible/api/cloudcontroller/ccv3/job_url.go (about)

     1  package ccv3
     2  
     3  import (
     4  	"bytes"
     5  	"code.cloudfoundry.org/cli/api/cloudcontroller"
     6  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/internal"
     7  )
     8  
     9  // JobURL is the URL to a given Job.
    10  type JobURL string
    11  
    12  // DeleteApplication deletes the app with the given app GUID. Returns back a
    13  // resulting job URL to poll.
    14  func (client *Client) DeleteApplication(appGUID string) (JobURL, Warnings, error) {
    15  	request, err := client.newHTTPRequest(requestOptions{
    16  		RequestName: internal.DeleteApplicationRequest,
    17  		URIParams:   internal.Params{"app_guid": appGUID},
    18  	})
    19  	if err != nil {
    20  		return "", nil, err
    21  	}
    22  
    23  	response := cloudcontroller.Response{}
    24  	err = client.connection.Make(request, &response)
    25  
    26  	return JobURL(response.ResourceLocationURL), response.Warnings, err
    27  }
    28  
    29  // UpdateApplicationApplyManifest applies the manifest to the given
    30  // application. Returns back a resulting job URL to poll.
    31  func (client *Client) UpdateApplicationApplyManifest(appGUID string, rawManifest []byte) (JobURL, Warnings, error) {
    32  	request, err := client.newHTTPRequest(requestOptions{
    33  		RequestName: internal.PostApplicationActionApplyManifest,
    34  		URIParams:   map[string]string{"app_guid": appGUID},
    35  		Body:        bytes.NewReader(rawManifest),
    36  	})
    37  
    38  	if err != nil {
    39  		return "", nil, err
    40  	}
    41  
    42  	request.Header.Set("Content-Type", "application/x-yaml")
    43  
    44  	response := cloudcontroller.Response{}
    45  	err = client.connection.Make(request, &response)
    46  
    47  	return JobURL(response.ResourceLocationURL), response.Warnings, err
    48  }
    49  
    50  // UpdateSpaceApplyManifest - Is there a better name for this, since ...
    51  // -- The Space resource is not actually updated.
    52  // -- Instead what this ApplyManifest may do is to Create or Update Applications instead.
    53  
    54  // Applies the manifest to the given space. Returns back a resulting job URL to poll.
    55  
    56  // For each app specified in the manifest, the server-side handles:
    57  // (1) Finding or creating this app.
    58  // (2) Applying manifest properties to this app.
    59  
    60  func (client *Client) UpdateSpaceApplyManifest(spaceGUID string, rawManifest []byte, query ...Query) (JobURL, Warnings, error) {
    61  	request, requestExecuteErr := client.newHTTPRequest(requestOptions{
    62  		RequestName: internal.PostSpaceActionApplyManifestRequest,
    63  		Query:       query,
    64  		URIParams:   map[string]string{"space_guid": spaceGUID},
    65  		Body:        bytes.NewReader(rawManifest),
    66  	})
    67  
    68  	if requestExecuteErr != nil {
    69  		return JobURL(""), nil, requestExecuteErr
    70  	}
    71  
    72  	request.Header.Set("Content-Type", "application/x-yaml")
    73  
    74  	response := cloudcontroller.Response{}
    75  	err := client.connection.Make(request, &response)
    76  
    77  	return JobURL(response.ResourceLocationURL), response.Warnings, err
    78  }