git_installation.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  1. package router
  2. import (
  3. "fmt"
  4. "github.com/go-chi/chi"
  5. "github.com/porter-dev/porter/api/server/handlers/environment"
  6. "github.com/porter-dev/porter/api/server/handlers/gitinstallation"
  7. "github.com/porter-dev/porter/api/server/shared"
  8. "github.com/porter-dev/porter/api/server/shared/config"
  9. "github.com/porter-dev/porter/api/server/shared/router"
  10. "github.com/porter-dev/porter/api/types"
  11. )
  12. func NewGitInstallationScopedRegisterer(children ...*router.Registerer) *router.Registerer {
  13. return &router.Registerer{
  14. GetRoutes: GetGitInstallationScopedRoutes,
  15. Children: children,
  16. }
  17. }
  18. func GetGitInstallationScopedRoutes(
  19. r chi.Router,
  20. config *config.Config,
  21. basePath *types.Path,
  22. factory shared.APIEndpointFactory,
  23. children ...*router.Registerer,
  24. ) []*router.Route {
  25. routes, projPath := getGitInstallationRoutes(r, config, basePath, factory)
  26. if len(children) > 0 {
  27. r.Route(projPath.RelativePath, func(r chi.Router) {
  28. for _, child := range children {
  29. childRoutes := child.GetRoutes(r, config, basePath, factory, child.Children...)
  30. routes = append(routes, childRoutes...)
  31. }
  32. })
  33. }
  34. return routes
  35. }
  36. func getGitInstallationRoutes(
  37. r chi.Router,
  38. config *config.Config,
  39. basePath *types.Path,
  40. factory shared.APIEndpointFactory,
  41. ) ([]*router.Route, *types.Path) {
  42. relPath := "/gitrepos/{git_installation_id}"
  43. newPath := &types.Path{
  44. Parent: basePath,
  45. RelativePath: relPath,
  46. }
  47. routes := make([]*router.Route, 0)
  48. // GET /api/projects/{project_id}/gitrepos/{git_installation_id} -> gitinstallation.NewGitInstallationGetHandler
  49. getEndpoint := factory.NewAPIEndpoint(
  50. &types.APIRequestMetadata{
  51. Verb: types.APIVerbGet,
  52. Method: types.HTTPVerbGet,
  53. Path: &types.Path{
  54. Parent: basePath,
  55. RelativePath: relPath,
  56. },
  57. Scopes: []types.PermissionScope{
  58. types.UserScope,
  59. types.ProjectScope,
  60. types.GitInstallationScope,
  61. },
  62. },
  63. )
  64. getHandler := gitinstallation.NewGitInstallationGetHandler(
  65. config,
  66. factory.GetResultWriter(),
  67. )
  68. routes = append(routes, &router.Route{
  69. Endpoint: getEndpoint,
  70. Handler: getHandler,
  71. Router: r,
  72. })
  73. // GET /api/projects/{project_id}/gitrepos/{git_installation_id}/permissions -> gitinstallation.NewGithubGetPermissionsHandler
  74. getPermissionsEndpoint := factory.NewAPIEndpoint(
  75. &types.APIRequestMetadata{
  76. Verb: types.APIVerbGet,
  77. Method: types.HTTPVerbGet,
  78. Path: &types.Path{
  79. Parent: basePath,
  80. RelativePath: relPath + "/permissions",
  81. },
  82. Scopes: []types.PermissionScope{
  83. types.UserScope,
  84. types.ProjectScope,
  85. types.GitInstallationScope,
  86. },
  87. },
  88. )
  89. getPermissionsHandler := gitinstallation.NewGithubGetPermissionsHandler(
  90. config,
  91. factory.GetDecoderValidator(),
  92. factory.GetResultWriter(),
  93. )
  94. routes = append(routes, &router.Route{
  95. Endpoint: getPermissionsEndpoint,
  96. Handler: getPermissionsHandler,
  97. Router: r,
  98. })
  99. if config.ServerConf.GithubIncomingWebhookSecret != "" {
  100. // POST /api/projects/{project_id}/gitrepos/{git_installation_id}/{owner}/{name}/clusters/{cluster_id}/environment ->
  101. // environment.NewCreateEnvironmentHandler
  102. createEnvironmentEndpoint := factory.NewAPIEndpoint(
  103. &types.APIRequestMetadata{
  104. Verb: types.APIVerbCreate,
  105. Method: types.HTTPVerbPost,
  106. Path: &types.Path{
  107. Parent: basePath,
  108. RelativePath: fmt.Sprintf(
  109. "%s/{%s}/{%s}/clusters/{cluster_id}/environment",
  110. relPath,
  111. types.URLParamGitRepoOwner,
  112. types.URLParamGitRepoName,
  113. ),
  114. },
  115. Scopes: []types.PermissionScope{
  116. types.UserScope,
  117. types.ProjectScope,
  118. types.GitInstallationScope,
  119. types.ClusterScope,
  120. },
  121. },
  122. )
  123. createEnvironmentHandler := environment.NewCreateEnvironmentHandler(
  124. config,
  125. factory.GetDecoderValidator(),
  126. factory.GetResultWriter(),
  127. )
  128. routes = append(routes, &router.Route{
  129. Endpoint: createEnvironmentEndpoint,
  130. Handler: createEnvironmentHandler,
  131. Router: r,
  132. })
  133. // POST /api/projects/{project_id}/gitrepos/{git_installation_id}/{owner}/{name}/clusters/{cluster_id}/deployment ->
  134. // environment.NewCreateDeploymentHandler
  135. createDeploymentEndpoint := factory.NewAPIEndpoint(
  136. &types.APIRequestMetadata{
  137. Verb: types.APIVerbCreate,
  138. Method: types.HTTPVerbPost,
  139. Path: &types.Path{
  140. Parent: basePath,
  141. RelativePath: fmt.Sprintf(
  142. "%s/{%s}/{%s}/clusters/{cluster_id}/deployment",
  143. relPath,
  144. types.URLParamGitRepoOwner,
  145. types.URLParamGitRepoName,
  146. ),
  147. },
  148. Scopes: []types.PermissionScope{
  149. types.UserScope,
  150. types.ProjectScope,
  151. types.GitInstallationScope,
  152. types.ClusterScope,
  153. },
  154. },
  155. )
  156. createDeploymentHandler := environment.NewCreateDeploymentHandler(
  157. config,
  158. factory.GetDecoderValidator(),
  159. factory.GetResultWriter(),
  160. )
  161. routes = append(routes, &router.Route{
  162. Endpoint: createDeploymentEndpoint,
  163. Handler: createDeploymentHandler,
  164. Router: r,
  165. })
  166. // GET /api/projects/{project_id}/gitrepos/{git_installation_id}/{owner}/{name}/clusters/{cluster_id}/deployment ->
  167. // environment.NewGetDeploymentHandler
  168. getDeploymentEndpoint := factory.NewAPIEndpoint(
  169. &types.APIRequestMetadata{
  170. Verb: types.APIVerbGet,
  171. Method: types.HTTPVerbGet,
  172. Path: &types.Path{
  173. Parent: basePath,
  174. RelativePath: fmt.Sprintf(
  175. "%s/{%s}/{%s}/clusters/{cluster_id}/deployment",
  176. relPath,
  177. types.URLParamGitRepoOwner,
  178. types.URLParamGitRepoName,
  179. ),
  180. },
  181. Scopes: []types.PermissionScope{
  182. types.UserScope,
  183. types.ProjectScope,
  184. types.GitInstallationScope,
  185. types.ClusterScope,
  186. },
  187. },
  188. )
  189. getDeploymentHandler := environment.NewGetDeploymentHandler(
  190. config,
  191. factory.GetDecoderValidator(),
  192. factory.GetResultWriter(),
  193. )
  194. routes = append(routes, &router.Route{
  195. Endpoint: getDeploymentEndpoint,
  196. Handler: getDeploymentHandler,
  197. Router: r,
  198. })
  199. // GET /api/projects/{project_id}/gitrepos/{git_installation_id}/{owner}/{name}/clusters/{cluster_id}/deployments ->
  200. // environment.NewCreateDeploymentHandler
  201. listDeploymentsEndpoint := factory.NewAPIEndpoint(
  202. &types.APIRequestMetadata{
  203. Verb: types.APIVerbGet,
  204. Method: types.HTTPVerbGet,
  205. Path: &types.Path{
  206. Parent: basePath,
  207. RelativePath: fmt.Sprintf(
  208. "%s/{%s}/{%s}/clusters/{cluster_id}/deployments",
  209. relPath,
  210. types.URLParamGitRepoOwner,
  211. types.URLParamGitRepoName,
  212. ),
  213. },
  214. Scopes: []types.PermissionScope{
  215. types.UserScope,
  216. types.ProjectScope,
  217. types.GitInstallationScope,
  218. types.ClusterScope,
  219. },
  220. },
  221. )
  222. listDeploymentsHandler := environment.NewListDeploymentsHandler(
  223. config,
  224. factory.GetDecoderValidator(),
  225. factory.GetResultWriter(),
  226. )
  227. routes = append(routes, &router.Route{
  228. Endpoint: listDeploymentsEndpoint,
  229. Handler: listDeploymentsHandler,
  230. Router: r,
  231. })
  232. // POST /api/projects/{project_id}/gitrepos/{git_installation_id}/{owner}/{name}/clusters/{cluster_id}/deployment/finalize ->
  233. // environment.NewFinalizeDeploymentHandler
  234. finalizeDeploymentEndpoint := factory.NewAPIEndpoint(
  235. &types.APIRequestMetadata{
  236. Verb: types.APIVerbCreate,
  237. Method: types.HTTPVerbPost,
  238. Path: &types.Path{
  239. Parent: basePath,
  240. RelativePath: fmt.Sprintf(
  241. "%s/{%s}/{%s}/clusters/{cluster_id}/deployment/finalize",
  242. relPath,
  243. types.URLParamGitRepoOwner,
  244. types.URLParamGitRepoName,
  245. ),
  246. },
  247. Scopes: []types.PermissionScope{
  248. types.UserScope,
  249. types.ProjectScope,
  250. types.GitInstallationScope,
  251. types.ClusterScope,
  252. },
  253. },
  254. )
  255. finalizeDeploymentHandler := environment.NewFinalizeDeploymentHandler(
  256. config,
  257. factory.GetDecoderValidator(),
  258. factory.GetResultWriter(),
  259. )
  260. routes = append(routes, &router.Route{
  261. Endpoint: finalizeDeploymentEndpoint,
  262. Handler: finalizeDeploymentHandler,
  263. Router: r,
  264. })
  265. // POST /api/projects/{project_id}/gitrepos/{git_installation_id}/{owner}/{name}/clusters/{cluster_id}/deployment/update ->
  266. // environment.NewFinalizeDeploymentHandler
  267. updateDeploymentEndpoint := factory.NewAPIEndpoint(
  268. &types.APIRequestMetadata{
  269. Verb: types.APIVerbUpdate,
  270. Method: types.HTTPVerbPost,
  271. Path: &types.Path{
  272. Parent: basePath,
  273. RelativePath: fmt.Sprintf(
  274. "%s/{%s}/{%s}/clusters/{cluster_id}/deployment/update",
  275. relPath,
  276. types.URLParamGitRepoOwner,
  277. types.URLParamGitRepoName,
  278. ),
  279. },
  280. Scopes: []types.PermissionScope{
  281. types.UserScope,
  282. types.ProjectScope,
  283. types.GitInstallationScope,
  284. types.ClusterScope,
  285. },
  286. },
  287. )
  288. updateDeploymentHandler := environment.NewUpdateDeploymentHandler(
  289. config,
  290. factory.GetDecoderValidator(),
  291. factory.GetResultWriter(),
  292. )
  293. routes = append(routes, &router.Route{
  294. Endpoint: updateDeploymentEndpoint,
  295. Handler: updateDeploymentHandler,
  296. Router: r,
  297. })
  298. // POST /api/projects/{project_id}/gitrepos/{git_installation_id}/{owner}/{name}/clusters/{cluster_id}/deployment/update/status ->
  299. // environment.NewUpdateDeploymentStatusHandler
  300. updateDeploymentStatusEndpoint := factory.NewAPIEndpoint(
  301. &types.APIRequestMetadata{
  302. Verb: types.APIVerbUpdate,
  303. Method: types.HTTPVerbPost,
  304. Path: &types.Path{
  305. Parent: basePath,
  306. RelativePath: fmt.Sprintf(
  307. "%s/{%s}/{%s}/clusters/{cluster_id}/deployment/update/status",
  308. relPath,
  309. types.URLParamGitRepoOwner,
  310. types.URLParamGitRepoName,
  311. ),
  312. },
  313. Scopes: []types.PermissionScope{
  314. types.UserScope,
  315. types.ProjectScope,
  316. types.GitInstallationScope,
  317. types.ClusterScope,
  318. },
  319. },
  320. )
  321. updateDeploymentStatusHandler := environment.NewUpdateDeploymentStatusHandler(
  322. config,
  323. factory.GetDecoderValidator(),
  324. factory.GetResultWriter(),
  325. )
  326. routes = append(routes, &router.Route{
  327. Endpoint: updateDeploymentStatusEndpoint,
  328. Handler: updateDeploymentStatusHandler,
  329. Router: r,
  330. })
  331. // POST /api/projects/{project_id}/gitrepos/{git_installation_id}/{owner}/{name}/clusters/{cluster_id}/deployment/finalize_errors ->
  332. // environment.NewFinalizeDeploymentWithErrorsHandler
  333. finalizeDeploymentWithErrorsEndpoint := factory.NewAPIEndpoint(
  334. &types.APIRequestMetadata{
  335. Verb: types.APIVerbUpdate,
  336. Method: types.HTTPVerbPost,
  337. Path: &types.Path{
  338. Parent: basePath,
  339. RelativePath: fmt.Sprintf(
  340. "%s/{%s}/{%s}/clusters/{cluster_id}/deployment/finalize_errors",
  341. relPath,
  342. types.URLParamGitRepoOwner,
  343. types.URLParamGitRepoName,
  344. ),
  345. },
  346. Scopes: []types.PermissionScope{
  347. types.UserScope,
  348. types.ProjectScope,
  349. types.GitInstallationScope,
  350. types.ClusterScope,
  351. },
  352. },
  353. )
  354. finalizeDeploymentWithErrorsHandler := environment.NewFinalizeDeploymentWithErrorsHandler(
  355. config,
  356. factory.GetDecoderValidator(),
  357. factory.GetResultWriter(),
  358. )
  359. routes = append(routes, &router.Route{
  360. Endpoint: finalizeDeploymentWithErrorsEndpoint,
  361. Handler: finalizeDeploymentWithErrorsHandler,
  362. Router: r,
  363. })
  364. // DELETE /api/projects/{project_id}/gitrepos/{git_installation_id}/{owner}/{name}/clusters/{cluster_id}/environment ->
  365. // environment.NewDeleteEnvironmentHandler
  366. deleteEnvironmentEndpoint := factory.NewAPIEndpoint(
  367. &types.APIRequestMetadata{
  368. Verb: types.APIVerbDelete,
  369. Method: types.HTTPVerbDelete,
  370. Path: &types.Path{
  371. Parent: basePath,
  372. RelativePath: fmt.Sprintf(
  373. "%s/{%s}/{%s}/clusters/{cluster_id}/environment",
  374. relPath,
  375. types.URLParamGitRepoOwner,
  376. types.URLParamGitRepoName,
  377. ),
  378. },
  379. Scopes: []types.PermissionScope{
  380. types.UserScope,
  381. types.ProjectScope,
  382. types.GitInstallationScope,
  383. types.ClusterScope,
  384. },
  385. },
  386. )
  387. deleteEnvironmentHandler := environment.NewDeleteEnvironmentHandler(
  388. config,
  389. factory.GetDecoderValidator(),
  390. factory.GetResultWriter(),
  391. )
  392. routes = append(routes, &router.Route{
  393. Endpoint: deleteEnvironmentEndpoint,
  394. Handler: deleteEnvironmentHandler,
  395. Router: r,
  396. })
  397. }
  398. // GET /api/projects/{project_id}/gitrepos/{git_installation_id}/repos ->
  399. // gitinstallation.GithubListReposHandler
  400. listReposEndpoint := factory.NewAPIEndpoint(
  401. &types.APIRequestMetadata{
  402. Verb: types.APIVerbList,
  403. Method: types.HTTPVerbGet,
  404. Path: &types.Path{
  405. Parent: basePath,
  406. RelativePath: relPath + "/repos",
  407. },
  408. Scopes: []types.PermissionScope{
  409. types.UserScope,
  410. types.ProjectScope,
  411. types.GitInstallationScope,
  412. },
  413. },
  414. )
  415. listReposHandler := gitinstallation.NewGithubListReposHandler(
  416. config,
  417. factory.GetResultWriter(),
  418. )
  419. routes = append(routes, &router.Route{
  420. Endpoint: listReposEndpoint,
  421. Handler: listReposHandler,
  422. Router: r,
  423. })
  424. // GET /api/projects/{project_id}/gitrepos/{installation_id}/repos/{kind}/{owner}/{name}/branches ->
  425. // gitinstallation.GithubListBranchesHandler
  426. listBranchesEndpoint := factory.NewAPIEndpoint(
  427. &types.APIRequestMetadata{
  428. Verb: types.APIVerbList,
  429. Method: types.HTTPVerbGet,
  430. Path: &types.Path{
  431. Parent: basePath,
  432. RelativePath: fmt.Sprintf(
  433. "%s/repos/{%s}/{%s}/{%s}/branches",
  434. relPath,
  435. types.URLParamGitKind,
  436. types.URLParamGitRepoOwner,
  437. types.URLParamGitRepoName,
  438. ),
  439. },
  440. Scopes: []types.PermissionScope{
  441. types.UserScope,
  442. types.ProjectScope,
  443. types.GitInstallationScope,
  444. },
  445. },
  446. )
  447. listBranchesHandler := gitinstallation.NewGithubListBranchesHandler(
  448. config,
  449. factory.GetResultWriter(),
  450. )
  451. routes = append(routes, &router.Route{
  452. Endpoint: listBranchesEndpoint,
  453. Handler: listBranchesHandler,
  454. Router: r,
  455. })
  456. // GET /api/projects/{project_id}/gitrepos/{installation_id}/repos/{kind}/{owner}/{name}/{branch}/buildpack/detect ->
  457. // gitinstallation.NewGithubGetBuildpackHandler
  458. getBuildpackEndpoint := factory.NewAPIEndpoint(
  459. &types.APIRequestMetadata{
  460. Verb: types.APIVerbGet,
  461. Method: types.HTTPVerbGet,
  462. Path: &types.Path{
  463. Parent: basePath,
  464. RelativePath: fmt.Sprintf(
  465. "%s/repos/{%s}/{%s}/{%s}/{%s}/buildpack/detect",
  466. relPath,
  467. types.URLParamGitKind,
  468. types.URLParamGitRepoOwner,
  469. types.URLParamGitRepoName,
  470. types.URLParamGitBranch,
  471. ),
  472. },
  473. Scopes: []types.PermissionScope{
  474. types.UserScope,
  475. types.ProjectScope,
  476. types.GitInstallationScope,
  477. },
  478. },
  479. )
  480. getBuildpackHandler := gitinstallation.NewGithubGetBuildpackHandler(
  481. config,
  482. factory.GetDecoderValidator(),
  483. factory.GetResultWriter(),
  484. )
  485. routes = append(routes, &router.Route{
  486. Endpoint: getBuildpackEndpoint,
  487. Handler: getBuildpackHandler,
  488. Router: r,
  489. })
  490. // GET /api/projects/{project_id}/gitrepos/{installation_id}/repos/{kind}/{owner}/{name}/{branch}/contents ->
  491. // gitinstallation.NewGithubGetContentsHandler
  492. getContentsEndpoint := factory.NewAPIEndpoint(
  493. &types.APIRequestMetadata{
  494. Verb: types.APIVerbGet,
  495. Method: types.HTTPVerbGet,
  496. Path: &types.Path{
  497. Parent: basePath,
  498. RelativePath: fmt.Sprintf(
  499. "%s/repos/{%s}/{%s}/{%s}/{%s}/contents",
  500. relPath,
  501. types.URLParamGitKind,
  502. types.URLParamGitRepoOwner,
  503. types.URLParamGitRepoName,
  504. types.URLParamGitBranch,
  505. ),
  506. },
  507. Scopes: []types.PermissionScope{
  508. types.UserScope,
  509. types.ProjectScope,
  510. types.GitInstallationScope,
  511. },
  512. },
  513. )
  514. getContentsHandler := gitinstallation.NewGithubGetContentsHandler(
  515. config,
  516. factory.GetDecoderValidator(),
  517. factory.GetResultWriter(),
  518. )
  519. routes = append(routes, &router.Route{
  520. Endpoint: getContentsEndpoint,
  521. Handler: getContentsHandler,
  522. Router: r,
  523. })
  524. // GET /api/projects/{project_id}/gitrepos/{installation_id}/repos/{kind}/{owner}/{name}/{branch}/procfile ->
  525. // gitinstallation.NewGithubGetProcfileHandler
  526. getProcfileEndpoint := factory.NewAPIEndpoint(
  527. &types.APIRequestMetadata{
  528. Verb: types.APIVerbGet,
  529. Method: types.HTTPVerbGet,
  530. Path: &types.Path{
  531. Parent: basePath,
  532. RelativePath: fmt.Sprintf(
  533. "%s/repos/{%s}/{%s}/{%s}/{%s}/procfile",
  534. relPath,
  535. types.URLParamGitKind,
  536. types.URLParamGitRepoOwner,
  537. types.URLParamGitRepoName,
  538. types.URLParamGitBranch,
  539. ),
  540. },
  541. Scopes: []types.PermissionScope{
  542. types.UserScope,
  543. types.ProjectScope,
  544. types.GitInstallationScope,
  545. },
  546. },
  547. )
  548. getProcfileHandler := gitinstallation.NewGithubGetProcfileHandler(
  549. config,
  550. factory.GetDecoderValidator(),
  551. factory.GetResultWriter(),
  552. )
  553. routes = append(routes, &router.Route{
  554. Endpoint: getProcfileEndpoint,
  555. Handler: getProcfileHandler,
  556. Router: r,
  557. })
  558. // GET /api/projects/{project_id}/gitrepos/{installation_id}/repos/{kind}/{owner}/{name}/{branch}/tarball_url ->
  559. // gitinstallation.NewGithubGetTarballURLHandler
  560. getTarballURLEndpoint := factory.NewAPIEndpoint(
  561. &types.APIRequestMetadata{
  562. Verb: types.APIVerbGet,
  563. Method: types.HTTPVerbGet,
  564. Path: &types.Path{
  565. Parent: basePath,
  566. RelativePath: fmt.Sprintf(
  567. "%s/repos/{%s}/{%s}/{%s}/{%s}/tarball_url",
  568. relPath,
  569. types.URLParamGitKind,
  570. types.URLParamGitRepoOwner,
  571. types.URLParamGitRepoName,
  572. types.URLParamGitBranch,
  573. ),
  574. },
  575. Scopes: []types.PermissionScope{
  576. types.UserScope,
  577. types.ProjectScope,
  578. types.GitInstallationScope,
  579. },
  580. },
  581. )
  582. getTarballURLHandler := gitinstallation.NewGithubGetTarballURLHandler(
  583. config,
  584. factory.GetDecoderValidator(),
  585. factory.GetResultWriter(),
  586. )
  587. routes = append(routes, &router.Route{
  588. Endpoint: getTarballURLEndpoint,
  589. Handler: getTarballURLHandler,
  590. Router: r,
  591. })
  592. // POST /api/projects/{project_id}/gitrepos/{git_installation_id}/{owner}/{name}/clusters/{cluster_id}/rerun_workflow ->
  593. // gitinstallation.NewRerunWorkflowHandler
  594. rerunWorkflowEndpoint := factory.NewAPIEndpoint(
  595. &types.APIRequestMetadata{
  596. Verb: types.APIVerbUpdate,
  597. Method: types.HTTPVerbPost,
  598. Path: &types.Path{
  599. Parent: basePath,
  600. RelativePath: fmt.Sprintf(
  601. "%s/{%s}/{%s}/clusters/{cluster_id}/rerun_workflow",
  602. relPath,
  603. types.URLParamGitRepoOwner,
  604. types.URLParamGitRepoName,
  605. ),
  606. },
  607. Scopes: []types.PermissionScope{
  608. types.UserScope,
  609. types.ProjectScope,
  610. types.GitInstallationScope,
  611. types.ClusterScope,
  612. },
  613. },
  614. )
  615. rerunWorkflowHandler := gitinstallation.NewRerunWorkflowHandler(
  616. config,
  617. factory.GetDecoderValidator(),
  618. factory.GetResultWriter(),
  619. )
  620. routes = append(routes, &router.Route{
  621. Endpoint: rerunWorkflowEndpoint,
  622. Handler: rerunWorkflowHandler,
  623. Router: r,
  624. })
  625. return routes, newPath
  626. }