namespace.go 18 KB

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