porter_app.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784
  1. package client
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/porter-dev/porter/api/server/handlers/porter_app"
  6. "github.com/porter-dev/porter/internal/models"
  7. appInternal "github.com/porter-dev/porter/internal/porter_app"
  8. "github.com/porter-dev/porter/api/types"
  9. )
  10. func (c *Client) NewGetPorterApp(
  11. ctx context.Context,
  12. projectID, clusterID uint,
  13. appName string,
  14. ) (*types.PorterApp, error) {
  15. resp := &types.PorterApp{}
  16. err := c.getRequest(
  17. fmt.Sprintf(
  18. "/projects/%d/clusters/%d/applications/%s",
  19. projectID, clusterID, appName,
  20. ),
  21. nil,
  22. resp,
  23. )
  24. return resp, err
  25. }
  26. func (c *Client) NewCreatePorterApp(
  27. ctx context.Context,
  28. projectID, clusterID uint,
  29. appName string,
  30. req *types.CreatePorterAppRequest,
  31. ) (*types.PorterApp, error) {
  32. resp := &types.PorterApp{}
  33. err := c.postRequest(
  34. fmt.Sprintf(
  35. "/projects/%d/clusters/%d/applications/%s",
  36. projectID, clusterID, appName,
  37. ),
  38. req,
  39. resp,
  40. )
  41. return resp, err
  42. }
  43. // NewCreateOrUpdatePorterAppEvent will create a porter app event if one does not exist, or else it will update the existing one if an ID is passed in the object
  44. func (c *Client) NewCreateOrUpdatePorterAppEvent(
  45. ctx context.Context,
  46. projectID, clusterID uint,
  47. appName string,
  48. req *types.CreateOrUpdatePorterAppEventRequest,
  49. ) (types.PorterAppEvent, error) {
  50. resp := &types.PorterAppEvent{}
  51. err := c.postRequest(
  52. fmt.Sprintf(
  53. "/projects/%d/clusters/%d/applications/%s/events",
  54. projectID, clusterID, appName,
  55. ),
  56. req,
  57. resp,
  58. )
  59. return *resp, err
  60. }
  61. // TODO: remove these functions once they are no longer called (check telemetry)
  62. func (c *Client) GetPorterApp(
  63. ctx context.Context,
  64. projectID, clusterID uint,
  65. stackName string,
  66. ) (*types.PorterApp, error) {
  67. resp := &types.PorterApp{}
  68. err := c.getRequest(
  69. fmt.Sprintf(
  70. "/projects/%d/clusters/%d/stacks/%s",
  71. projectID, clusterID, stackName,
  72. ),
  73. nil,
  74. resp,
  75. )
  76. return resp, err
  77. }
  78. func (c *Client) CreatePorterApp(
  79. ctx context.Context,
  80. projectID, clusterID uint,
  81. name string,
  82. req *types.CreatePorterAppRequest,
  83. ) (*types.PorterApp, error) {
  84. resp := &types.PorterApp{}
  85. err := c.postRequest(
  86. fmt.Sprintf(
  87. "/projects/%d/clusters/%d/stacks/%s",
  88. projectID, clusterID, name,
  89. ),
  90. req,
  91. resp,
  92. )
  93. return resp, err
  94. }
  95. // CreateOrUpdatePorterAppEvent will create a porter app event if one does not exist, or else it will update the existing one if an ID is passed in the object
  96. func (c *Client) CreateOrUpdatePorterAppEvent(
  97. ctx context.Context,
  98. projectID, clusterID uint,
  99. name string,
  100. req *types.CreateOrUpdatePorterAppEventRequest,
  101. ) (types.PorterAppEvent, error) {
  102. resp := &types.PorterAppEvent{}
  103. err := c.postRequest(
  104. fmt.Sprintf(
  105. "/projects/%d/clusters/%d/stacks/%s/events",
  106. projectID, clusterID, name,
  107. ),
  108. req,
  109. resp,
  110. )
  111. return *resp, err
  112. }
  113. // ListEnvGroups (List all Env Groups for a given cluster)
  114. func (c *Client) ListEnvGroups(
  115. ctx context.Context,
  116. projectID, clusterID uint,
  117. ) (types.ListEnvironmentGroupsResponse, error) {
  118. resp := &types.ListEnvironmentGroupsResponse{}
  119. err := c.getRequest(
  120. fmt.Sprintf(
  121. "/projects/%d/clusters/%d/environment-groups",
  122. projectID, clusterID,
  123. ),
  124. nil,
  125. resp,
  126. )
  127. return *resp, err
  128. }
  129. // ParseYAML takes in a base64 encoded porter yaml and returns an app proto
  130. func (c *Client) ParseYAML(
  131. ctx context.Context,
  132. projectID, clusterID uint,
  133. b64Yaml string,
  134. appName string,
  135. ) (*porter_app.ParsePorterYAMLToProtoResponse, error) {
  136. resp := &porter_app.ParsePorterYAMLToProtoResponse{}
  137. req := &porter_app.ParsePorterYAMLToProtoRequest{
  138. B64Yaml: b64Yaml,
  139. AppName: appName,
  140. }
  141. err := c.postRequest(
  142. fmt.Sprintf(
  143. "/projects/%d/clusters/%d/apps/parse",
  144. projectID, clusterID,
  145. ),
  146. req,
  147. resp,
  148. )
  149. return resp, err
  150. }
  151. // GetAppManifests returns the manifests for a given app based on the latest successful app revision
  152. func (c *Client) GetAppManifests(
  153. ctx context.Context,
  154. projectID, clusterID uint,
  155. appName string,
  156. ) (*porter_app.AppManifestsResponse, error) {
  157. resp := &porter_app.AppManifestsResponse{}
  158. err := c.getRequest(
  159. fmt.Sprintf(
  160. "/projects/%d/clusters/%d/apps/%s/manifests",
  161. projectID, clusterID, appName,
  162. ),
  163. nil,
  164. resp,
  165. )
  166. return resp, err
  167. }
  168. // UpdateAppInput is the input struct to UpdateApp
  169. type UpdateAppInput struct {
  170. ProjectID uint
  171. ClusterID uint
  172. Name string
  173. ImageTagOverride string
  174. GitSource porter_app.GitSource
  175. DeploymentTargetId string
  176. CommitSHA string
  177. AppRevisionID string
  178. Base64AppProto string
  179. Base64PorterYAML string
  180. IsEnvOverride bool
  181. WithPredeploy bool
  182. Exact bool
  183. }
  184. // UpdateApp updates a porter app
  185. func (c *Client) UpdateApp(
  186. ctx context.Context,
  187. inp UpdateAppInput,
  188. ) (*porter_app.UpdateAppResponse, error) {
  189. resp := &porter_app.UpdateAppResponse{}
  190. req := &porter_app.UpdateAppRequest{
  191. Name: inp.Name,
  192. GitSource: inp.GitSource,
  193. DeploymentTargetId: inp.DeploymentTargetId,
  194. CommitSHA: inp.CommitSHA,
  195. ImageTagOverride: inp.ImageTagOverride,
  196. AppRevisionID: inp.AppRevisionID,
  197. Base64AppProto: inp.Base64AppProto,
  198. Base64PorterYAML: inp.Base64PorterYAML,
  199. IsEnvOverride: inp.IsEnvOverride,
  200. WithPredeploy: inp.WithPredeploy,
  201. Exact: inp.Exact,
  202. }
  203. err := c.postRequest(
  204. fmt.Sprintf(
  205. "/projects/%d/clusters/%d/apps/update",
  206. inp.ProjectID, inp.ClusterID,
  207. ),
  208. req,
  209. resp,
  210. )
  211. return resp, err
  212. }
  213. // DefaultDeploymentTarget returns the default deployment target for a given project and cluster
  214. func (c *Client) DefaultDeploymentTarget(
  215. ctx context.Context,
  216. projectID, clusterID uint,
  217. ) (*porter_app.DefaultDeploymentTargetResponse, error) {
  218. resp := &porter_app.DefaultDeploymentTargetResponse{}
  219. req := &porter_app.DefaultDeploymentTargetRequest{}
  220. err := c.getRequest(
  221. fmt.Sprintf(
  222. "/projects/%d/clusters/%d/default-deployment-target",
  223. projectID, clusterID,
  224. ),
  225. req,
  226. resp,
  227. )
  228. return resp, err
  229. }
  230. // CurrentAppRevisionInput is the input struct to CurrentAppRevision
  231. type CurrentAppRevisionInput struct {
  232. ProjectID uint
  233. ClusterID uint
  234. AppName string
  235. // DeploymentTargetName is the name of the deployment target to get the current app revision for. One of this or DeploymentTargetID must be set.
  236. DeploymentTargetName string
  237. // DeploymentTargetID is the id of the deployment target to get the current app revision for. One of this or DeploymentTargetName must be set.
  238. DeploymentTargetID string
  239. }
  240. // CurrentAppRevision returns the currently deployed app revision for a given project, app name and deployment target
  241. func (c *Client) CurrentAppRevision(
  242. ctx context.Context,
  243. input CurrentAppRevisionInput,
  244. ) (*porter_app.LatestAppRevisionResponse, error) {
  245. resp := &porter_app.LatestAppRevisionResponse{}
  246. req := &porter_app.LatestAppRevisionRequest{
  247. DeploymentTargetName: input.DeploymentTargetName,
  248. DeploymentTargetID: input.DeploymentTargetID,
  249. }
  250. err := c.getRequest(
  251. fmt.Sprintf(
  252. "/projects/%d/clusters/%d/apps/%s/latest",
  253. input.ProjectID, input.ClusterID, input.AppName,
  254. ),
  255. req,
  256. resp,
  257. )
  258. return resp, err
  259. }
  260. // CreatePorterAppDBEntryInput is the input struct to CreatePorterAppDBEntry
  261. type CreatePorterAppDBEntryInput struct {
  262. AppName string
  263. GitRepoName string
  264. GitRepoID uint
  265. GitBranch string
  266. ImageRepository string
  267. PorterYamlPath string
  268. ImageTag string
  269. Local bool
  270. DeploymentTargetID string
  271. }
  272. // CreatePorterAppDBEntry creates an entry in the porter app
  273. func (c *Client) CreatePorterAppDBEntry(
  274. ctx context.Context,
  275. projectID uint, clusterID uint,
  276. inp CreatePorterAppDBEntryInput,
  277. ) error {
  278. var sourceType appInternal.SourceType
  279. var image *appInternal.Image
  280. if inp.Local {
  281. sourceType = appInternal.SourceType_Local
  282. }
  283. if inp.GitRepoName != "" {
  284. sourceType = appInternal.SourceType_Github
  285. }
  286. if inp.ImageRepository != "" {
  287. sourceType = appInternal.SourceType_DockerRegistry
  288. image = &appInternal.Image{
  289. Repository: inp.ImageRepository,
  290. Tag: inp.ImageTag,
  291. }
  292. }
  293. req := &porter_app.CreateAppRequest{
  294. Name: inp.AppName,
  295. SourceType: sourceType,
  296. GitSource: porter_app.GitSource{
  297. GitBranch: inp.GitBranch,
  298. GitRepoName: inp.GitRepoName,
  299. GitRepoID: inp.GitRepoID,
  300. },
  301. Image: image,
  302. PorterYamlPath: inp.PorterYamlPath,
  303. DeploymentTargetID: inp.DeploymentTargetID,
  304. }
  305. err := c.postRequest(
  306. fmt.Sprintf(
  307. "/projects/%d/clusters/%d/apps/create",
  308. projectID, clusterID,
  309. ),
  310. req,
  311. &types.PorterApp{},
  312. )
  313. return err
  314. }
  315. // CreateSubdomain returns a subdomain for a given service that point to the ingress-nginx service in the cluster
  316. func (c *Client) CreateSubdomain(
  317. ctx context.Context,
  318. projectID uint, clusterID uint,
  319. appName string, serviceName string,
  320. ) (*porter_app.CreateSubdomainResponse, error) {
  321. resp := &porter_app.CreateSubdomainResponse{}
  322. req := &porter_app.CreateSubdomainRequest{
  323. ServiceName: serviceName,
  324. }
  325. err := c.postRequest(
  326. fmt.Sprintf(
  327. "/projects/%d/clusters/%d/apps/%s/subdomain",
  328. projectID, clusterID, appName,
  329. ),
  330. req,
  331. resp,
  332. )
  333. return resp, err
  334. }
  335. // PredeployStatus checks the current status of a predeploy job for an app revision
  336. func (c *Client) PredeployStatus(
  337. ctx context.Context,
  338. projectID uint, clusterID uint,
  339. appName string, appRevisionId string,
  340. ) (*porter_app.PredeployStatusResponse, error) {
  341. resp := &porter_app.PredeployStatusResponse{}
  342. err := c.getRequest(
  343. fmt.Sprintf(
  344. "/projects/%d/clusters/%d/apps/%s/%s/predeploy-status",
  345. projectID, clusterID, appName, appRevisionId,
  346. ),
  347. nil,
  348. resp,
  349. )
  350. if resp.Status == "" {
  351. return nil, fmt.Errorf("no predeploy status found")
  352. }
  353. return resp, err
  354. }
  355. // GetRevision returns an app revision
  356. func (c *Client) GetRevision(
  357. ctx context.Context,
  358. projectID uint, clusterID uint,
  359. appName string, appRevisionId string,
  360. ) (*porter_app.GetAppRevisionResponse, error) {
  361. resp := &porter_app.GetAppRevisionResponse{}
  362. err := c.getRequest(
  363. fmt.Sprintf(
  364. "/projects/%d/clusters/%d/apps/%s/revisions/%s",
  365. projectID, clusterID, appName, appRevisionId,
  366. ),
  367. nil,
  368. resp,
  369. )
  370. return resp, err
  371. }
  372. // GetRevisionStatus returns the status of an app revision
  373. func (c *Client) GetRevisionStatus(
  374. ctx context.Context,
  375. projectID uint, clusterID uint,
  376. appName string, appRevisionId string,
  377. ) (*porter_app.GetAppRevisionStatusResponse, error) {
  378. resp := &porter_app.GetAppRevisionStatusResponse{}
  379. err := c.getRequest(
  380. fmt.Sprintf(
  381. "/projects/%d/clusters/%d/apps/%s/revisions/%s/status",
  382. projectID, clusterID, appName, appRevisionId,
  383. ),
  384. nil,
  385. resp,
  386. )
  387. return resp, err
  388. }
  389. // UpdateRevisionStatus updates the status of an app revision
  390. func (c *Client) UpdateRevisionStatus(
  391. ctx context.Context,
  392. projectID uint, clusterID uint,
  393. appName string, appRevisionId string,
  394. status models.AppRevisionStatus,
  395. ) (*porter_app.UpdateAppRevisionStatusResponse, error) {
  396. resp := &porter_app.UpdateAppRevisionStatusResponse{}
  397. req := &porter_app.UpdateAppRevisionStatusRequest{
  398. Status: status,
  399. }
  400. err := c.postRequest(
  401. fmt.Sprintf(
  402. "/projects/%d/clusters/%d/apps/%s/revisions/%s",
  403. projectID, clusterID, appName, appRevisionId,
  404. ),
  405. req,
  406. resp,
  407. )
  408. return resp, err
  409. }
  410. // GetBuildEnv returns the build environment for a given app proto
  411. func (c *Client) GetBuildEnv(
  412. ctx context.Context,
  413. projectID uint, clusterID uint,
  414. appName string, appRevisionId string,
  415. ) (*porter_app.GetBuildEnvResponse, error) {
  416. resp := &porter_app.GetBuildEnvResponse{}
  417. err := c.getRequest(
  418. fmt.Sprintf(
  419. "/projects/%d/clusters/%d/apps/%s/revisions/%s/build-env",
  420. projectID, clusterID, appName, appRevisionId,
  421. ),
  422. nil,
  423. resp,
  424. )
  425. return resp, err
  426. }
  427. // GetAppEnvVariables returns all env variables for a given app
  428. func (c *Client) GetAppEnvVariables(
  429. ctx context.Context,
  430. projectID uint, clusterID uint,
  431. appName string,
  432. deploymentTargetName string,
  433. ) (*porter_app.AppEnvVariablesResponse, error) {
  434. resp := &porter_app.AppEnvVariablesResponse{}
  435. req := &porter_app.AppEnvVariablesRequest{
  436. DeploymentTargetName: deploymentTargetName,
  437. }
  438. err := c.getRequest(
  439. fmt.Sprintf(
  440. "/projects/%d/clusters/%d/apps/%s/env-variables",
  441. projectID, clusterID, appName,
  442. ),
  443. req,
  444. resp,
  445. )
  446. return resp, err
  447. }
  448. // GetBuildFromRevision returns the build environment for a given app proto
  449. func (c *Client) GetBuildFromRevision(
  450. ctx context.Context,
  451. projectID uint, clusterID uint,
  452. appName string, appRevisionId string,
  453. ) (*porter_app.GetBuildFromRevisionResponse, error) {
  454. resp := &porter_app.GetBuildFromRevisionResponse{}
  455. err := c.getRequest(
  456. fmt.Sprintf(
  457. "/projects/%d/clusters/%d/apps/%s/revisions/%s/build",
  458. projectID, clusterID, appName, appRevisionId,
  459. ),
  460. nil,
  461. resp,
  462. )
  463. return resp, err
  464. }
  465. // ReportRevisionStatusInput is the input struct to ReportRevisionStatus
  466. type ReportRevisionStatusInput struct {
  467. ProjectID uint
  468. ClusterID uint
  469. AppName string
  470. AppRevisionID string
  471. PRNumber int
  472. CommitSHA string
  473. }
  474. // ReportRevisionStatus reports the status of an app revision to external services
  475. func (c *Client) ReportRevisionStatus(
  476. ctx context.Context,
  477. inp ReportRevisionStatusInput,
  478. ) (*porter_app.ReportRevisionStatusResponse, error) {
  479. resp := &porter_app.ReportRevisionStatusResponse{}
  480. req := &porter_app.ReportRevisionStatusRequest{
  481. PRNumber: inp.PRNumber,
  482. CommitSHA: inp.CommitSHA,
  483. }
  484. err := c.postRequest(
  485. fmt.Sprintf(
  486. "/projects/%d/clusters/%d/apps/%s/revisions/%s/status",
  487. inp.ProjectID, inp.ClusterID, inp.AppName, inp.AppRevisionID,
  488. ),
  489. req,
  490. resp,
  491. )
  492. return resp, err
  493. }
  494. // CreateOrUpdateAppEnvironment updates the app environment group and creates it if it doesn't exist
  495. func (c *Client) CreateOrUpdateAppEnvironment(
  496. ctx context.Context,
  497. projectID uint, clusterID uint,
  498. appName string,
  499. deploymentTargetID string,
  500. variables map[string]string,
  501. secrets map[string]string,
  502. Base64AppProto string,
  503. ) (*porter_app.UpdateAppEnvironmentResponse, error) {
  504. resp := &porter_app.UpdateAppEnvironmentResponse{}
  505. req := &porter_app.UpdateAppEnvironmentRequest{
  506. DeploymentTargetID: deploymentTargetID,
  507. Variables: variables,
  508. Secrets: secrets,
  509. HardUpdate: false,
  510. Base64AppProto: Base64AppProto,
  511. }
  512. err := c.postRequest(
  513. fmt.Sprintf(
  514. "/projects/%d/clusters/%d/apps/%s/update-environment",
  515. projectID, clusterID, appName,
  516. ),
  517. req,
  518. resp,
  519. )
  520. return resp, err
  521. }
  522. // PorterYamlV2Pods gets all pods for a given deployment target id and app name
  523. func (c *Client) PorterYamlV2Pods(
  524. ctx context.Context,
  525. projectID, clusterID uint,
  526. porterAppName string,
  527. deploymentTargetName string,
  528. ) (*types.GetReleaseAllPodsResponse, error) {
  529. req := &porter_app.PodStatusRequest{
  530. DeploymentTargetName: deploymentTargetName,
  531. }
  532. resp := &types.GetReleaseAllPodsResponse{}
  533. err := c.getRequest(
  534. fmt.Sprintf(
  535. "/projects/%d/clusters/%d/apps/%s/pods",
  536. projectID, clusterID,
  537. porterAppName,
  538. ),
  539. req,
  540. resp,
  541. )
  542. return resp, err
  543. }
  544. // UpdateImage updates the image for a porter app (porter yaml v2 only)
  545. func (c *Client) UpdateImage(
  546. ctx context.Context,
  547. projectID, clusterID uint,
  548. appName, deploymentTargetName, tag string,
  549. ) (*porter_app.UpdateImageResponse, error) {
  550. req := &porter_app.UpdateImageRequest{
  551. Tag: tag,
  552. DeploymentTargetName: deploymentTargetName,
  553. }
  554. resp := &porter_app.UpdateImageResponse{}
  555. err := c.postRequest(
  556. fmt.Sprintf(
  557. "/projects/%d/clusters/%d/apps/%s/update-image",
  558. projectID, clusterID, appName,
  559. ),
  560. &req,
  561. resp,
  562. )
  563. return resp, err
  564. }
  565. // ListAppRevisions lists the last ten app revisions for a given app
  566. func (c *Client) ListAppRevisions(
  567. ctx context.Context,
  568. projectID, clusterID uint,
  569. appName string,
  570. deploymentTargetID string,
  571. ) (*porter_app.ListAppRevisionsResponse, error) {
  572. resp := &porter_app.ListAppRevisionsResponse{}
  573. req := &porter_app.ListAppRevisionsRequest{
  574. DeploymentTargetID: deploymentTargetID,
  575. }
  576. err := c.getRequest(
  577. fmt.Sprintf(
  578. "/projects/%d/clusters/%d/apps/%s/revisions",
  579. projectID, clusterID,
  580. appName,
  581. ),
  582. req,
  583. resp,
  584. )
  585. return resp, err
  586. }
  587. // RollbackRevision reverts an app to a previous revision
  588. func (c *Client) RollbackRevision(
  589. ctx context.Context,
  590. projectID, clusterID uint,
  591. appName string,
  592. deploymentTargetName string,
  593. ) (*porter_app.RollbackAppRevisionResponse, error) {
  594. resp := &porter_app.RollbackAppRevisionResponse{}
  595. req := &porter_app.RollbackAppRevisionRequest{
  596. DeploymentTargetName: deploymentTargetName,
  597. }
  598. err := c.postRequest(
  599. fmt.Sprintf(
  600. "/projects/%d/clusters/%d/apps/%s/rollback",
  601. projectID, clusterID,
  602. appName,
  603. ),
  604. req,
  605. resp,
  606. )
  607. return resp, err
  608. }
  609. // RunAppJob runs a job for an app
  610. func (c *Client) RunAppJob(
  611. ctx context.Context,
  612. projectID, clusterID uint,
  613. appName string, jobName string,
  614. deploymentTargetName string,
  615. ) (*porter_app.RunAppJobResponse, error) {
  616. resp := &porter_app.RunAppJobResponse{}
  617. req := &porter_app.RunAppJobRequest{
  618. ServiceName: jobName,
  619. DeploymentTargetName: deploymentTargetName,
  620. }
  621. err := c.postRequest(
  622. fmt.Sprintf(
  623. "/projects/%d/clusters/%d/apps/%s/run",
  624. projectID, clusterID,
  625. appName,
  626. ),
  627. req,
  628. resp,
  629. )
  630. return resp, err
  631. }
  632. // RunAppJobStatusInput contains all the information necessary to check the status of a job
  633. type RunAppJobStatusInput struct {
  634. // AppName is the name of the app associated with the job
  635. AppName string
  636. // Cluster is the id of the cluster against which to retrieve a helm agent for
  637. ClusterID uint
  638. // DeploymentTargetName is the id of the deployment target the job was run against
  639. DeploymentTargetName string
  640. // ServiceName is the name of the app service that was triggered
  641. ServiceName string
  642. // JobRunID is the UID returned from the /apps/{porter_app_name}/run endpoint
  643. JobRunID string
  644. // ProjectID is the project in which the cluster exists
  645. ProjectID uint
  646. }
  647. // RunAppJobStatus gets the status for a job app run
  648. func (c *Client) RunAppJobStatus(
  649. ctx context.Context,
  650. input RunAppJobStatusInput,
  651. ) (*porter_app.AppJobRunStatusResponse, error) {
  652. resp := &porter_app.AppJobRunStatusResponse{}
  653. req := &porter_app.AppJobRunStatusRequest{
  654. DeploymentTargetName: input.DeploymentTargetName,
  655. JobRunID: input.JobRunID,
  656. ServiceName: input.ServiceName,
  657. }
  658. err := c.getRequest(
  659. fmt.Sprintf(
  660. "/projects/%d/clusters/%d/apps/%s/run-status",
  661. input.ProjectID, input.ClusterID,
  662. input.AppName,
  663. ),
  664. req,
  665. resp,
  666. )
  667. return resp, err
  668. }