namespace.go 18 KB

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