namespace.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751
  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}/logs/loki -> namespace.NewStreamPodLogsLokiHandler
  376. streamPodLogsLokiEndpoint := 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/logs/loki",
  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. streamPodLogsLokiHandler := namespace.NewStreamPodLogsLokiHandler(
  397. config,
  398. factory.GetDecoderValidator(),
  399. factory.GetResultWriter(),
  400. )
  401. routes = append(routes, &router.Route{
  402. Endpoint: streamPodLogsLokiEndpoint,
  403. Handler: streamPodLogsLokiHandler,
  404. Router: r,
  405. })
  406. // GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/jobs/stream -> namespace.NewStreamJobRunsHandler
  407. streamJobRunsEndpoint := 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/jobs/stream",
  415. relPath,
  416. ),
  417. },
  418. Scopes: []types.PermissionScope{
  419. types.UserScope,
  420. types.ProjectScope,
  421. types.ClusterScope,
  422. types.NamespaceScope,
  423. },
  424. IsWebsocket: true,
  425. },
  426. )
  427. streamJobRunsHandler := namespace.NewStreamJobRunsHandler(
  428. config,
  429. factory.GetDecoderValidator(),
  430. factory.GetResultWriter(),
  431. )
  432. routes = append(routes, &router.Route{
  433. Endpoint: streamJobRunsEndpoint,
  434. Handler: streamJobRunsHandler,
  435. Router: r,
  436. })
  437. // GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/pod/{name}/previous_logs
  438. getPreviousLogsEndpoint := factory.NewAPIEndpoint(
  439. &types.APIRequestMetadata{
  440. Verb: types.APIVerbGet,
  441. Method: types.HTTPVerbGet,
  442. Path: &types.Path{
  443. Parent: basePath,
  444. RelativePath: fmt.Sprintf(
  445. "%s/pod/{%s}/previous_logs",
  446. relPath,
  447. types.URLParamPodName,
  448. ),
  449. },
  450. Scopes: []types.PermissionScope{
  451. types.UserScope,
  452. types.ProjectScope,
  453. types.ClusterScope,
  454. types.NamespaceScope,
  455. },
  456. },
  457. )
  458. getPreviousLogsHandler := namespace.NewGetPreviousLogsHandler(
  459. config,
  460. factory.GetDecoderValidator(),
  461. factory.GetResultWriter(),
  462. )
  463. routes = append(routes, &router.Route{
  464. Endpoint: getPreviousLogsEndpoint,
  465. Handler: getPreviousLogsHandler,
  466. Router: r,
  467. })
  468. // GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/jobs/{name}/pods -> jobs.NewGetPodsHandler
  469. getJobPodsEndpoint := factory.NewAPIEndpoint(
  470. &types.APIRequestMetadata{
  471. Verb: types.APIVerbList,
  472. Method: types.HTTPVerbGet,
  473. Path: &types.Path{
  474. Parent: basePath,
  475. RelativePath: fmt.Sprintf(
  476. "%s/jobs/{%s}/pods",
  477. relPath,
  478. types.URLParamJobName,
  479. ),
  480. },
  481. Scopes: []types.PermissionScope{
  482. types.UserScope,
  483. types.ProjectScope,
  484. types.ClusterScope,
  485. types.NamespaceScope,
  486. },
  487. },
  488. )
  489. getJobPodsHandler := job.NewGetPodsHandler(
  490. config,
  491. factory.GetResultWriter(),
  492. )
  493. routes = append(routes, &router.Route{
  494. Endpoint: getJobPodsEndpoint,
  495. Handler: getJobPodsHandler,
  496. Router: r,
  497. })
  498. // DELETE /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/jobs/{name} -> jobs.NewDeleteHandler
  499. deleteJobEndpoint := factory.NewAPIEndpoint(
  500. &types.APIRequestMetadata{
  501. Verb: types.APIVerbDelete,
  502. Method: types.HTTPVerbDelete,
  503. Path: &types.Path{
  504. Parent: basePath,
  505. RelativePath: fmt.Sprintf(
  506. "%s/jobs/{%s}",
  507. relPath,
  508. types.URLParamJobName,
  509. ),
  510. },
  511. Scopes: []types.PermissionScope{
  512. types.UserScope,
  513. types.ProjectScope,
  514. types.ClusterScope,
  515. types.NamespaceScope,
  516. },
  517. },
  518. )
  519. deleteJobHandler := job.NewDeleteHandler(
  520. config,
  521. )
  522. routes = append(routes, &router.Route{
  523. Endpoint: deleteJobEndpoint,
  524. Handler: deleteJobHandler,
  525. Router: r,
  526. })
  527. // POST /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/jobs/{name}/stop -> jobs.NewStopHandler
  528. stopJobEndpoint := factory.NewAPIEndpoint(
  529. &types.APIRequestMetadata{
  530. Verb: types.APIVerbUpdate,
  531. Method: types.HTTPVerbPost,
  532. Path: &types.Path{
  533. Parent: basePath,
  534. RelativePath: fmt.Sprintf(
  535. "%s/jobs/{%s}/stop",
  536. relPath,
  537. types.URLParamJobName,
  538. ),
  539. },
  540. Scopes: []types.PermissionScope{
  541. types.UserScope,
  542. types.ProjectScope,
  543. types.ClusterScope,
  544. types.NamespaceScope,
  545. },
  546. },
  547. )
  548. stopJobHandler := job.NewStopHandler(
  549. config,
  550. )
  551. routes = append(routes, &router.Route{
  552. Endpoint: stopJobEndpoint,
  553. Handler: stopJobHandler,
  554. Router: r,
  555. })
  556. // GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/pods/{name} -> namespace.NewGetPodHandler
  557. getPodEndpoint := factory.NewAPIEndpoint(
  558. &types.APIRequestMetadata{
  559. Verb: types.APIVerbGet,
  560. Method: types.HTTPVerbGet,
  561. Path: &types.Path{
  562. Parent: basePath,
  563. RelativePath: fmt.Sprintf(
  564. "%s/pods/{%s}",
  565. relPath,
  566. types.URLParamPodName,
  567. ),
  568. },
  569. Scopes: []types.PermissionScope{
  570. types.UserScope,
  571. types.ProjectScope,
  572. types.ClusterScope,
  573. types.NamespaceScope,
  574. },
  575. },
  576. )
  577. getPodHandler := namespace.NewGetPodHandler(
  578. config,
  579. factory.GetResultWriter(),
  580. )
  581. routes = append(routes, &router.Route{
  582. Endpoint: getPodEndpoint,
  583. Handler: getPodHandler,
  584. Router: r,
  585. })
  586. // DELETE /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/pods/{name} -> namespace.NewDeletePodHandler
  587. deletePodEndpoint := factory.NewAPIEndpoint(
  588. &types.APIRequestMetadata{
  589. Verb: types.APIVerbDelete,
  590. Method: types.HTTPVerbDelete,
  591. Path: &types.Path{
  592. Parent: basePath,
  593. RelativePath: fmt.Sprintf(
  594. "%s/pods/{%s}",
  595. relPath,
  596. types.URLParamPodName,
  597. ),
  598. },
  599. Scopes: []types.PermissionScope{
  600. types.UserScope,
  601. types.ProjectScope,
  602. types.ClusterScope,
  603. types.NamespaceScope,
  604. },
  605. },
  606. )
  607. deletePodHandler := namespace.NewDeletePodHandler(
  608. config,
  609. )
  610. routes = append(routes, &router.Route{
  611. Endpoint: deletePodEndpoint,
  612. Handler: deletePodHandler,
  613. Router: r,
  614. })
  615. // GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/pods/{name}/events -> namespace.NewGetPodEventsHandler
  616. getPodEventsEndpoint := factory.NewAPIEndpoint(
  617. &types.APIRequestMetadata{
  618. Verb: types.APIVerbList,
  619. Method: types.HTTPVerbGet,
  620. Path: &types.Path{
  621. Parent: basePath,
  622. RelativePath: fmt.Sprintf(
  623. "%s/pods/{%s}/events",
  624. relPath,
  625. types.URLParamPodName,
  626. ),
  627. },
  628. Scopes: []types.PermissionScope{
  629. types.UserScope,
  630. types.ProjectScope,
  631. types.ClusterScope,
  632. types.NamespaceScope,
  633. },
  634. },
  635. )
  636. getPodEventsHandler := namespace.NewGetPodEventsHandler(
  637. config,
  638. factory.GetResultWriter(),
  639. )
  640. routes = append(routes, &router.Route{
  641. Endpoint: getPodEventsEndpoint,
  642. Handler: getPodEventsHandler,
  643. Router: r,
  644. })
  645. // GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/ingresses/{name} ->
  646. // namespace.NewGetIngressHandler
  647. getIngressEndpoint := factory.NewAPIEndpoint(
  648. &types.APIRequestMetadata{
  649. Verb: types.APIVerbGet,
  650. Method: types.HTTPVerbGet,
  651. Path: &types.Path{
  652. Parent: basePath,
  653. RelativePath: relPath + "/ingresses/{name}",
  654. },
  655. Scopes: []types.PermissionScope{
  656. types.UserScope,
  657. types.ProjectScope,
  658. types.ClusterScope,
  659. types.NamespaceScope,
  660. },
  661. },
  662. )
  663. getIngressHandler := namespace.NewGetIngressHandler(
  664. config,
  665. factory.GetResultWriter(),
  666. )
  667. routes = append(routes, &router.Route{
  668. Endpoint: getIngressEndpoint,
  669. Handler: getIngressHandler,
  670. Router: r,
  671. })
  672. return routes, newPath
  673. }