2
0

namespace.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780
  1. package router
  2. import (
  3. "fmt"
  4. "github.com/go-chi/chi/v5"
  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}/stacks/envgroup/create -> namespace.NewCreateEnvGroupHandler
  183. createStacksEnvGroupEndpoint := factory.NewAPIEndpoint(
  184. &types.APIRequestMetadata{
  185. Verb: types.APIVerbCreate,
  186. Method: types.HTTPVerbPost,
  187. Path: &types.Path{
  188. Parent: basePath,
  189. RelativePath: relPath + "/stacks/envgroup/create",
  190. },
  191. Scopes: []types.PermissionScope{
  192. types.UserScope,
  193. types.ProjectScope,
  194. types.ClusterScope,
  195. types.NamespaceScope,
  196. },
  197. },
  198. )
  199. createStacksEnvGroupHandler := namespace.NewCreateStacksEnvGroupHandler(
  200. config,
  201. factory.GetDecoderValidator(),
  202. factory.GetResultWriter(),
  203. )
  204. routes = append(routes, &router.Route{
  205. Endpoint: createStacksEnvGroupEndpoint,
  206. Handler: createStacksEnvGroupHandler,
  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, &router.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, &router.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, &router.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, &router.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, &router.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, &router.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, &router.Route{
  398. Endpoint: streamPodLogsEndpoint,
  399. Handler: streamPodLogsHandler,
  400. Router: r,
  401. })
  402. // GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/logs/loki -> namespace.NewStreamPodLogsLokiHandler
  403. streamPodLogsLokiEndpoint := 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/logs/loki",
  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. streamPodLogsLokiHandler := namespace.NewStreamPodLogsLokiHandler(
  424. config,
  425. factory.GetDecoderValidator(),
  426. factory.GetResultWriter(),
  427. )
  428. routes = append(routes, &router.Route{
  429. Endpoint: streamPodLogsLokiEndpoint,
  430. Handler: streamPodLogsLokiHandler,
  431. Router: r,
  432. })
  433. // GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/jobs/stream -> namespace.NewStreamJobRunsHandler
  434. streamJobRunsEndpoint := 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/jobs/stream",
  442. relPath,
  443. ),
  444. },
  445. Scopes: []types.PermissionScope{
  446. types.UserScope,
  447. types.ProjectScope,
  448. types.ClusterScope,
  449. types.NamespaceScope,
  450. },
  451. IsWebsocket: true,
  452. },
  453. )
  454. streamJobRunsHandler := namespace.NewStreamJobRunsHandler(
  455. config,
  456. factory.GetDecoderValidator(),
  457. factory.GetResultWriter(),
  458. )
  459. routes = append(routes, &router.Route{
  460. Endpoint: streamJobRunsEndpoint,
  461. Handler: streamJobRunsHandler,
  462. Router: r,
  463. })
  464. // GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/pod/{name}/previous_logs
  465. getPreviousLogsEndpoint := factory.NewAPIEndpoint(
  466. &types.APIRequestMetadata{
  467. Verb: types.APIVerbGet,
  468. Method: types.HTTPVerbGet,
  469. Path: &types.Path{
  470. Parent: basePath,
  471. RelativePath: fmt.Sprintf(
  472. "%s/pod/{%s}/previous_logs",
  473. relPath,
  474. types.URLParamPodName,
  475. ),
  476. },
  477. Scopes: []types.PermissionScope{
  478. types.UserScope,
  479. types.ProjectScope,
  480. types.ClusterScope,
  481. types.NamespaceScope,
  482. },
  483. },
  484. )
  485. getPreviousLogsHandler := namespace.NewGetPreviousLogsHandler(
  486. config,
  487. factory.GetDecoderValidator(),
  488. factory.GetResultWriter(),
  489. )
  490. routes = append(routes, &router.Route{
  491. Endpoint: getPreviousLogsEndpoint,
  492. Handler: getPreviousLogsHandler,
  493. Router: r,
  494. })
  495. // GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/jobs/{name}/pods -> jobs.NewGetPodsHandler
  496. getJobPodsEndpoint := factory.NewAPIEndpoint(
  497. &types.APIRequestMetadata{
  498. Verb: types.APIVerbList,
  499. Method: types.HTTPVerbGet,
  500. Path: &types.Path{
  501. Parent: basePath,
  502. RelativePath: fmt.Sprintf(
  503. "%s/jobs/{%s}/pods",
  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. getJobPodsHandler := job.NewGetPodsHandler(
  517. config,
  518. factory.GetResultWriter(),
  519. )
  520. routes = append(routes, &router.Route{
  521. Endpoint: getJobPodsEndpoint,
  522. Handler: getJobPodsHandler,
  523. Router: r,
  524. })
  525. // DELETE /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/jobs/{name} -> jobs.NewDeleteHandler
  526. deleteJobEndpoint := factory.NewAPIEndpoint(
  527. &types.APIRequestMetadata{
  528. Verb: types.APIVerbDelete,
  529. Method: types.HTTPVerbDelete,
  530. Path: &types.Path{
  531. Parent: basePath,
  532. RelativePath: fmt.Sprintf(
  533. "%s/jobs/{%s}",
  534. relPath,
  535. types.URLParamJobName,
  536. ),
  537. },
  538. Scopes: []types.PermissionScope{
  539. types.UserScope,
  540. types.ProjectScope,
  541. types.ClusterScope,
  542. types.NamespaceScope,
  543. },
  544. },
  545. )
  546. deleteJobHandler := job.NewDeleteHandler(
  547. config,
  548. )
  549. routes = append(routes, &router.Route{
  550. Endpoint: deleteJobEndpoint,
  551. Handler: deleteJobHandler,
  552. Router: r,
  553. })
  554. // POST /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/jobs/{name}/stop -> jobs.NewStopHandler
  555. stopJobEndpoint := factory.NewAPIEndpoint(
  556. &types.APIRequestMetadata{
  557. Verb: types.APIVerbUpdate,
  558. Method: types.HTTPVerbPost,
  559. Path: &types.Path{
  560. Parent: basePath,
  561. RelativePath: fmt.Sprintf(
  562. "%s/jobs/{%s}/stop",
  563. relPath,
  564. types.URLParamJobName,
  565. ),
  566. },
  567. Scopes: []types.PermissionScope{
  568. types.UserScope,
  569. types.ProjectScope,
  570. types.ClusterScope,
  571. types.NamespaceScope,
  572. },
  573. },
  574. )
  575. stopJobHandler := job.NewStopHandler(
  576. config,
  577. )
  578. routes = append(routes, &router.Route{
  579. Endpoint: stopJobEndpoint,
  580. Handler: stopJobHandler,
  581. Router: r,
  582. })
  583. // GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/pods/{name} -> namespace.NewGetPodHandler
  584. getPodEndpoint := factory.NewAPIEndpoint(
  585. &types.APIRequestMetadata{
  586. Verb: types.APIVerbGet,
  587. Method: types.HTTPVerbGet,
  588. Path: &types.Path{
  589. Parent: basePath,
  590. RelativePath: fmt.Sprintf(
  591. "%s/pods/{%s}",
  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. getPodHandler := namespace.NewGetPodHandler(
  605. config,
  606. factory.GetResultWriter(),
  607. )
  608. routes = append(routes, &router.Route{
  609. Endpoint: getPodEndpoint,
  610. Handler: getPodHandler,
  611. Router: r,
  612. })
  613. // DELETE /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/pods/{name} -> namespace.NewDeletePodHandler
  614. deletePodEndpoint := factory.NewAPIEndpoint(
  615. &types.APIRequestMetadata{
  616. Verb: types.APIVerbDelete,
  617. Method: types.HTTPVerbDelete,
  618. Path: &types.Path{
  619. Parent: basePath,
  620. RelativePath: fmt.Sprintf(
  621. "%s/pods/{%s}",
  622. relPath,
  623. types.URLParamPodName,
  624. ),
  625. },
  626. Scopes: []types.PermissionScope{
  627. types.UserScope,
  628. types.ProjectScope,
  629. types.ClusterScope,
  630. types.NamespaceScope,
  631. },
  632. },
  633. )
  634. deletePodHandler := namespace.NewDeletePodHandler(
  635. config,
  636. )
  637. routes = append(routes, &router.Route{
  638. Endpoint: deletePodEndpoint,
  639. Handler: deletePodHandler,
  640. Router: r,
  641. })
  642. // GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/pods/{name}/events -> namespace.NewGetPodEventsHandler
  643. getPodEventsEndpoint := factory.NewAPIEndpoint(
  644. &types.APIRequestMetadata{
  645. Verb: types.APIVerbList,
  646. Method: types.HTTPVerbGet,
  647. Path: &types.Path{
  648. Parent: basePath,
  649. RelativePath: fmt.Sprintf(
  650. "%s/pods/{%s}/events",
  651. relPath,
  652. types.URLParamPodName,
  653. ),
  654. },
  655. Scopes: []types.PermissionScope{
  656. types.UserScope,
  657. types.ProjectScope,
  658. types.ClusterScope,
  659. types.NamespaceScope,
  660. },
  661. },
  662. )
  663. getPodEventsHandler := namespace.NewGetPodEventsHandler(
  664. config,
  665. factory.GetResultWriter(),
  666. )
  667. routes = append(routes, &router.Route{
  668. Endpoint: getPodEventsEndpoint,
  669. Handler: getPodEventsHandler,
  670. Router: r,
  671. })
  672. // GET /api/projects/{project_id}/clusters/{cluster_id}/namespaces/{namespace}/ingresses/{name} ->
  673. // namespace.NewGetIngressHandler
  674. getIngressEndpoint := factory.NewAPIEndpoint(
  675. &types.APIRequestMetadata{
  676. Verb: types.APIVerbGet,
  677. Method: types.HTTPVerbGet,
  678. Path: &types.Path{
  679. Parent: basePath,
  680. RelativePath: relPath + "/ingresses/{name}",
  681. },
  682. Scopes: []types.PermissionScope{
  683. types.UserScope,
  684. types.ProjectScope,
  685. types.ClusterScope,
  686. types.NamespaceScope,
  687. },
  688. },
  689. )
  690. getIngressHandler := namespace.NewGetIngressHandler(
  691. config,
  692. factory.GetResultWriter(),
  693. )
  694. routes = append(routes, &router.Route{
  695. Endpoint: getIngressEndpoint,
  696. Handler: getIngressHandler,
  697. Router: r,
  698. })
  699. return routes, newPath
  700. }