github.com/wanddynosios/cli/v8@v8.7.9-0.20240221182337-1a92e3a7017f/api/cloudcontroller/ccv3/buildpack.go (about) 1 package ccv3 2 3 import ( 4 "io" 5 6 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/internal" 7 "code.cloudfoundry.org/cli/api/cloudcontroller/uploads" 8 "code.cloudfoundry.org/cli/resources" 9 ) 10 11 // CreateBuildpack creates a buildpack with the given settings, Type and the 12 // ApplicationRelationship must be set. 13 func (client *Client) CreateBuildpack(bp resources.Buildpack) (resources.Buildpack, Warnings, error) { 14 var responseBody resources.Buildpack 15 16 _, warnings, err := client.MakeRequest(RequestParams{ 17 RequestName: internal.PostBuildpackRequest, 18 RequestBody: bp, 19 ResponseBody: &responseBody, 20 }) 21 22 return responseBody, warnings, err 23 } 24 25 // DeleteBuildpack deletes the buildpack with the provided guid. 26 func (client Client) DeleteBuildpack(buildpackGUID string) (JobURL, Warnings, error) { 27 jobURL, warnings, err := client.MakeRequest(RequestParams{ 28 RequestName: internal.DeleteBuildpackRequest, 29 URIParams: internal.Params{"buildpack_guid": buildpackGUID}, 30 }) 31 32 return jobURL, warnings, err 33 } 34 35 // GetBuildpacks lists buildpacks with optional filters. 36 func (client *Client) GetBuildpacks(query ...Query) ([]resources.Buildpack, Warnings, error) { 37 var buildpacks []resources.Buildpack 38 39 _, warnings, err := client.MakeListRequest(RequestParams{ 40 RequestName: internal.GetBuildpacksRequest, 41 Query: query, 42 ResponseBody: resources.Buildpack{}, 43 AppendToList: func(item interface{}) error { 44 buildpacks = append(buildpacks, item.(resources.Buildpack)) 45 return nil 46 }, 47 }) 48 49 return buildpacks, warnings, err 50 } 51 52 func (client Client) UpdateBuildpack(buildpack resources.Buildpack) (resources.Buildpack, Warnings, error) { 53 var responseBody resources.Buildpack 54 55 _, warnings, err := client.MakeRequest(RequestParams{ 56 RequestName: internal.PatchBuildpackRequest, 57 URIParams: internal.Params{"buildpack_guid": buildpack.GUID}, 58 RequestBody: buildpack, 59 ResponseBody: &responseBody, 60 }) 61 62 return responseBody, warnings, err 63 } 64 65 // UploadBuildpack uploads the contents of a buildpack zip to the server. 66 func (client *Client) UploadBuildpack(buildpackGUID string, buildpackPath string, buildpack io.Reader, buildpackLength int64) (JobURL, Warnings, error) { 67 68 contentLength, err := uploads.CalculateRequestSize(buildpackLength, buildpackPath, "bits") 69 if err != nil { 70 return "", nil, err 71 } 72 73 contentType, body, writeErrors := uploads.CreateMultipartBodyAndHeader(buildpack, buildpackPath, "bits") 74 75 responseLocation, warnings, err := client.MakeRequestUploadAsync( 76 internal.PostBuildpackBitsRequest, 77 internal.Params{"buildpack_guid": buildpackGUID}, 78 contentType, 79 body, 80 contentLength, 81 nil, 82 writeErrors, 83 ) 84 85 return JobURL(responseLocation), warnings, err 86 }