namespace.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  1. package router
  2. import (
  3. "fmt"
  4. "github.com/go-chi/chi"
  5. "github.com/porter-dev/porter/api/server/handlers/job"
  6. "github.com/porter-dev/porter/api/server/handlers/namespace"
  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/types"
  10. )
  11. func NewNamespaceScopedRegisterer(children ...*Registerer) *Registerer {
  12. return &Registerer{
  13. GetRoutes: GetNamespaceScopedRoutes,
  14. Children: children,
  15. }
  16. }
  17. func GetNamespaceScopedRoutes(
  18. r chi.Router,
  19. config *config.Config,
  20. basePath *types.Path,
  21. factory shared.APIEndpointFactory,
  22. children ...*Registerer,
  23. ) []*Route {
  24. routes, projPath := getNamespaceRoutes(r, config, basePath, factory)
  25. if len(children) > 0 {
  26. r.Route(projPath.RelativePath, func(r chi.Router) {
  27. for _, child := range children {
  28. childRoutes := child.GetRoutes(r, config, basePath, factory, child.Children...)
  29. routes = append(routes, childRoutes...)
  30. }
  31. })
  32. }
  33. return routes
  34. }
  35. func getNamespaceRoutes(
  36. r chi.Router,
  37. config *config.Config,
  38. basePath *types.Path,
  39. factory shared.APIEndpointFactory,
  40. ) ([]*Route, *types.Path) {
  41. relPath := "/namespaces/{namespace}"
  42. newPath := &types.Path{
  43. Parent: basePath,
  44. RelativePath: relPath,
  45. }
  46. routes := make([]*Route, 0)
  47. // GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/envgroups/list -> namespace.NewListEnvGroupsHandler
  48. listEnvGroupsEndpoint := factory.NewAPIEndpoint(
  49. &types.APIRequestMetadata{
  50. Verb: types.APIVerbGet,
  51. Method: types.HTTPVerbGet,
  52. Path: &types.Path{
  53. Parent: basePath,
  54. RelativePath: relPath + "/envgroup/list",
  55. },
  56. Scopes: []types.PermissionScope{
  57. types.UserScope,
  58. types.ProjectScope,
  59. types.ClusterScope,
  60. types.NamespaceScope,
  61. },
  62. },
  63. )
  64. listEnvGroupsHandler := namespace.NewListEnvGroupsHandler(
  65. config,
  66. factory.GetResultWriter(),
  67. )
  68. routes = append(routes, &Route{
  69. Endpoint: listEnvGroupsEndpoint,
  70. Handler: listEnvGroupsHandler,
  71. Router: r,
  72. })
  73. // POST /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/envgroup/clone -> namespace.NewCloneEnvGroupHandler
  74. cloneEnvGroupEndpoint := factory.NewAPIEndpoint(
  75. &types.APIRequestMetadata{
  76. Verb: types.APIVerbCreate,
  77. Method: types.HTTPVerbPost,
  78. Path: &types.Path{
  79. Parent: basePath,
  80. RelativePath: relPath + "/envgroup/clone",
  81. },
  82. Scopes: []types.PermissionScope{
  83. types.UserScope,
  84. types.ProjectScope,
  85. types.ClusterScope,
  86. types.NamespaceScope,
  87. },
  88. },
  89. )
  90. cloneEnvGroupHandler := namespace.NewCloneEnvGroupHandler(
  91. config,
  92. factory.GetDecoderValidator(),
  93. factory.GetResultWriter(),
  94. )
  95. routes = append(routes, &Route{
  96. Endpoint: cloneEnvGroupEndpoint,
  97. Handler: cloneEnvGroupHandler,
  98. Router: r,
  99. })
  100. // GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/envgroup -> namespace.NewGetEnvGroupHandler
  101. getEnvGroupEndpoint := factory.NewAPIEndpoint(
  102. &types.APIRequestMetadata{
  103. Verb: types.APIVerbGet,
  104. Method: types.HTTPVerbGet,
  105. Path: &types.Path{
  106. Parent: basePath,
  107. RelativePath: relPath + "/envgroup",
  108. },
  109. Scopes: []types.PermissionScope{
  110. types.UserScope,
  111. types.ProjectScope,
  112. types.ClusterScope,
  113. types.NamespaceScope,
  114. },
  115. },
  116. )
  117. getEnvGroupHandler := namespace.NewGetEnvGroupHandler(
  118. config,
  119. factory.GetDecoderValidator(),
  120. factory.GetResultWriter(),
  121. )
  122. routes = append(routes, &Route{
  123. Endpoint: getEnvGroupEndpoint,
  124. Handler: getEnvGroupHandler,
  125. Router: r,
  126. })
  127. // GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/envgroup/all_versions -> namespace.NewGetEnvGroupAllVersionsHandler
  128. getEnvGroupAllVersionsEndpoint := factory.NewAPIEndpoint(
  129. &types.APIRequestMetadata{
  130. Verb: types.APIVerbGet,
  131. Method: types.HTTPVerbGet,
  132. Path: &types.Path{
  133. Parent: basePath,
  134. RelativePath: relPath + "/envgroup/all_versions",
  135. },
  136. Scopes: []types.PermissionScope{
  137. types.UserScope,
  138. types.ProjectScope,
  139. types.ClusterScope,
  140. types.NamespaceScope,
  141. },
  142. },
  143. )
  144. getEnvGroupAllVersionsHandler := namespace.NewGetEnvGroupAllVersionsHandler(
  145. config,
  146. factory.GetDecoderValidator(),
  147. factory.GetResultWriter(),
  148. )
  149. routes = append(routes, &Route{
  150. Endpoint: getEnvGroupAllVersionsEndpoint,
  151. Handler: getEnvGroupAllVersionsHandler,
  152. Router: r,
  153. })
  154. // POST /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/envgroup/create -> namespace.NewCreateEnvGroupHandler
  155. createEnvGroupEndpoint := factory.NewAPIEndpoint(
  156. &types.APIRequestMetadata{
  157. Verb: types.APIVerbCreate,
  158. Method: types.HTTPVerbPost,
  159. Path: &types.Path{
  160. Parent: basePath,
  161. RelativePath: relPath + "/envgroup/create",
  162. },
  163. Scopes: []types.PermissionScope{
  164. types.UserScope,
  165. types.ProjectScope,
  166. types.ClusterScope,
  167. types.NamespaceScope,
  168. },
  169. },
  170. )
  171. createEnvGroupHandler := namespace.NewCreateEnvGroupHandler(
  172. config,
  173. factory.GetDecoderValidator(),
  174. factory.GetResultWriter(),
  175. )
  176. routes = append(routes, &Route{
  177. Endpoint: createEnvGroupEndpoint,
  178. Handler: createEnvGroupHandler,
  179. Router: r,
  180. })
  181. // POST /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/envgroup/add_application -> namespace.NewAddEnvGroupAppHandler
  182. updateEnvGroupAppsEndpoint := factory.NewAPIEndpoint(
  183. &types.APIRequestMetadata{
  184. Verb: types.APIVerbUpdate,
  185. Method: types.HTTPVerbPost,
  186. Path: &types.Path{
  187. Parent: basePath,
  188. RelativePath: relPath + "/envgroup/add_application",
  189. },
  190. Scopes: []types.PermissionScope{
  191. types.UserScope,
  192. types.ProjectScope,
  193. types.ClusterScope,
  194. types.NamespaceScope,
  195. },
  196. },
  197. )
  198. updateEnvGroupAppsHandler := namespace.NewAddEnvGroupAppHandler(
  199. config,
  200. factory.GetDecoderValidator(),
  201. factory.GetResultWriter(),
  202. )
  203. routes = append(routes, &Route{
  204. Endpoint: updateEnvGroupAppsEndpoint,
  205. Handler: updateEnvGroupAppsHandler,
  206. Router: r,
  207. })
  208. // POST /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/envgroup/remove_application -> namespace.NewRemoveEnvGroupAppHandler
  209. removeEnvGroupAppEndpoint := factory.NewAPIEndpoint(
  210. &types.APIRequestMetadata{
  211. Verb: types.APIVerbUpdate,
  212. Method: types.HTTPVerbPost,
  213. Path: &types.Path{
  214. Parent: basePath,
  215. RelativePath: relPath + "/envgroup/remove_application",
  216. },
  217. Scopes: []types.PermissionScope{
  218. types.UserScope,
  219. types.ProjectScope,
  220. types.ClusterScope,
  221. types.NamespaceScope,
  222. },
  223. },
  224. )
  225. removeEnvGroupAppHandler := namespace.NewRemoveEnvGroupAppHandler(
  226. config,
  227. factory.GetDecoderValidator(),
  228. factory.GetResultWriter(),
  229. )
  230. routes = append(routes, &Route{
  231. Endpoint: removeEnvGroupAppEndpoint,
  232. Handler: removeEnvGroupAppHandler,
  233. Router: r,
  234. })
  235. // DELETE /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/envgroup -> namespace.NewDeleteEnvGroupHandler
  236. deleteEnvGroupEndpoint := factory.NewAPIEndpoint(
  237. &types.APIRequestMetadata{
  238. Verb: types.APIVerbDelete,
  239. Method: types.HTTPVerbDelete,
  240. Path: &types.Path{
  241. Parent: basePath,
  242. RelativePath: relPath + "/envgroup",
  243. },
  244. Scopes: []types.PermissionScope{
  245. types.UserScope,
  246. types.ProjectScope,
  247. types.ClusterScope,
  248. types.NamespaceScope,
  249. },
  250. },
  251. )
  252. deleteEnvGroupHandler := namespace.NewDeleteEnvGroupHandler(
  253. config,
  254. factory.GetDecoderValidator(),
  255. factory.GetResultWriter(),
  256. )
  257. routes = append(routes, &Route{
  258. Endpoint: deleteEnvGroupEndpoint,
  259. Handler: deleteEnvGroupHandler,
  260. Router: r,
  261. })
  262. // POST /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/configmap/update -> namespace.NewUpdateConfigMapHandler
  263. updateConfigMapEndpoint := factory.NewAPIEndpoint(
  264. &types.APIRequestMetadata{
  265. Verb: types.APIVerbUpdate,
  266. Method: types.HTTPVerbPost,
  267. Path: &types.Path{
  268. Parent: basePath,
  269. RelativePath: relPath + "/configmap/update",
  270. },
  271. Scopes: []types.PermissionScope{
  272. types.UserScope,
  273. types.ProjectScope,
  274. types.ClusterScope,
  275. types.NamespaceScope,
  276. },
  277. },
  278. )
  279. updateConfigMapHandler := namespace.NewUpdateConfigMapHandler(
  280. config,
  281. factory.GetDecoderValidator(),
  282. factory.GetResultWriter(),
  283. )
  284. routes = append(routes, &Route{
  285. Endpoint: updateConfigMapEndpoint,
  286. Handler: updateConfigMapHandler,
  287. Router: r,
  288. })
  289. // DELETE /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/crd -> namespace.NewCRDDeleteHandler
  290. deleteCRDEndpoint := factory.NewAPIEndpoint(
  291. &types.APIRequestMetadata{
  292. Verb: types.APIVerbDelete,
  293. Method: types.HTTPVerbDelete,
  294. Path: &types.Path{
  295. Parent: basePath,
  296. RelativePath: relPath + "/crd",
  297. },
  298. Scopes: []types.PermissionScope{
  299. types.UserScope,
  300. types.ProjectScope,
  301. types.ClusterScope,
  302. },
  303. },
  304. )
  305. deleteCRDHandler := namespace.NewCRDDeleteHandler(
  306. config,
  307. factory.GetDecoderValidator(),
  308. factory.GetResultWriter(),
  309. )
  310. routes = append(routes, &Route{
  311. Endpoint: deleteCRDEndpoint,
  312. Handler: deleteCRDHandler,
  313. Router: r,
  314. })
  315. // GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/releases -> namespace.NewListReleasesHandler
  316. listReleasesEndpoint := factory.NewAPIEndpoint(
  317. &types.APIRequestMetadata{
  318. Verb: types.APIVerbGet,
  319. Method: types.HTTPVerbGet,
  320. Path: &types.Path{
  321. Parent: basePath,
  322. RelativePath: relPath + "/releases",
  323. },
  324. Scopes: []types.PermissionScope{
  325. types.UserScope,
  326. types.ProjectScope,
  327. types.ClusterScope,
  328. types.NamespaceScope,
  329. },
  330. },
  331. )
  332. listReleasesHandler := namespace.NewListReleasesHandler(
  333. config,
  334. factory.GetDecoderValidator(),
  335. factory.GetResultWriter(),
  336. )
  337. routes = append(routes, &Route{
  338. Endpoint: listReleasesEndpoint,
  339. Handler: listReleasesHandler,
  340. Router: r,
  341. })
  342. // GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/pod/{name}/logs -> namespace.NewStreamPodLogsHandler
  343. streamPodLogsEndpoint := factory.NewAPIEndpoint(
  344. &types.APIRequestMetadata{
  345. Verb: types.APIVerbGet,
  346. Method: types.HTTPVerbGet,
  347. Path: &types.Path{
  348. Parent: basePath,
  349. RelativePath: fmt.Sprintf(
  350. "%s/pod/{%s}/logs",
  351. relPath,
  352. types.URLParamPodName,
  353. ),
  354. },
  355. Scopes: []types.PermissionScope{
  356. types.UserScope,
  357. types.ProjectScope,
  358. types.ClusterScope,
  359. types.NamespaceScope,
  360. },
  361. IsWebsocket: true,
  362. },
  363. )
  364. streamPodLogsHandler := namespace.NewStreamPodLogsHandler(
  365. config,
  366. factory.GetDecoderValidator(),
  367. factory.GetResultWriter(),
  368. )
  369. routes = append(routes, &Route{
  370. Endpoint: streamPodLogsEndpoint,
  371. Handler: streamPodLogsHandler,
  372. Router: r,
  373. })
  374. // GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/jobs/stream -> namespace.NewStreamJobRunsHandler
  375. streamJobRunsEndpoint := factory.NewAPIEndpoint(
  376. &types.APIRequestMetadata{
  377. Verb: types.APIVerbGet,
  378. Method: types.HTTPVerbGet,
  379. Path: &types.Path{
  380. Parent: basePath,
  381. RelativePath: fmt.Sprintf(
  382. "%s/jobs/stream",
  383. relPath,
  384. ),
  385. },
  386. Scopes: []types.PermissionScope{
  387. types.UserScope,
  388. types.ProjectScope,
  389. types.ClusterScope,
  390. types.NamespaceScope,
  391. },
  392. IsWebsocket: true,
  393. },
  394. )
  395. streamJobRunsHandler := namespace.NewStreamJobRunsHandler(
  396. config,
  397. factory.GetDecoderValidator(),
  398. factory.GetResultWriter(),
  399. )
  400. routes = append(routes, &Route{
  401. Endpoint: streamJobRunsEndpoint,
  402. Handler: streamJobRunsHandler,
  403. Router: r,
  404. })
  405. // GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/pod/{name}/previous_logs
  406. getPreviousLogsEndpoint := factory.NewAPIEndpoint(
  407. &types.APIRequestMetadata{
  408. Verb: types.APIVerbGet,
  409. Method: types.HTTPVerbGet,
  410. Path: &types.Path{
  411. Parent: basePath,
  412. RelativePath: fmt.Sprintf(
  413. "%s/pod/{%s}/previous_logs",
  414. relPath,
  415. types.URLParamPodName,
  416. ),
  417. },
  418. Scopes: []types.PermissionScope{
  419. types.UserScope,
  420. types.ProjectScope,
  421. types.ClusterScope,
  422. types.NamespaceScope,
  423. },
  424. },
  425. )
  426. getPreviousLogsHandler := namespace.NewGetPreviousLogsHandler(
  427. config,
  428. factory.GetDecoderValidator(),
  429. factory.GetResultWriter(),
  430. )
  431. routes = append(routes, &Route{
  432. Endpoint: getPreviousLogsEndpoint,
  433. Handler: getPreviousLogsHandler,
  434. Router: r,
  435. })
  436. // GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/jobs/{name}/pods -> jobs.NewGetPodsHandler
  437. getJobPodsEndpoint := factory.NewAPIEndpoint(
  438. &types.APIRequestMetadata{
  439. Verb: types.APIVerbList,
  440. Method: types.HTTPVerbGet,
  441. Path: &types.Path{
  442. Parent: basePath,
  443. RelativePath: fmt.Sprintf(
  444. "%s/jobs/{%s}/pods",
  445. relPath,
  446. types.URLParamJobName,
  447. ),
  448. },
  449. Scopes: []types.PermissionScope{
  450. types.UserScope,
  451. types.ProjectScope,
  452. types.ClusterScope,
  453. types.NamespaceScope,
  454. },
  455. },
  456. )
  457. getJobPodsHandler := job.NewGetPodsHandler(
  458. config,
  459. factory.GetResultWriter(),
  460. )
  461. routes = append(routes, &Route{
  462. Endpoint: getJobPodsEndpoint,
  463. Handler: getJobPodsHandler,
  464. Router: r,
  465. })
  466. // DELETE /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/jobs/{name} -> jobs.NewDeleteHandler
  467. deleteJobEndpoint := factory.NewAPIEndpoint(
  468. &types.APIRequestMetadata{
  469. Verb: types.APIVerbDelete,
  470. Method: types.HTTPVerbDelete,
  471. Path: &types.Path{
  472. Parent: basePath,
  473. RelativePath: fmt.Sprintf(
  474. "%s/jobs/{%s}",
  475. relPath,
  476. types.URLParamJobName,
  477. ),
  478. },
  479. Scopes: []types.PermissionScope{
  480. types.UserScope,
  481. types.ProjectScope,
  482. types.ClusterScope,
  483. types.NamespaceScope,
  484. },
  485. },
  486. )
  487. deleteJobHandler := job.NewDeleteHandler(
  488. config,
  489. )
  490. routes = append(routes, &Route{
  491. Endpoint: deleteJobEndpoint,
  492. Handler: deleteJobHandler,
  493. Router: r,
  494. })
  495. // POST /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/jobs/{name}/stop -> jobs.NewStopHandler
  496. stopJobEndpoint := factory.NewAPIEndpoint(
  497. &types.APIRequestMetadata{
  498. Verb: types.APIVerbUpdate,
  499. Method: types.HTTPVerbPost,
  500. Path: &types.Path{
  501. Parent: basePath,
  502. RelativePath: fmt.Sprintf(
  503. "%s/jobs/{%s}/stop",
  504. relPath,
  505. types.URLParamJobName,
  506. ),
  507. },
  508. Scopes: []types.PermissionScope{
  509. types.UserScope,
  510. types.ProjectScope,
  511. types.ClusterScope,
  512. types.NamespaceScope,
  513. },
  514. },
  515. )
  516. stopJobHandler := job.NewStopHandler(
  517. config,
  518. )
  519. routes = append(routes, &Route{
  520. Endpoint: stopJobEndpoint,
  521. Handler: stopJobHandler,
  522. Router: r,
  523. })
  524. // GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/pods/{name} -> namespace.NewGetPodHandler
  525. getPodEndpoint := factory.NewAPIEndpoint(
  526. &types.APIRequestMetadata{
  527. Verb: types.APIVerbGet,
  528. Method: types.HTTPVerbGet,
  529. Path: &types.Path{
  530. Parent: basePath,
  531. RelativePath: fmt.Sprintf(
  532. "%s/pods/{%s}",
  533. relPath,
  534. types.URLParamPodName,
  535. ),
  536. },
  537. Scopes: []types.PermissionScope{
  538. types.UserScope,
  539. types.ProjectScope,
  540. types.ClusterScope,
  541. types.NamespaceScope,
  542. },
  543. },
  544. )
  545. getPodHandler := namespace.NewGetPodHandler(
  546. config,
  547. factory.GetResultWriter(),
  548. )
  549. routes = append(routes, &Route{
  550. Endpoint: getPodEndpoint,
  551. Handler: getPodHandler,
  552. Router: r,
  553. })
  554. // DELETE /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/pods/{name} -> namespace.NewDeletePodHandler
  555. deletePodEndpoint := factory.NewAPIEndpoint(
  556. &types.APIRequestMetadata{
  557. Verb: types.APIVerbDelete,
  558. Method: types.HTTPVerbDelete,
  559. Path: &types.Path{
  560. Parent: basePath,
  561. RelativePath: fmt.Sprintf(
  562. "%s/pods/{%s}",
  563. relPath,
  564. types.URLParamPodName,
  565. ),
  566. },
  567. Scopes: []types.PermissionScope{
  568. types.UserScope,
  569. types.ProjectScope,
  570. types.ClusterScope,
  571. types.NamespaceScope,
  572. },
  573. },
  574. )
  575. deletePodHandler := namespace.NewDeletePodHandler(
  576. config,
  577. )
  578. routes = append(routes, &Route{
  579. Endpoint: deletePodEndpoint,
  580. Handler: deletePodHandler,
  581. Router: r,
  582. })
  583. // GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/pods/{name}/events -> namespace.NewGetPodEventsHandler
  584. getPodEventsEndpoint := factory.NewAPIEndpoint(
  585. &types.APIRequestMetadata{
  586. Verb: types.APIVerbList,
  587. Method: types.HTTPVerbGet,
  588. Path: &types.Path{
  589. Parent: basePath,
  590. RelativePath: fmt.Sprintf(
  591. "%s/pods/{%s}/events",
  592. relPath,
  593. types.URLParamPodName,
  594. ),
  595. },
  596. Scopes: []types.PermissionScope{
  597. types.UserScope,
  598. types.ProjectScope,
  599. types.ClusterScope,
  600. types.NamespaceScope,
  601. },
  602. },
  603. )
  604. getPodEventsHandler := namespace.NewGetPodEventsHandler(
  605. config,
  606. factory.GetResultWriter(),
  607. )
  608. routes = append(routes, &Route{
  609. Endpoint: getPodEventsEndpoint,
  610. Handler: getPodEventsHandler,
  611. Router: r,
  612. })
  613. // GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/ingresses/{name} ->
  614. // namespace.NewGetIngressHandler
  615. getIngressEndpoint := factory.NewAPIEndpoint(
  616. &types.APIRequestMetadata{
  617. Verb: types.APIVerbGet,
  618. Method: types.HTTPVerbGet,
  619. Path: &types.Path{
  620. Parent: basePath,
  621. RelativePath: relPath + "/ingresses/{name}",
  622. },
  623. Scopes: []types.PermissionScope{
  624. types.UserScope,
  625. types.ProjectScope,
  626. types.ClusterScope,
  627. types.NamespaceScope,
  628. },
  629. },
  630. )
  631. getIngressHandler := namespace.NewGetIngressHandler(
  632. config,
  633. factory.GetResultWriter(),
  634. )
  635. routes = append(routes, &Route{
  636. Endpoint: getIngressEndpoint,
  637. Handler: getIngressHandler,
  638. Router: r,
  639. })
  640. return routes, newPath
  641. }