git_installation.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806
  1. package router
  2. import (
  3. "fmt"
  4. "github.com/go-chi/chi/v5"
  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}/{owner}/{name}/{branch}/buildpack/detect ->
  466. // gitinstallation.NewGithubGetBuildpackHandler
  467. getBuildpackEndpoint := factory.NewAPIEndpoint(
  468. &types.APIRequestMetadata{
  469. Verb: types.APIVerbGet,
  470. Method: types.HTTPVerbGet,
  471. Path: &types.Path{
  472. Parent: basePath,
  473. RelativePath: fmt.Sprintf(
  474. "%s/repos/{%s}/{%s}/{%s}/{%s}/buildpack/detect",
  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. getBuildpackHandler := gitinstallation.NewGithubGetBuildpackHandler(
  490. config,
  491. factory.GetDecoderValidator(),
  492. factory.GetResultWriter(),
  493. )
  494. routes = append(routes, &router.Route{
  495. Endpoint: getBuildpackEndpoint,
  496. Handler: getBuildpackHandler,
  497. Router: r,
  498. })
  499. // GET /api/projects/{project_id}/gitrepos/{installation_id}/repos/{kind}/{owner}/{name}/{branch}/contents ->
  500. // gitinstallation.NewGithubGetContentsHandler
  501. getContentsEndpoint := factory.NewAPIEndpoint(
  502. &types.APIRequestMetadata{
  503. Verb: types.APIVerbGet,
  504. Method: types.HTTPVerbGet,
  505. Path: &types.Path{
  506. Parent: basePath,
  507. RelativePath: fmt.Sprintf(
  508. "%s/repos/{%s}/{%s}/{%s}/{%s}/contents",
  509. relPath,
  510. types.URLParamGitKind,
  511. types.URLParamGitRepoOwner,
  512. types.URLParamGitRepoName,
  513. types.URLParamGitBranch,
  514. ),
  515. },
  516. Scopes: []types.PermissionScope{
  517. types.UserScope,
  518. types.ProjectScope,
  519. types.GitInstallationScope,
  520. },
  521. },
  522. )
  523. getContentsHandler := gitinstallation.NewGithubGetContentsHandler(
  524. config,
  525. factory.GetDecoderValidator(),
  526. factory.GetResultWriter(),
  527. )
  528. routes = append(routes, &router.Route{
  529. Endpoint: getContentsEndpoint,
  530. Handler: getContentsHandler,
  531. Router: r,
  532. })
  533. // GET /api/projects/{project_id}/gitrepos/{installation_id}/repos/{kind}/{owner}/{name}/{branch}/porteryaml ->
  534. // gitinstallation.NewGithubGetProcfileHandler
  535. getPorterYamlEndpoint := factory.NewAPIEndpoint(
  536. &types.APIRequestMetadata{
  537. Verb: types.APIVerbGet,
  538. Method: types.HTTPVerbGet,
  539. Path: &types.Path{
  540. Parent: basePath,
  541. RelativePath: fmt.Sprintf(
  542. "%s/repos/{%s}/{%s}/{%s}/{%s}/porteryaml",
  543. relPath,
  544. types.URLParamGitKind,
  545. types.URLParamGitRepoOwner,
  546. types.URLParamGitRepoName,
  547. types.URLParamGitBranch,
  548. ),
  549. },
  550. Scopes: []types.PermissionScope{
  551. types.UserScope,
  552. types.ProjectScope,
  553. types.GitInstallationScope,
  554. },
  555. },
  556. )
  557. getPorterYamlHandler := gitinstallation.NewGithubGetPorterYamlHandler(
  558. config,
  559. factory.GetDecoderValidator(),
  560. factory.GetResultWriter(),
  561. )
  562. routes = append(routes, &router.Route{
  563. Endpoint: getPorterYamlEndpoint,
  564. Handler: getPorterYamlHandler,
  565. Router: r,
  566. })
  567. // GET /api/projects/{project_id}/gitrepos/{installation_id}/repos/{kind}/{owner}/{name}/{branch}/procfile ->
  568. // gitinstallation.NewGithubGetProcfileHandler
  569. getProcfileEndpoint := factory.NewAPIEndpoint(
  570. &types.APIRequestMetadata{
  571. Verb: types.APIVerbGet,
  572. Method: types.HTTPVerbGet,
  573. Path: &types.Path{
  574. Parent: basePath,
  575. RelativePath: fmt.Sprintf(
  576. "%s/repos/{%s}/{%s}/{%s}/{%s}/procfile",
  577. relPath,
  578. types.URLParamGitKind,
  579. types.URLParamGitRepoOwner,
  580. types.URLParamGitRepoName,
  581. types.URLParamGitBranch,
  582. ),
  583. },
  584. Scopes: []types.PermissionScope{
  585. types.UserScope,
  586. types.ProjectScope,
  587. types.GitInstallationScope,
  588. },
  589. },
  590. )
  591. getProcfileHandler := gitinstallation.NewGithubGetProcfileHandler(
  592. config,
  593. factory.GetDecoderValidator(),
  594. factory.GetResultWriter(),
  595. )
  596. routes = append(routes, &router.Route{
  597. Endpoint: getProcfileEndpoint,
  598. Handler: getProcfileHandler,
  599. Router: r,
  600. })
  601. // GET /api/projects/{project_id}/gitrepos/{installation_id}/repos/{kind}/{owner}/{name}/{branch}/tarball_url ->
  602. // gitinstallation.NewGithubGetTarballURLHandler
  603. getTarballURLEndpoint := factory.NewAPIEndpoint(
  604. &types.APIRequestMetadata{
  605. Verb: types.APIVerbGet,
  606. Method: types.HTTPVerbGet,
  607. Path: &types.Path{
  608. Parent: basePath,
  609. RelativePath: fmt.Sprintf(
  610. "%s/repos/{%s}/{%s}/{%s}/{%s}/tarball_url",
  611. relPath,
  612. types.URLParamGitKind,
  613. types.URLParamGitRepoOwner,
  614. types.URLParamGitRepoName,
  615. types.URLParamGitBranch,
  616. ),
  617. },
  618. Scopes: []types.PermissionScope{
  619. types.UserScope,
  620. types.ProjectScope,
  621. types.GitInstallationScope,
  622. },
  623. },
  624. )
  625. getTarballURLHandler := gitinstallation.NewGithubGetTarballURLHandler(
  626. config,
  627. factory.GetDecoderValidator(),
  628. factory.GetResultWriter(),
  629. )
  630. routes = append(routes, &router.Route{
  631. Endpoint: getTarballURLEndpoint,
  632. Handler: getTarballURLHandler,
  633. Router: r,
  634. })
  635. // POST /api/projects/{project_id}/gitrepos/{git_installation_id}/{owner}/{name}/clusters/{cluster_id}/rerun_workflow ->
  636. // gitinstallation.NewRerunWorkflowHandler
  637. rerunWorkflowEndpoint := factory.NewAPIEndpoint(
  638. &types.APIRequestMetadata{
  639. Verb: types.APIVerbUpdate,
  640. Method: types.HTTPVerbPost,
  641. Path: &types.Path{
  642. Parent: basePath,
  643. RelativePath: fmt.Sprintf(
  644. "%s/{%s}/{%s}/clusters/{cluster_id}/rerun_workflow",
  645. relPath,
  646. types.URLParamGitRepoOwner,
  647. types.URLParamGitRepoName,
  648. ),
  649. },
  650. Scopes: []types.PermissionScope{
  651. types.UserScope,
  652. types.ProjectScope,
  653. types.GitInstallationScope,
  654. types.ClusterScope,
  655. },
  656. },
  657. )
  658. rerunWorkflowHandler := gitinstallation.NewRerunWorkflowHandler(
  659. config,
  660. factory.GetDecoderValidator(),
  661. factory.GetResultWriter(),
  662. )
  663. routes = append(routes, &router.Route{
  664. Endpoint: rerunWorkflowEndpoint,
  665. Handler: rerunWorkflowHandler,
  666. Router: r,
  667. })
  668. getWorkflowLogsEndpoint := factory.NewAPIEndpoint(
  669. &types.APIRequestMetadata{
  670. Verb: types.APIVerbGet,
  671. Method: types.HTTPVerbGet,
  672. Path: &types.Path{
  673. Parent: basePath,
  674. RelativePath: fmt.Sprintf(
  675. "%s/{%s}/{%s}/clusters/{cluster_id}/get_logs_workflow",
  676. relPath,
  677. types.URLParamGitRepoOwner,
  678. types.URLParamGitRepoName,
  679. ),
  680. },
  681. Scopes: []types.PermissionScope{
  682. types.UserScope,
  683. types.ProjectScope,
  684. types.GitInstallationScope,
  685. types.ClusterScope,
  686. },
  687. },
  688. )
  689. getWorkflowLogsHandler := gitinstallation.NewGetWorkflowLogsHandler(
  690. config,
  691. factory.GetDecoderValidator(),
  692. factory.GetResultWriter(),
  693. )
  694. routes = append(routes, &router.Route{
  695. Endpoint: getWorkflowLogsEndpoint,
  696. Handler: getWorkflowLogsHandler,
  697. Router: r,
  698. })
  699. getWorkflowLogByIDEndpoint := factory.NewAPIEndpoint(
  700. &types.APIRequestMetadata{
  701. Verb: types.APIVerbGet,
  702. Method: types.HTTPVerbGet,
  703. Path: &types.Path{
  704. Parent: basePath,
  705. RelativePath: fmt.Sprintf(
  706. "%s/{%s}/{%s}/clusters/{cluster_id}/workflow_run_id",
  707. relPath,
  708. types.URLParamGitRepoOwner,
  709. types.URLParamGitRepoName,
  710. ),
  711. },
  712. Scopes: []types.PermissionScope{
  713. types.UserScope,
  714. types.ProjectScope,
  715. types.GitInstallationScope,
  716. types.ClusterScope,
  717. },
  718. },
  719. )
  720. getWorkflowLogByIDHandler := gitinstallation.NewGetSpecificWorkflowLogsHandler(
  721. config,
  722. factory.GetDecoderValidator(),
  723. factory.GetResultWriter(),
  724. )
  725. routes = append(routes, &router.Route{
  726. Endpoint: getWorkflowLogByIDEndpoint,
  727. Handler: getWorkflowLogByIDHandler,
  728. Router: r,
  729. })
  730. return routes, newPath
  731. }