github.com/wanddynosios/cli/v8@v8.7.9-0.20240221182337-1a92e3a7017f/api/cloudcontroller/ccv3/application.go (about) 1 package ccv3 2 3 import ( 4 "code.cloudfoundry.org/cli/api/cloudcontroller/ccerror" 5 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/internal" 6 "code.cloudfoundry.org/cli/resources" 7 ) 8 9 // CreateApplication creates an application with the given settings. 10 func (client *Client) CreateApplication(app resources.Application) (resources.Application, Warnings, error) { 11 var responseBody resources.Application 12 13 _, warnings, err := client.MakeRequest(RequestParams{ 14 RequestName: internal.PostApplicationRequest, 15 RequestBody: app, 16 ResponseBody: &responseBody, 17 }) 18 19 return responseBody, warnings, err 20 } 21 22 func (client *Client) GetApplicationByNameAndSpace(appName string, spaceGUID string) (resources.Application, Warnings, error) { 23 apps, warnings, err := client.GetApplications( 24 Query{Key: NameFilter, Values: []string{appName}}, 25 Query{Key: SpaceGUIDFilter, Values: []string{spaceGUID}}, 26 Query{Key: PerPage, Values: []string{"1"}}, 27 Query{Key: Page, Values: []string{"1"}}, 28 ) 29 if err != nil { 30 return resources.Application{}, warnings, err 31 } 32 33 if len(apps) == 0 { 34 return resources.Application{}, warnings, ccerror.ApplicationNotFoundError{Name: appName} 35 } 36 37 return apps[0], warnings, nil 38 } 39 40 // GetApplications lists applications with optional queries. 41 func (client *Client) GetApplications(query ...Query) ([]resources.Application, Warnings, error) { 42 var apps []resources.Application 43 44 _, warnings, err := client.MakeListRequest(RequestParams{ 45 RequestName: internal.GetApplicationsRequest, 46 Query: query, 47 ResponseBody: resources.Application{}, 48 AppendToList: func(item interface{}) error { 49 apps = append(apps, item.(resources.Application)) 50 return nil 51 }, 52 }) 53 54 return apps, warnings, err 55 } 56 57 // UpdateApplication updates an application with the given settings. 58 func (client *Client) UpdateApplication(app resources.Application) (resources.Application, Warnings, error) { 59 var responseBody resources.Application 60 61 _, warnings, err := client.MakeRequest(RequestParams{ 62 RequestName: internal.PatchApplicationRequest, 63 URIParams: internal.Params{"app_guid": app.GUID}, 64 RequestBody: app, 65 ResponseBody: &responseBody, 66 }) 67 68 return responseBody, warnings, err 69 } 70 71 // UpdateApplicationName updates an application with the new name given 72 func (client *Client) UpdateApplicationName(newAppName string, appGUID string) (resources.Application, Warnings, error) { 73 var responseBody resources.Application 74 _, warnings, err := client.MakeRequest(RequestParams{ 75 RequestName: internal.PatchApplicationRequest, 76 URIParams: internal.Params{"app_guid": appGUID}, 77 RequestBody: resources.ApplicationNameOnly{Name: newAppName}, 78 ResponseBody: &responseBody, 79 }) 80 81 return responseBody, warnings, err 82 } 83 84 // UpdateApplicationRestart restarts the given application. 85 func (client *Client) UpdateApplicationRestart(appGUID string) (resources.Application, Warnings, error) { 86 var responseBody resources.Application 87 88 _, warnings, err := client.MakeRequest(RequestParams{ 89 RequestName: internal.PostApplicationActionRestartRequest, 90 URIParams: internal.Params{"app_guid": appGUID}, 91 ResponseBody: &responseBody, 92 }) 93 94 return responseBody, warnings, err 95 } 96 97 // UpdateApplicationStart starts the given application. 98 func (client *Client) UpdateApplicationStart(appGUID string) (resources.Application, Warnings, error) { 99 var responseBody resources.Application 100 101 _, warnings, err := client.MakeRequest(RequestParams{ 102 RequestName: internal.PostApplicationActionStartRequest, 103 URIParams: internal.Params{"app_guid": appGUID}, 104 ResponseBody: &responseBody, 105 }) 106 107 return responseBody, warnings, err 108 } 109 110 // UpdateApplicationStop stops the given application. 111 func (client *Client) UpdateApplicationStop(appGUID string) (resources.Application, Warnings, error) { 112 var responseBody resources.Application 113 114 _, warnings, err := client.MakeRequest(RequestParams{ 115 RequestName: internal.PostApplicationActionStopRequest, 116 URIParams: internal.Params{"app_guid": appGUID}, 117 ResponseBody: &responseBody, 118 }) 119 120 return responseBody, warnings, err 121 }