github.com/jenspinney/cli@v6.42.1-0.20190207184520-7450c600020e+incompatible/api/cloudcontroller/ccv3/job_url.go (about)

     1  package ccv3
     2  
     3  import (
     4  	"bytes"
     5  
     6  	"code.cloudfoundry.org/cli/api/cloudcontroller"
     7  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/internal"
     8  )
     9  
    10  // JobURL is the URL to a given Job.
    11  type JobURL string
    12  
    13  // DeleteApplication deletes the app with the given app GUID. Returns back a
    14  // resulting job URL to poll.
    15  func (client *Client) DeleteApplication(appGUID string) (JobURL, Warnings, error) {
    16  	request, err := client.newHTTPRequest(requestOptions{
    17  		RequestName: internal.DeleteApplicationRequest,
    18  		URIParams:   internal.Params{"app_guid": appGUID},
    19  	})
    20  	if err != nil {
    21  		return "", nil, err
    22  	}
    23  
    24  	response := cloudcontroller.Response{}
    25  	err = client.connection.Make(request, &response)
    26  
    27  	return JobURL(response.ResourceLocationURL), response.Warnings, err
    28  }
    29  
    30  // UpdateApplicationApplyManifest applies the manifest to the given
    31  // application. Returns back a resulting job URL to poll.
    32  func (client *Client) UpdateApplicationApplyManifest(appGUID string, rawManifest []byte) (JobURL, Warnings, error) {
    33  	request, err := client.newHTTPRequest(requestOptions{
    34  		RequestName: internal.PostApplicationActionApplyManifest,
    35  		URIParams:   map[string]string{"app_guid": appGUID},
    36  		Body:        bytes.NewReader(rawManifest),
    37  	})
    38  
    39  	if err != nil {
    40  		return "", nil, err
    41  	}
    42  
    43  	request.Header.Set("Content-Type", "application/x-yaml")
    44  
    45  	response := cloudcontroller.Response{}
    46  	err = client.connection.Make(request, &response)
    47  
    48  	return JobURL(response.ResourceLocationURL), response.Warnings, err
    49  }