git_installation.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  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. types.PreviewEnvironmentScope,
  121. },
  122. },
  123. )
  124. createEnvironmentHandler := environment.NewCreateEnvironmentHandler(
  125. config,
  126. factory.GetDecoderValidator(),
  127. factory.GetResultWriter(),
  128. )
  129. routes = append(routes, &router.Route{
  130. Endpoint: createEnvironmentEndpoint,
  131. Handler: createEnvironmentHandler,
  132. Router: r,
  133. })
  134. // POST /api/projects/{project_id}/gitrepos/{git_installation_id}/{owner}/{name}/clusters/{cluster_id}/deployment ->
  135. // environment.NewCreateDeploymentHandler
  136. createDeploymentEndpoint := factory.NewAPIEndpoint(
  137. &types.APIRequestMetadata{
  138. Verb: types.APIVerbCreate,
  139. Method: types.HTTPVerbPost,
  140. Path: &types.Path{
  141. Parent: basePath,
  142. RelativePath: fmt.Sprintf(
  143. "%s/{%s}/{%s}/clusters/{cluster_id}/deployment",
  144. relPath,
  145. types.URLParamGitRepoOwner,
  146. types.URLParamGitRepoName,
  147. ),
  148. },
  149. Scopes: []types.PermissionScope{
  150. types.UserScope,
  151. types.ProjectScope,
  152. types.GitInstallationScope,
  153. types.ClusterScope,
  154. types.PreviewEnvironmentScope,
  155. },
  156. },
  157. )
  158. createDeploymentHandler := environment.NewCreateDeploymentHandler(
  159. config,
  160. factory.GetDecoderValidator(),
  161. factory.GetResultWriter(),
  162. )
  163. routes = append(routes, &router.Route{
  164. Endpoint: createDeploymentEndpoint,
  165. Handler: createDeploymentHandler,
  166. Router: r,
  167. })
  168. // GET /api/projects/{project_id}/gitrepos/{git_installation_id}/{owner}/{name}/clusters/{cluster_id}/deployment ->
  169. // environment.NewGetDeploymentHandler
  170. getDeploymentEndpoint := factory.NewAPIEndpoint(
  171. &types.APIRequestMetadata{
  172. Verb: types.APIVerbGet,
  173. Method: types.HTTPVerbGet,
  174. Path: &types.Path{
  175. Parent: basePath,
  176. RelativePath: fmt.Sprintf(
  177. "%s/{%s}/{%s}/clusters/{cluster_id}/deployment",
  178. relPath,
  179. types.URLParamGitRepoOwner,
  180. types.URLParamGitRepoName,
  181. ),
  182. },
  183. Scopes: []types.PermissionScope{
  184. types.UserScope,
  185. types.ProjectScope,
  186. types.GitInstallationScope,
  187. types.ClusterScope,
  188. types.PreviewEnvironmentScope,
  189. },
  190. },
  191. )
  192. getDeploymentHandler := environment.NewGetDeploymentHandler(
  193. config,
  194. factory.GetDecoderValidator(),
  195. factory.GetResultWriter(),
  196. )
  197. routes = append(routes, &router.Route{
  198. Endpoint: getDeploymentEndpoint,
  199. Handler: getDeploymentHandler,
  200. Router: r,
  201. })
  202. // GET /api/projects/{project_id}/gitrepos/{git_installation_id}/{owner}/{name}/clusters/{cluster_id}/deployments ->
  203. // environment.NewCreateDeploymentHandler
  204. listDeploymentsEndpoint := factory.NewAPIEndpoint(
  205. &types.APIRequestMetadata{
  206. Verb: types.APIVerbGet,
  207. Method: types.HTTPVerbGet,
  208. Path: &types.Path{
  209. Parent: basePath,
  210. RelativePath: fmt.Sprintf(
  211. "%s/{%s}/{%s}/clusters/{cluster_id}/deployments",
  212. relPath,
  213. types.URLParamGitRepoOwner,
  214. types.URLParamGitRepoName,
  215. ),
  216. },
  217. Scopes: []types.PermissionScope{
  218. types.UserScope,
  219. types.ProjectScope,
  220. types.GitInstallationScope,
  221. types.ClusterScope,
  222. types.PreviewEnvironmentScope,
  223. },
  224. },
  225. )
  226. listDeploymentsHandler := environment.NewListDeploymentsHandler(
  227. config,
  228. factory.GetDecoderValidator(),
  229. factory.GetResultWriter(),
  230. )
  231. routes = append(routes, &router.Route{
  232. Endpoint: listDeploymentsEndpoint,
  233. Handler: listDeploymentsHandler,
  234. Router: r,
  235. })
  236. // POST /api/projects/{project_id}/gitrepos/{git_installation_id}/{owner}/{name}/clusters/{cluster_id}/deployment/finalize ->
  237. // environment.NewFinalizeDeploymentHandler
  238. finalizeDeploymentEndpoint := factory.NewAPIEndpoint(
  239. &types.APIRequestMetadata{
  240. Verb: types.APIVerbCreate,
  241. Method: types.HTTPVerbPost,
  242. Path: &types.Path{
  243. Parent: basePath,
  244. RelativePath: fmt.Sprintf(
  245. "%s/{%s}/{%s}/clusters/{cluster_id}/deployment/finalize",
  246. relPath,
  247. types.URLParamGitRepoOwner,
  248. types.URLParamGitRepoName,
  249. ),
  250. },
  251. Scopes: []types.PermissionScope{
  252. types.UserScope,
  253. types.ProjectScope,
  254. types.GitInstallationScope,
  255. types.ClusterScope,
  256. types.PreviewEnvironmentScope,
  257. },
  258. },
  259. )
  260. finalizeDeploymentHandler := environment.NewFinalizeDeploymentHandler(
  261. config,
  262. factory.GetDecoderValidator(),
  263. factory.GetResultWriter(),
  264. )
  265. routes = append(routes, &router.Route{
  266. Endpoint: finalizeDeploymentEndpoint,
  267. Handler: finalizeDeploymentHandler,
  268. Router: r,
  269. })
  270. // POST /api/projects/{project_id}/gitrepos/{git_installation_id}/{owner}/{name}/clusters/{cluster_id}/deployment/update ->
  271. // environment.NewFinalizeDeploymentHandler
  272. updateDeploymentEndpoint := factory.NewAPIEndpoint(
  273. &types.APIRequestMetadata{
  274. Verb: types.APIVerbUpdate,
  275. Method: types.HTTPVerbPost,
  276. Path: &types.Path{
  277. Parent: basePath,
  278. RelativePath: fmt.Sprintf(
  279. "%s/{%s}/{%s}/clusters/{cluster_id}/deployment/update",
  280. relPath,
  281. types.URLParamGitRepoOwner,
  282. types.URLParamGitRepoName,
  283. ),
  284. },
  285. Scopes: []types.PermissionScope{
  286. types.UserScope,
  287. types.ProjectScope,
  288. types.GitInstallationScope,
  289. types.ClusterScope,
  290. types.PreviewEnvironmentScope,
  291. },
  292. },
  293. )
  294. updateDeploymentHandler := environment.NewUpdateDeploymentHandler(
  295. config,
  296. factory.GetDecoderValidator(),
  297. factory.GetResultWriter(),
  298. )
  299. routes = append(routes, &router.Route{
  300. Endpoint: updateDeploymentEndpoint,
  301. Handler: updateDeploymentHandler,
  302. Router: r,
  303. })
  304. // POST /api/projects/{project_id}/gitrepos/{git_installation_id}/{owner}/{name}/clusters/{cluster_id}/deployment/update/status ->
  305. // environment.NewUpdateDeploymentStatusHandler
  306. updateDeploymentStatusEndpoint := factory.NewAPIEndpoint(
  307. &types.APIRequestMetadata{
  308. Verb: types.APIVerbUpdate,
  309. Method: types.HTTPVerbPost,
  310. Path: &types.Path{
  311. Parent: basePath,
  312. RelativePath: fmt.Sprintf(
  313. "%s/{%s}/{%s}/clusters/{cluster_id}/deployment/update/status",
  314. relPath,
  315. types.URLParamGitRepoOwner,
  316. types.URLParamGitRepoName,
  317. ),
  318. },
  319. Scopes: []types.PermissionScope{
  320. types.UserScope,
  321. types.ProjectScope,
  322. types.GitInstallationScope,
  323. types.ClusterScope,
  324. types.PreviewEnvironmentScope,
  325. },
  326. },
  327. )
  328. updateDeploymentStatusHandler := environment.NewUpdateDeploymentStatusHandler(
  329. config,
  330. factory.GetDecoderValidator(),
  331. factory.GetResultWriter(),
  332. )
  333. routes = append(routes, &router.Route{
  334. Endpoint: updateDeploymentStatusEndpoint,
  335. Handler: updateDeploymentStatusHandler,
  336. Router: r,
  337. })
  338. // POST /api/projects/{project_id}/gitrepos/{git_installation_id}/{owner}/{name}/clusters/{cluster_id}/deployment/finalize_errors ->
  339. // environment.NewFinalizeDeploymentWithErrorsHandler
  340. finalizeDeploymentWithErrorsEndpoint := factory.NewAPIEndpoint(
  341. &types.APIRequestMetadata{
  342. Verb: types.APIVerbUpdate,
  343. Method: types.HTTPVerbPost,
  344. Path: &types.Path{
  345. Parent: basePath,
  346. RelativePath: fmt.Sprintf(
  347. "%s/{%s}/{%s}/clusters/{cluster_id}/deployment/finalize_errors",
  348. relPath,
  349. types.URLParamGitRepoOwner,
  350. types.URLParamGitRepoName,
  351. ),
  352. },
  353. Scopes: []types.PermissionScope{
  354. types.UserScope,
  355. types.ProjectScope,
  356. types.GitInstallationScope,
  357. types.ClusterScope,
  358. types.PreviewEnvironmentScope,
  359. },
  360. },
  361. )
  362. finalizeDeploymentWithErrorsHandler := environment.NewFinalizeDeploymentWithErrorsHandler(
  363. config,
  364. factory.GetDecoderValidator(),
  365. factory.GetResultWriter(),
  366. )
  367. routes = append(routes, &router.Route{
  368. Endpoint: finalizeDeploymentWithErrorsEndpoint,
  369. Handler: finalizeDeploymentWithErrorsHandler,
  370. Router: r,
  371. })
  372. // DELETE /api/projects/{project_id}/gitrepos/{git_installation_id}/{owner}/{name}/clusters/{cluster_id}/environment ->
  373. // environment.NewDeleteEnvironmentHandler
  374. deleteEnvironmentEndpoint := factory.NewAPIEndpoint(
  375. &types.APIRequestMetadata{
  376. Verb: types.APIVerbDelete,
  377. Method: types.HTTPVerbDelete,
  378. Path: &types.Path{
  379. Parent: basePath,
  380. RelativePath: fmt.Sprintf(
  381. "%s/{%s}/{%s}/clusters/{cluster_id}/environment",
  382. relPath,
  383. types.URLParamGitRepoOwner,
  384. types.URLParamGitRepoName,
  385. ),
  386. },
  387. Scopes: []types.PermissionScope{
  388. types.UserScope,
  389. types.ProjectScope,
  390. types.GitInstallationScope,
  391. types.ClusterScope,
  392. types.PreviewEnvironmentScope,
  393. },
  394. },
  395. )
  396. deleteEnvironmentHandler := environment.NewDeleteEnvironmentHandler(
  397. config,
  398. factory.GetDecoderValidator(),
  399. factory.GetResultWriter(),
  400. )
  401. routes = append(routes, &router.Route{
  402. Endpoint: deleteEnvironmentEndpoint,
  403. Handler: deleteEnvironmentHandler,
  404. Router: r,
  405. })
  406. }
  407. // GET /api/projects/{project_id}/gitrepos/{git_installation_id}/repos ->
  408. // gitinstallation.GithubListReposHandler
  409. listReposEndpoint := factory.NewAPIEndpoint(
  410. &types.APIRequestMetadata{
  411. Verb: types.APIVerbList,
  412. Method: types.HTTPVerbGet,
  413. Path: &types.Path{
  414. Parent: basePath,
  415. RelativePath: relPath + "/repos",
  416. },
  417. Scopes: []types.PermissionScope{
  418. types.UserScope,
  419. types.ProjectScope,
  420. types.GitInstallationScope,
  421. },
  422. },
  423. )
  424. listReposHandler := gitinstallation.NewGithubListReposHandler(
  425. config,
  426. factory.GetResultWriter(),
  427. )
  428. routes = append(routes, &router.Route{
  429. Endpoint: listReposEndpoint,
  430. Handler: listReposHandler,
  431. Router: r,
  432. })
  433. // GET /api/projects/{project_id}/gitrepos/{installation_id}/repos/{kind}/{owner}/{name}/branches ->
  434. // gitinstallation.GithubListBranchesHandler
  435. listBranchesEndpoint := factory.NewAPIEndpoint(
  436. &types.APIRequestMetadata{
  437. Verb: types.APIVerbList,
  438. Method: types.HTTPVerbGet,
  439. Path: &types.Path{
  440. Parent: basePath,
  441. RelativePath: fmt.Sprintf(
  442. "%s/repos/{%s}/{%s}/{%s}/branches",
  443. relPath,
  444. types.URLParamGitKind,
  445. types.URLParamGitRepoOwner,
  446. types.URLParamGitRepoName,
  447. ),
  448. },
  449. Scopes: []types.PermissionScope{
  450. types.UserScope,
  451. types.ProjectScope,
  452. types.GitInstallationScope,
  453. },
  454. },
  455. )
  456. listBranchesHandler := gitinstallation.NewGithubListBranchesHandler(
  457. config,
  458. factory.GetResultWriter(),
  459. )
  460. routes = append(routes, &router.Route{
  461. Endpoint: listBranchesEndpoint,
  462. Handler: listBranchesHandler,
  463. Router: r,
  464. })
  465. // GET /api/projects/{project_id}/gitrepos/{installation_id}/repos/{kind}/{ownner}/{name}/branches/{branch} ->
  466. // gitinstallation.GithubGetBranchMetadataHandler
  467. getBranchMetadataEndpoint := factory.NewAPIEndpoint(
  468. &types.APIRequestMetadata{
  469. Verb: types.APIVerbList,
  470. Method: types.HTTPVerbGet,
  471. Path: &types.Path{
  472. Parent: basePath,
  473. RelativePath: fmt.Sprintf(
  474. "%s/repos/{%s}/{%s}/{%s}/branches/{%s}",
  475. relPath,
  476. types.URLParamGitKind,
  477. types.URLParamGitRepoOwner,
  478. types.URLParamGitRepoName,
  479. types.URLParamGitBranch,
  480. ),
  481. },
  482. Scopes: []types.PermissionScope{
  483. types.UserScope,
  484. types.ProjectScope,
  485. types.GitInstallationScope,
  486. },
  487. },
  488. )
  489. getBranchMetadataHandler := gitinstallation.NewGithubGetBranchMetadataHandler(
  490. config,
  491. factory.GetResultWriter(),
  492. )
  493. routes = append(routes, &router.Route{
  494. Endpoint: getBranchMetadataEndpoint,
  495. Handler: getBranchMetadataHandler,
  496. Router: r,
  497. })
  498. // GET /api/projects/{project_id}/gitrepos/{installation_id}/repos/{kind}/{owner}/{name}/{branch}/buildpack/detect ->
  499. // gitinstallation.NewGithubGetBuildpackHandler
  500. getBuildpackEndpoint := factory.NewAPIEndpoint(
  501. &types.APIRequestMetadata{
  502. Verb: types.APIVerbGet,
  503. Method: types.HTTPVerbGet,
  504. Path: &types.Path{
  505. Parent: basePath,
  506. RelativePath: fmt.Sprintf(
  507. "%s/repos/{%s}/{%s}/{%s}/{%s}/buildpack/detect",
  508. relPath,
  509. types.URLParamGitKind,
  510. types.URLParamGitRepoOwner,
  511. types.URLParamGitRepoName,
  512. types.URLParamGitBranch,
  513. ),
  514. },
  515. Scopes: []types.PermissionScope{
  516. types.UserScope,
  517. types.ProjectScope,
  518. types.GitInstallationScope,
  519. },
  520. },
  521. )
  522. getBuildpackHandler := gitinstallation.NewGithubGetBuildpackHandler(
  523. config,
  524. factory.GetDecoderValidator(),
  525. factory.GetResultWriter(),
  526. )
  527. routes = append(routes, &router.Route{
  528. Endpoint: getBuildpackEndpoint,
  529. Handler: getBuildpackHandler,
  530. Router: r,
  531. })
  532. // GET /api/projects/{project_id}/gitrepos/{installation_id}/repos/{kind}/{owner}/{name}/{branch}/contents ->
  533. // gitinstallation.NewGithubGetContentsHandler
  534. getContentsEndpoint := factory.NewAPIEndpoint(
  535. &types.APIRequestMetadata{
  536. Verb: types.APIVerbGet,
  537. Method: types.HTTPVerbGet,
  538. Path: &types.Path{
  539. Parent: basePath,
  540. RelativePath: fmt.Sprintf(
  541. "%s/repos/{%s}/{%s}/{%s}/{%s}/contents",
  542. relPath,
  543. types.URLParamGitKind,
  544. types.URLParamGitRepoOwner,
  545. types.URLParamGitRepoName,
  546. types.URLParamGitBranch,
  547. ),
  548. },
  549. Scopes: []types.PermissionScope{
  550. types.UserScope,
  551. types.ProjectScope,
  552. types.GitInstallationScope,
  553. },
  554. },
  555. )
  556. getContentsHandler := gitinstallation.NewGithubGetContentsHandler(
  557. config,
  558. factory.GetDecoderValidator(),
  559. factory.GetResultWriter(),
  560. )
  561. routes = append(routes, &router.Route{
  562. Endpoint: getContentsEndpoint,
  563. Handler: getContentsHandler,
  564. Router: r,
  565. })
  566. // GET /api/projects/{project_id}/gitrepos/{installation_id}/repos/{kind}/{owner}/{name}/{branch}/procfile ->
  567. // gitinstallation.NewGithubGetProcfileHandler
  568. getProcfileEndpoint := factory.NewAPIEndpoint(
  569. &types.APIRequestMetadata{
  570. Verb: types.APIVerbGet,
  571. Method: types.HTTPVerbGet,
  572. Path: &types.Path{
  573. Parent: basePath,
  574. RelativePath: fmt.Sprintf(
  575. "%s/repos/{%s}/{%s}/{%s}/{%s}/procfile",
  576. relPath,
  577. types.URLParamGitKind,
  578. types.URLParamGitRepoOwner,
  579. types.URLParamGitRepoName,
  580. types.URLParamGitBranch,
  581. ),
  582. },
  583. Scopes: []types.PermissionScope{
  584. types.UserScope,
  585. types.ProjectScope,
  586. types.GitInstallationScope,
  587. },
  588. },
  589. )
  590. getProcfileHandler := gitinstallation.NewGithubGetProcfileHandler(
  591. config,
  592. factory.GetDecoderValidator(),
  593. factory.GetResultWriter(),
  594. )
  595. routes = append(routes, &router.Route{
  596. Endpoint: getProcfileEndpoint,
  597. Handler: getProcfileHandler,
  598. Router: r,
  599. })
  600. // GET /api/projects/{project_id}/gitrepos/{installation_id}/repos/{kind}/{owner}/{name}/{branch}/tarball_url ->
  601. // gitinstallation.NewGithubGetTarballURLHandler
  602. getTarballURLEndpoint := factory.NewAPIEndpoint(
  603. &types.APIRequestMetadata{
  604. Verb: types.APIVerbGet,
  605. Method: types.HTTPVerbGet,
  606. Path: &types.Path{
  607. Parent: basePath,
  608. RelativePath: fmt.Sprintf(
  609. "%s/repos/{%s}/{%s}/{%s}/{%s}/tarball_url",
  610. relPath,
  611. types.URLParamGitKind,
  612. types.URLParamGitRepoOwner,
  613. types.URLParamGitRepoName,
  614. types.URLParamGitBranch,
  615. ),
  616. },
  617. Scopes: []types.PermissionScope{
  618. types.UserScope,
  619. types.ProjectScope,
  620. types.GitInstallationScope,
  621. },
  622. },
  623. )
  624. getTarballURLHandler := gitinstallation.NewGithubGetTarballURLHandler(
  625. config,
  626. factory.GetDecoderValidator(),
  627. factory.GetResultWriter(),
  628. )
  629. routes = append(routes, &router.Route{
  630. Endpoint: getTarballURLEndpoint,
  631. Handler: getTarballURLHandler,
  632. Router: r,
  633. })
  634. // POST /api/projects/{project_id}/gitrepos/{git_installation_id}/{owner}/{name}/clusters/{cluster_id}/rerun_workflow ->
  635. // gitinstallation.NewRerunWorkflowHandler
  636. rerunWorkflowEndpoint := factory.NewAPIEndpoint(
  637. &types.APIRequestMetadata{
  638. Verb: types.APIVerbUpdate,
  639. Method: types.HTTPVerbPost,
  640. Path: &types.Path{
  641. Parent: basePath,
  642. RelativePath: fmt.Sprintf(
  643. "%s/{%s}/{%s}/clusters/{cluster_id}/rerun_workflow",
  644. relPath,
  645. types.URLParamGitRepoOwner,
  646. types.URLParamGitRepoName,
  647. ),
  648. },
  649. Scopes: []types.PermissionScope{
  650. types.UserScope,
  651. types.ProjectScope,
  652. types.GitInstallationScope,
  653. types.ClusterScope,
  654. },
  655. },
  656. )
  657. rerunWorkflowHandler := gitinstallation.NewRerunWorkflowHandler(
  658. config,
  659. factory.GetDecoderValidator(),
  660. factory.GetResultWriter(),
  661. )
  662. routes = append(routes, &router.Route{
  663. Endpoint: rerunWorkflowEndpoint,
  664. Handler: rerunWorkflowHandler,
  665. Router: r,
  666. })
  667. return routes, newPath
  668. }