porter_app.go 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767
  1. package router
  2. import (
  3. "fmt"
  4. "github.com/go-chi/chi/v5"
  5. "github.com/porter-dev/porter/api/server/handlers/porter_app"
  6. "github.com/porter-dev/porter/api/server/shared"
  7. "github.com/porter-dev/porter/api/server/shared/config"
  8. "github.com/porter-dev/porter/api/server/shared/router"
  9. "github.com/porter-dev/porter/api/types"
  10. )
  11. func NewPorterAppScopedRegisterer(children ...*router.Registerer) *router.Registerer {
  12. return &router.Registerer{
  13. GetRoutes: GetPorterAppScopedRoutes,
  14. Children: children,
  15. }
  16. }
  17. func GetPorterAppScopedRoutes(
  18. r chi.Router,
  19. config *config.Config,
  20. basePath *types.Path,
  21. factory shared.APIEndpointFactory,
  22. children ...*router.Registerer,
  23. ) []*router.Route {
  24. routes, projPath := getPorterAppRoutes(r, config, basePath, factory)
  25. if len(children) > 0 {
  26. r.Route(projPath.RelativePath, func(r chi.Router) {
  27. for _, child := range children {
  28. childRoutes := child.GetRoutes(r, config, basePath, factory, child.Children...)
  29. routes = append(routes, childRoutes...)
  30. }
  31. })
  32. }
  33. return routes
  34. }
  35. func getPorterAppRoutes(
  36. r chi.Router,
  37. config *config.Config,
  38. basePath *types.Path,
  39. factory shared.APIEndpointFactory,
  40. ) ([]*router.Route, *types.Path) {
  41. relPath := "/applications"
  42. relPathV2 := "/apps"
  43. newPath := &types.Path{
  44. Parent: basePath,
  45. RelativePath: relPath,
  46. }
  47. var routes []*router.Route
  48. // GET /api/projects/{project_id}/clusters/{cluster_id}/applications/{name} -> porter_app.NewPorterAppGetHandler
  49. getPorterAppEndpoint := factory.NewAPIEndpoint(
  50. &types.APIRequestMetadata{
  51. Verb: types.APIVerbGet,
  52. Method: types.HTTPVerbGet,
  53. Path: &types.Path{
  54. Parent: basePath,
  55. RelativePath: fmt.Sprintf("%s/{%s}", relPath, types.URLParamPorterAppName),
  56. },
  57. Scopes: []types.PermissionScope{
  58. types.UserScope,
  59. types.ProjectScope,
  60. types.ClusterScope,
  61. },
  62. },
  63. )
  64. getPorterAppHandler := porter_app.NewGetPorterAppHandler(
  65. config,
  66. factory.GetResultWriter(),
  67. )
  68. routes = append(routes, &router.Route{
  69. Endpoint: getPorterAppEndpoint,
  70. Handler: getPorterAppHandler,
  71. Router: r,
  72. })
  73. // GET /api/projects/{project_id}/clusters/{cluster_id}/applications/{name}/releases/{version} -> porter_app.NewPorterAppReleaseGetHandler
  74. getPorterAppHelmReleaseEndpoint := factory.NewAPIEndpoint(
  75. &types.APIRequestMetadata{
  76. Verb: types.APIVerbList,
  77. Method: types.HTTPVerbGet,
  78. Path: &types.Path{
  79. Parent: basePath,
  80. RelativePath: fmt.Sprintf("%s/{%s}/releases/{%s}", relPath, types.URLParamPorterAppName, types.URLParamReleaseVersion),
  81. },
  82. Scopes: []types.PermissionScope{
  83. types.UserScope,
  84. types.ProjectScope,
  85. types.ClusterScope,
  86. },
  87. },
  88. )
  89. getPorterAppHelmReleaseHandler := porter_app.NewPorterAppHelmReleaseGetHandler(
  90. config,
  91. factory.GetResultWriter(),
  92. )
  93. routes = append(routes, &router.Route{
  94. Endpoint: getPorterAppHelmReleaseEndpoint,
  95. Handler: getPorterAppHelmReleaseHandler,
  96. Router: r,
  97. })
  98. // GET /api/projects/{project_id}/clusters/{cluster_id}/applications/{name}/release-history -> porter_app.NewPorterAppHelmReleaseHistoryGetHandler
  99. getPorterAppHelmReleaseHistoryGetEndpoint := factory.NewAPIEndpoint(
  100. &types.APIRequestMetadata{
  101. Verb: types.APIVerbList,
  102. Method: types.HTTPVerbGet,
  103. Path: &types.Path{
  104. Parent: basePath,
  105. RelativePath: fmt.Sprintf("%s/{%s}/release-history", relPath, types.URLParamPorterAppName),
  106. },
  107. Scopes: []types.PermissionScope{
  108. types.UserScope,
  109. types.ProjectScope,
  110. types.ClusterScope,
  111. },
  112. },
  113. )
  114. getPorterAppHelmReleaseHistoryGetHandler := porter_app.NewPorterAppHelmReleaseHistoryGetHandler(
  115. config,
  116. factory.GetResultWriter(),
  117. )
  118. routes = append(routes, &router.Route{
  119. Endpoint: getPorterAppHelmReleaseHistoryGetEndpoint,
  120. Handler: getPorterAppHelmReleaseHistoryGetHandler,
  121. Router: r,
  122. })
  123. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/pods -> cluster.NewPodStatusHandler
  124. appPodStatusEndpoint := factory.NewAPIEndpoint(
  125. &types.APIRequestMetadata{
  126. Verb: types.APIVerbGet,
  127. Method: types.HTTPVerbGet,
  128. Path: &types.Path{
  129. Parent: basePath,
  130. RelativePath: fmt.Sprintf("%s/{%s}/pods", relPathV2, types.URLParamPorterAppName),
  131. },
  132. Scopes: []types.PermissionScope{
  133. types.UserScope,
  134. types.ProjectScope,
  135. types.ClusterScope,
  136. },
  137. },
  138. )
  139. appPodStatusHandler := porter_app.NewPodStatusHandler(
  140. config,
  141. factory.GetDecoderValidator(),
  142. factory.GetResultWriter(),
  143. )
  144. routes = append(routes, &router.Route{
  145. Endpoint: appPodStatusEndpoint,
  146. Handler: appPodStatusHandler,
  147. Router: r,
  148. })
  149. // GET /api/projects/{project_id}/clusters/{cluster_id}/applications/{name}/releases/{version}/pods/all -> porter_app.NewPorterAppPodsGetHandler
  150. getPorterAppPodsEndpoint := factory.NewAPIEndpoint(
  151. &types.APIRequestMetadata{
  152. Verb: types.APIVerbList,
  153. Method: types.HTTPVerbGet,
  154. Path: &types.Path{
  155. Parent: basePath,
  156. RelativePath: fmt.Sprintf("%s/{%s}/releases/{%s}/pods/all", relPath, types.URLParamPorterAppName, types.URLParamReleaseVersion),
  157. },
  158. Scopes: []types.PermissionScope{
  159. types.UserScope,
  160. types.ProjectScope,
  161. types.ClusterScope,
  162. },
  163. },
  164. )
  165. getPorterAppPodsHandler := porter_app.NewPorterAppPodsGetHandler(
  166. config,
  167. factory.GetResultWriter(),
  168. )
  169. routes = append(routes, &router.Route{
  170. Endpoint: getPorterAppPodsEndpoint,
  171. Handler: getPorterAppPodsHandler,
  172. Router: r,
  173. })
  174. // GET /api/projects/{project_id}/clusters/{cluster_id}/applications -> porter_app.NewPorterAppListHandler
  175. listPorterAppEndpoint := factory.NewAPIEndpoint(
  176. &types.APIRequestMetadata{
  177. Verb: types.APIVerbList,
  178. Method: types.HTTPVerbGet,
  179. Path: &types.Path{
  180. Parent: basePath,
  181. RelativePath: relPath,
  182. },
  183. Scopes: []types.PermissionScope{
  184. types.UserScope,
  185. types.ProjectScope,
  186. types.ClusterScope,
  187. },
  188. },
  189. )
  190. listPorterAppHandler := porter_app.NewPorterAppListHandler(
  191. config,
  192. factory.GetResultWriter(),
  193. )
  194. routes = append(routes, &router.Route{
  195. Endpoint: listPorterAppEndpoint,
  196. Handler: listPorterAppHandler,
  197. Router: r,
  198. })
  199. // DELETE /api/projects/{project_id}/clusters/{cluster_id}/applications/{porter_app_name} -> release.NewDeletePorterAppByNameHandler
  200. deletePorterAppByNameEndpoint := factory.NewAPIEndpoint(
  201. &types.APIRequestMetadata{
  202. Verb: types.APIVerbDelete,
  203. Method: types.HTTPVerbDelete,
  204. Path: &types.Path{
  205. Parent: basePath,
  206. RelativePath: fmt.Sprintf("%s/{%s}", relPath, types.URLParamPorterAppName),
  207. },
  208. Scopes: []types.PermissionScope{
  209. types.UserScope,
  210. types.ProjectScope,
  211. types.ClusterScope,
  212. },
  213. },
  214. )
  215. deletePorterAppByNameHandler := porter_app.NewDeletePorterAppByNameHandler(
  216. config,
  217. factory.GetDecoderValidator(),
  218. factory.GetResultWriter(),
  219. )
  220. routes = append(routes, &router.Route{
  221. Endpoint: deletePorterAppByNameEndpoint,
  222. Handler: deletePorterAppByNameHandler,
  223. Router: r,
  224. })
  225. // POST /api/projects/{project_id}/clusters/{cluster_id}/applications/{porter_app_name} -> porter_app.NewCreatePorterAppHandler
  226. createPorterAppEndpoint := factory.NewAPIEndpoint(
  227. &types.APIRequestMetadata{
  228. Verb: types.APIVerbCreate,
  229. Method: types.HTTPVerbPost,
  230. Path: &types.Path{
  231. Parent: basePath,
  232. RelativePath: fmt.Sprintf("%s/{%s}", relPath, types.URLParamPorterAppName),
  233. },
  234. Scopes: []types.PermissionScope{
  235. types.UserScope,
  236. types.ProjectScope,
  237. types.ClusterScope,
  238. },
  239. },
  240. )
  241. createPorterAppHandler := porter_app.NewCreatePorterAppHandler(
  242. config,
  243. factory.GetDecoderValidator(),
  244. factory.GetResultWriter(),
  245. )
  246. routes = append(routes, &router.Route{
  247. Endpoint: createPorterAppEndpoint,
  248. Handler: createPorterAppHandler,
  249. Router: r,
  250. })
  251. // POST /api/projects/{project_id}/clusters/{cluster_id}/applications/{porter_app_name}/rollback -> porter_app.NewRollbackPorterAppHandler
  252. rollbackPorterAppEndpoint := factory.NewAPIEndpoint(
  253. &types.APIRequestMetadata{
  254. Verb: types.APIVerbCreate,
  255. Method: types.HTTPVerbPost,
  256. Path: &types.Path{
  257. Parent: basePath,
  258. RelativePath: fmt.Sprintf("%s/{%s}/rollback", relPath, types.URLParamPorterAppName),
  259. },
  260. Scopes: []types.PermissionScope{
  261. types.UserScope,
  262. types.ProjectScope,
  263. types.ClusterScope,
  264. },
  265. },
  266. )
  267. rollbackPorterAppHandler := porter_app.NewRollbackPorterAppHandler(
  268. config,
  269. factory.GetDecoderValidator(),
  270. factory.GetResultWriter(),
  271. )
  272. routes = append(routes, &router.Route{
  273. Endpoint: rollbackPorterAppEndpoint,
  274. Handler: rollbackPorterAppHandler,
  275. Router: r,
  276. })
  277. // POST /api/projects/{project_id}/clusters/{cluster_id}/applications/{porter_app_name}/pr -> porter_app.NewOpenStackPRHandler
  278. createSecretAndOpenGitHubPullRequestEndpoint := factory.NewAPIEndpoint(
  279. &types.APIRequestMetadata{
  280. Verb: types.APIVerbCreate,
  281. Method: types.HTTPVerbPost,
  282. Path: &types.Path{
  283. Parent: basePath,
  284. RelativePath: fmt.Sprintf("%s/{%s}/pr", relPath, types.URLParamPorterAppName),
  285. },
  286. Scopes: []types.PermissionScope{
  287. types.UserScope,
  288. types.ProjectScope,
  289. types.ClusterScope,
  290. },
  291. },
  292. )
  293. createSecretAndOpenGitHubPullRequestHandler := porter_app.NewOpenStackPRHandler(
  294. config,
  295. factory.GetDecoderValidator(),
  296. factory.GetResultWriter(),
  297. )
  298. routes = append(routes, &router.Route{
  299. Endpoint: createSecretAndOpenGitHubPullRequestEndpoint,
  300. Handler: createSecretAndOpenGitHubPullRequestHandler,
  301. Router: r,
  302. })
  303. // GET /api/projects/{project_id}/clusters/{cluster_id}/applications/{porter_app_name}/events -> porter_app.NewPorterAppEventListHandler
  304. listPorterAppEventsEndpoint := factory.NewAPIEndpoint(
  305. &types.APIRequestMetadata{
  306. Verb: types.APIVerbList,
  307. Method: types.HTTPVerbGet,
  308. Path: &types.Path{
  309. Parent: basePath,
  310. RelativePath: fmt.Sprintf("%s/{%s}/events", relPath, types.URLParamPorterAppName),
  311. },
  312. Scopes: []types.PermissionScope{
  313. types.UserScope,
  314. types.ProjectScope,
  315. types.ClusterScope,
  316. },
  317. },
  318. )
  319. listPorterAppEventsHandler := porter_app.NewPorterAppEventListHandler(
  320. config,
  321. factory.GetResultWriter(),
  322. )
  323. routes = append(routes, &router.Route{
  324. Endpoint: listPorterAppEventsEndpoint,
  325. Handler: listPorterAppEventsHandler,
  326. Router: r,
  327. })
  328. // POST /api/projects/{project_id}/clusters/{cluster_id}/applications/{name}/events -> porter_app.NewCreatePorterAppEventHandler
  329. createPorterAppEventEndpoint := factory.NewAPIEndpoint(
  330. &types.APIRequestMetadata{
  331. Verb: types.APIVerbCreate,
  332. Method: types.HTTPVerbPost,
  333. Path: &types.Path{
  334. Parent: basePath,
  335. RelativePath: fmt.Sprintf("%s/{%s}/events", relPath, types.URLParamPorterAppName),
  336. },
  337. Scopes: []types.PermissionScope{
  338. types.UserScope,
  339. types.ProjectScope,
  340. types.ClusterScope,
  341. },
  342. },
  343. )
  344. createPorterAppEventHandler := porter_app.NewCreateUpdatePorterAppEventHandler(
  345. config,
  346. factory.GetDecoderValidator(),
  347. factory.GetResultWriter(),
  348. )
  349. routes = append(routes, &router.Route{
  350. Endpoint: createPorterAppEventEndpoint,
  351. Handler: createPorterAppEventHandler,
  352. Router: r,
  353. })
  354. // GET /api/projects/{project_id}/clusters/{cluster_id}/events/id -> porter_app.NewGetPorterAppEventHandler
  355. getPorterAppEventEndpoint := factory.NewAPIEndpoint(
  356. &types.APIRequestMetadata{
  357. Verb: types.APIVerbCreate,
  358. Method: types.HTTPVerbGet,
  359. Path: &types.Path{
  360. Parent: basePath,
  361. RelativePath: fmt.Sprintf("/events/{%s}", types.URLParamPorterAppEventID),
  362. },
  363. Scopes: []types.PermissionScope{
  364. types.UserScope,
  365. types.ProjectScope,
  366. types.ClusterScope,
  367. },
  368. },
  369. )
  370. getPorterAppEventHandler := porter_app.NewGetPorterAppEventHandler(
  371. config,
  372. factory.GetResultWriter(),
  373. )
  374. routes = append(routes, &router.Route{
  375. Endpoint: getPorterAppEventEndpoint,
  376. Handler: getPorterAppEventHandler,
  377. Router: r,
  378. })
  379. // POST /api/projects/{project_id}/clusters/{cluster_id}/applications/analytics -> porter_app.NewPorterAppAnalyticsHandler
  380. porterAppAnalyticsEndpoint := factory.NewAPIEndpoint(
  381. &types.APIRequestMetadata{
  382. Verb: types.APIVerbUpdate,
  383. Method: types.HTTPVerbPost,
  384. Path: &types.Path{
  385. Parent: basePath,
  386. RelativePath: fmt.Sprintf("%s/analytics", relPath),
  387. },
  388. Scopes: []types.PermissionScope{
  389. types.UserScope,
  390. types.ProjectScope,
  391. types.ClusterScope,
  392. },
  393. },
  394. )
  395. porterAppAnalyticsHandler := porter_app.NewPorterAppAnalyticsHandler(
  396. config,
  397. factory.GetDecoderValidator(),
  398. factory.GetResultWriter(),
  399. )
  400. routes = append(routes, &router.Route{
  401. Endpoint: porterAppAnalyticsEndpoint,
  402. Handler: porterAppAnalyticsHandler,
  403. Router: r,
  404. })
  405. // GET /api/projects/{project_id}/clusters/{cluster_id}/applications/logs -> cluster.NewGetChartLogsWithinTimeRangeHandler
  406. getChartLogsWithinTimeRangeEndpoint := factory.NewAPIEndpoint(
  407. &types.APIRequestMetadata{
  408. Verb: types.APIVerbGet,
  409. Method: types.HTTPVerbGet,
  410. Path: &types.Path{
  411. Parent: basePath,
  412. RelativePath: fmt.Sprintf("%s/logs", relPath),
  413. },
  414. Scopes: []types.PermissionScope{
  415. types.UserScope,
  416. types.ProjectScope,
  417. types.ClusterScope,
  418. },
  419. },
  420. )
  421. getChartLogsWithinTimeRangeHandler := porter_app.NewGetLogsWithinTimeRangeHandler(
  422. config,
  423. factory.GetDecoderValidator(),
  424. factory.GetResultWriter(),
  425. )
  426. routes = append(routes, &router.Route{
  427. Endpoint: getChartLogsWithinTimeRangeEndpoint,
  428. Handler: getChartLogsWithinTimeRangeHandler,
  429. Router: r,
  430. })
  431. // POST /api/projects/{project_id}/clusters/{cluster_id}/applications/{porter_app_name}/run -> porter_app.NewRunPorterAppCommandHandler
  432. runPorterAppCommandEndpoint := factory.NewAPIEndpoint(
  433. &types.APIRequestMetadata{
  434. Verb: types.APIVerbCreate,
  435. Method: types.HTTPVerbPost,
  436. Path: &types.Path{
  437. Parent: basePath,
  438. RelativePath: fmt.Sprintf("%s/{%s}/run", relPath, types.URLParamPorterAppName),
  439. },
  440. Scopes: []types.PermissionScope{
  441. types.UserScope,
  442. types.ProjectScope,
  443. types.ClusterScope,
  444. },
  445. },
  446. )
  447. runPorterAppCommandHandler := porter_app.NewRunPorterAppCommandHandler(
  448. config,
  449. factory.GetDecoderValidator(),
  450. factory.GetResultWriter(),
  451. )
  452. routes = append(routes, &router.Route{
  453. Endpoint: runPorterAppCommandEndpoint,
  454. Handler: runPorterAppCommandHandler,
  455. Router: r,
  456. })
  457. // TODO: remove these three endpoints once these three 'stacks' routes are no longer used in telemetry
  458. // GET /api/projects/{project_id}/clusters/{cluster_id}/stacks/{name} -> porter_app.NewPorterAppGetHandler
  459. LEGACY_getPorterAppEndpoint := factory.NewAPIEndpoint(
  460. &types.APIRequestMetadata{
  461. Verb: types.APIVerbGet,
  462. Method: types.HTTPVerbGet,
  463. Path: &types.Path{
  464. Parent: basePath,
  465. RelativePath: fmt.Sprintf("/stacks/{%s}", types.URLParamPorterAppName),
  466. },
  467. Scopes: []types.PermissionScope{
  468. types.UserScope,
  469. types.ProjectScope,
  470. types.ClusterScope,
  471. },
  472. },
  473. )
  474. LEGACY_getPorterAppHandler := porter_app.NewGetPorterAppHandler(
  475. config,
  476. factory.GetResultWriter(),
  477. )
  478. routes = append(routes, &router.Route{
  479. Endpoint: LEGACY_getPorterAppEndpoint,
  480. Handler: LEGACY_getPorterAppHandler,
  481. Router: r,
  482. })
  483. // POST /api/projects/{project_id}/clusters/{cluster_id}/stacks/{porter_app_name} -> porter_app.NewCreatePorterAppHandler
  484. LEGACY_createPorterAppEndpoint := factory.NewAPIEndpoint(
  485. &types.APIRequestMetadata{
  486. Verb: types.APIVerbCreate,
  487. Method: types.HTTPVerbPost,
  488. Path: &types.Path{
  489. Parent: basePath,
  490. RelativePath: fmt.Sprintf("/stacks/{%s}", types.URLParamPorterAppName),
  491. },
  492. Scopes: []types.PermissionScope{
  493. types.UserScope,
  494. types.ProjectScope,
  495. types.ClusterScope,
  496. },
  497. },
  498. )
  499. LEGACY_createPorterAppHandler := porter_app.NewCreatePorterAppHandler(
  500. config,
  501. factory.GetDecoderValidator(),
  502. factory.GetResultWriter(),
  503. )
  504. routes = append(routes, &router.Route{
  505. Endpoint: LEGACY_createPorterAppEndpoint,
  506. Handler: LEGACY_createPorterAppHandler,
  507. Router: r,
  508. })
  509. // POST /api/projects/{project_id}/clusters/{cluster_id}/stacks/{name}/events -> porter_app.NewCreatePorterAppEventHandler
  510. LEGACY_createPorterAppEventEndpoint := factory.NewAPIEndpoint(
  511. &types.APIRequestMetadata{
  512. Verb: types.APIVerbCreate,
  513. Method: types.HTTPVerbPost,
  514. Path: &types.Path{
  515. Parent: basePath,
  516. RelativePath: fmt.Sprintf("/stacks/{%s}/events", types.URLParamPorterAppName),
  517. },
  518. Scopes: []types.PermissionScope{
  519. types.UserScope,
  520. types.ProjectScope,
  521. types.ClusterScope,
  522. },
  523. },
  524. )
  525. LEGACY_createPorterAppEventHandler := porter_app.NewCreateUpdatePorterAppEventHandler(
  526. config,
  527. factory.GetDecoderValidator(),
  528. factory.GetResultWriter(),
  529. )
  530. routes = append(routes, &router.Route{
  531. Endpoint: LEGACY_createPorterAppEventEndpoint,
  532. Handler: LEGACY_createPorterAppEventHandler,
  533. Router: r,
  534. })
  535. // POST /api/projects/{project_id}/clusters/{cluster_id}/apps/parse -> porter_app.NewParsePorterYAMLToProtoHandler
  536. parsePorterYAMLToProtoEndpoint := factory.NewAPIEndpoint(
  537. &types.APIRequestMetadata{
  538. Verb: types.APIVerbGet,
  539. Method: types.HTTPVerbPost,
  540. Path: &types.Path{
  541. Parent: basePath,
  542. RelativePath: fmt.Sprintf("%s/parse", relPathV2),
  543. },
  544. Scopes: []types.PermissionScope{
  545. types.UserScope,
  546. types.ProjectScope,
  547. types.ClusterScope,
  548. },
  549. },
  550. )
  551. parsePorterYAMLToProtoHandler := porter_app.NewParsePorterYAMLToProtoHandler(
  552. config,
  553. factory.GetDecoderValidator(),
  554. factory.GetResultWriter(),
  555. )
  556. routes = append(routes, &router.Route{
  557. Endpoint: parsePorterYAMLToProtoEndpoint,
  558. Handler: parsePorterYAMLToProtoHandler,
  559. Router: r,
  560. })
  561. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/manifests -> porter_app.NewGetAppManifestsHandler
  562. getAppManifestsEndpoint := factory.NewAPIEndpoint(
  563. &types.APIRequestMetadata{
  564. Verb: types.APIVerbGet,
  565. Method: types.HTTPVerbGet,
  566. Path: &types.Path{
  567. Parent: basePath,
  568. RelativePath: fmt.Sprintf("%s/{%s}/manifests", relPathV2, types.URLParamPorterAppName),
  569. },
  570. Scopes: []types.PermissionScope{
  571. types.UserScope,
  572. types.ProjectScope,
  573. types.ClusterScope,
  574. },
  575. },
  576. )
  577. getAppManifestsHandler := porter_app.NewAppManifestsHandler(
  578. config,
  579. factory.GetDecoderValidator(),
  580. factory.GetResultWriter(),
  581. )
  582. routes = append(routes, &router.Route{
  583. Endpoint: getAppManifestsEndpoint,
  584. Handler: getAppManifestsHandler,
  585. Router: r,
  586. })
  587. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/env-variables -> porter_app.AppEnvVariablesHandler
  588. appEnvVariablesEndpoint := factory.NewAPIEndpoint(
  589. &types.APIRequestMetadata{
  590. Verb: types.APIVerbGet,
  591. Method: types.HTTPVerbGet,
  592. Path: &types.Path{
  593. Parent: basePath,
  594. RelativePath: fmt.Sprintf("%s/{%s}/env-variables", relPathV2, types.URLParamPorterAppName),
  595. },
  596. Scopes: []types.PermissionScope{
  597. types.UserScope,
  598. types.ProjectScope,
  599. types.ClusterScope,
  600. },
  601. },
  602. )
  603. appEnvVariablesHandler := porter_app.NewAppEnvVariablesHandler(
  604. config,
  605. factory.GetDecoderValidator(),
  606. factory.GetResultWriter(),
  607. )
  608. routes = append(routes, &router.Route{
  609. Endpoint: appEnvVariablesEndpoint,
  610. Handler: appEnvVariablesHandler,
  611. Router: r,
  612. })
  613. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/revisions/{app_revision_id}/yaml -> porter_app.NewPorterYAMLFromRevisionHandler
  614. porterYAMLFromRevision := factory.NewAPIEndpoint(
  615. &types.APIRequestMetadata{
  616. Verb: types.APIVerbGet,
  617. Method: types.HTTPVerbGet,
  618. Path: &types.Path{
  619. Parent: basePath,
  620. RelativePath: fmt.Sprintf("%s/{%s}/revisions/{%s}/yaml", relPathV2, types.URLParamPorterAppName, types.URLParamAppRevisionID),
  621. },
  622. Scopes: []types.PermissionScope{
  623. types.UserScope,
  624. types.ProjectScope,
  625. types.ClusterScope,
  626. },
  627. },
  628. )
  629. porterYAMLFromRevisionHandler := porter_app.NewPorterYAMLFromRevisionHandler(
  630. config,
  631. factory.GetDecoderValidator(),
  632. factory.GetResultWriter(),
  633. )
  634. routes = append(routes, &router.Route{
  635. Endpoint: porterYAMLFromRevision,
  636. Handler: porterYAMLFromRevisionHandler,
  637. Router: r,
  638. })
  639. // POST /api/projects/{project_id}/clusters/{cluster_id}/apps/create -> porter_app.NewCreateAppHandler
  640. createAppEndpoint := factory.NewAPIEndpoint(
  641. &types.APIRequestMetadata{
  642. Verb: types.APIVerbCreate,
  643. Method: types.HTTPVerbPost,
  644. Path: &types.Path{
  645. Parent: basePath,
  646. RelativePath: fmt.Sprintf("%s/create", relPathV2),
  647. },
  648. Scopes: []types.PermissionScope{
  649. types.UserScope,
  650. types.ProjectScope,
  651. types.ClusterScope,
  652. },
  653. },
  654. )
  655. createAppHandler := porter_app.NewCreateAppHandler(
  656. config,
  657. factory.GetDecoderValidator(),
  658. factory.GetResultWriter(),
  659. )
  660. routes = append(routes, &router.Route{
  661. Endpoint: createAppEndpoint,
  662. Handler: createAppHandler,
  663. Router: r,
  664. })
  665. // POST /api/projects/{project_id}/clusters/{cluster_id}/apps/attach-env-group -> porter_app.NewAttachEnvGroupHandler
  666. attachEnvGroupEndpoint := factory.NewAPIEndpoint(
  667. &types.APIRequestMetadata{
  668. Verb: types.APIVerbUpdate,
  669. Method: types.HTTPVerbPost,
  670. Path: &types.Path{
  671. Parent: basePath,
  672. RelativePath: fmt.Sprintf("%s/attach-env-group", relPathV2),
  673. },
  674. Scopes: []types.PermissionScope{
  675. types.UserScope,
  676. types.ProjectScope,
  677. types.ClusterScope,
  678. },
  679. },
  680. )
  681. attachEnvGroupHandler := porter_app.NewAttachEnvGroupHandler(
  682. config,
  683. factory.GetDecoderValidator(),
  684. factory.GetResultWriter(),
  685. )
  686. routes = append(routes, &router.Route{
  687. Endpoint: attachEnvGroupEndpoint,
  688. Handler: attachEnvGroupHandler,
  689. Router: r,
  690. })
  691. // POST /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/rollback -> porter_app.NewRollbackAppRevisionHandler
  692. rollbackAppRevisionEndpoint := factory.NewAPIEndpoint(
  693. &types.APIRequestMetadata{
  694. Verb: types.APIVerbUpdate,
  695. Method: types.HTTPVerbPost,
  696. Path: &types.Path{
  697. Parent: basePath,
  698. RelativePath: fmt.Sprintf("%s/{%s}/rollback", relPathV2, types.URLParamPorterAppName),
  699. },
  700. Scopes: []types.PermissionScope{
  701. types.UserScope,
  702. types.ProjectScope,
  703. types.ClusterScope,
  704. },
  705. },
  706. )
  707. rollbackAppRevisionHandler := porter_app.NewRollbackAppRevisionHandler(
  708. config,
  709. factory.GetDecoderValidator(),
  710. factory.GetResultWriter(),
  711. )
  712. routes = append(routes, &router.Route{
  713. Endpoint: rollbackAppRevisionEndpoint,
  714. Handler: rollbackAppRevisionHandler,
  715. Router: r,
  716. })
  717. // POST /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/update-image -> porter_app.NewUpdateImageHandler
  718. updatePorterAppImageEndpoint := factory.NewAPIEndpoint(
  719. &types.APIRequestMetadata{
  720. Verb: types.APIVerbUpdate,
  721. Method: types.HTTPVerbPost,
  722. Path: &types.Path{
  723. Parent: basePath,
  724. RelativePath: fmt.Sprintf("%s/{%s}/update-image", relPathV2, types.URLParamPorterAppName),
  725. },
  726. Scopes: []types.PermissionScope{
  727. types.UserScope,
  728. types.ProjectScope,
  729. types.ClusterScope,
  730. },
  731. },
  732. )
  733. updatePorterAppImageHandler := porter_app.NewUpdateImageHandler(
  734. config,
  735. factory.GetDecoderValidator(),
  736. factory.GetResultWriter(),
  737. )
  738. routes = append(routes, &router.Route{
  739. Endpoint: updatePorterAppImageEndpoint,
  740. Handler: updatePorterAppImageHandler,
  741. Router: r,
  742. })
  743. // GET /api/projects/{project_id}/clusters/{cluster_id}/default-deployment-target -> porter_app.NewDefaultDeploymentTargetHandler
  744. defaultDeploymentTargetEndpoint := factory.NewAPIEndpoint(
  745. &types.APIRequestMetadata{
  746. Verb: types.APIVerbGet,
  747. Method: types.HTTPVerbGet,
  748. Path: &types.Path{
  749. Parent: basePath,
  750. RelativePath: "/default-deployment-target",
  751. },
  752. Scopes: []types.PermissionScope{
  753. types.UserScope,
  754. types.ProjectScope,
  755. types.ClusterScope,
  756. },
  757. },
  758. )
  759. defaultDeploymentTargetHandler := porter_app.NewDefaultDeploymentTargetHandler(
  760. config,
  761. factory.GetDecoderValidator(),
  762. factory.GetResultWriter(),
  763. )
  764. routes = append(routes, &router.Route{
  765. Endpoint: defaultDeploymentTargetEndpoint,
  766. Handler: defaultDeploymentTargetHandler,
  767. Router: r,
  768. })
  769. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/latest -> porter_app.NewCurrentAppRevisionHandler
  770. currentAppRevisionEndpoint := factory.NewAPIEndpoint(
  771. &types.APIRequestMetadata{
  772. Verb: types.APIVerbGet,
  773. Method: types.HTTPVerbGet,
  774. Path: &types.Path{
  775. Parent: basePath,
  776. RelativePath: fmt.Sprintf("%s/{%s}/latest", relPathV2, types.URLParamPorterAppName),
  777. },
  778. Scopes: []types.PermissionScope{
  779. types.UserScope,
  780. types.ProjectScope,
  781. types.ClusterScope,
  782. },
  783. },
  784. )
  785. currentAppRevisionHandler := porter_app.NewLatestAppRevisionHandler(
  786. config,
  787. factory.GetDecoderValidator(),
  788. factory.GetResultWriter(),
  789. )
  790. routes = append(routes, &router.Route{
  791. Endpoint: currentAppRevisionEndpoint,
  792. Handler: currentAppRevisionHandler,
  793. Router: r,
  794. })
  795. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/notifications -> porter_app.NewAppNotificationsHandler
  796. appNotificationsEndpoint := factory.NewAPIEndpoint(
  797. &types.APIRequestMetadata{
  798. Verb: types.APIVerbGet,
  799. Method: types.HTTPVerbGet,
  800. Path: &types.Path{
  801. Parent: basePath,
  802. RelativePath: fmt.Sprintf("%s/{%s}/notifications", relPathV2, types.URLParamPorterAppName),
  803. },
  804. Scopes: []types.PermissionScope{
  805. types.UserScope,
  806. types.ProjectScope,
  807. types.ClusterScope,
  808. },
  809. },
  810. )
  811. appNotificationsHandler := porter_app.NewAppNotificationsHandler(
  812. config,
  813. factory.GetDecoderValidator(),
  814. factory.GetResultWriter(),
  815. )
  816. routes = append(routes, &router.Route{
  817. Endpoint: appNotificationsEndpoint,
  818. Handler: appNotificationsHandler,
  819. Router: r,
  820. })
  821. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/revisions -> porter_app.NewCurrentAppRevisionHandler
  822. listAppRevisionsEndpoint := factory.NewAPIEndpoint(
  823. &types.APIRequestMetadata{
  824. Verb: types.APIVerbGet,
  825. Method: types.HTTPVerbGet,
  826. Path: &types.Path{
  827. Parent: basePath,
  828. RelativePath: fmt.Sprintf("%s/{%s}/revisions", relPathV2, types.URLParamPorterAppName),
  829. },
  830. Scopes: []types.PermissionScope{
  831. types.UserScope,
  832. types.ProjectScope,
  833. types.ClusterScope,
  834. },
  835. },
  836. )
  837. listAppRevisionsHandler := porter_app.NewListAppRevisionsHandler(
  838. config,
  839. factory.GetDecoderValidator(),
  840. factory.GetResultWriter(),
  841. )
  842. routes = append(routes, &router.Route{
  843. Endpoint: listAppRevisionsEndpoint,
  844. Handler: listAppRevisionsHandler,
  845. Router: r,
  846. })
  847. // POST /api/projects/{project_id}/clusters/{cluster_id}/apps/update -> porter_app.UpdateAppHandler
  848. updateAppEndpoint := factory.NewAPIEndpoint(
  849. &types.APIRequestMetadata{
  850. Verb: types.APIVerbUpdate,
  851. Method: types.HTTPVerbPost,
  852. Path: &types.Path{
  853. Parent: basePath,
  854. RelativePath: fmt.Sprintf("%s/update", relPathV2),
  855. },
  856. Scopes: []types.PermissionScope{
  857. types.UserScope,
  858. types.ProjectScope,
  859. types.ClusterScope,
  860. },
  861. },
  862. )
  863. updateAppHandler := porter_app.NewUpdateAppHandler(
  864. config,
  865. factory.GetDecoderValidator(),
  866. factory.GetResultWriter(),
  867. )
  868. routes = append(routes, &router.Route{
  869. Endpoint: updateAppEndpoint,
  870. Handler: updateAppHandler,
  871. Router: r,
  872. })
  873. // POST /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/build -> porter_app.NewUpdateAppBuildSettingsHandler
  874. updateAppBuildSettingsEndpoint := factory.NewAPIEndpoint(
  875. &types.APIRequestMetadata{
  876. Verb: types.APIVerbUpdate,
  877. Method: types.HTTPVerbPost,
  878. Path: &types.Path{
  879. Parent: basePath,
  880. RelativePath: fmt.Sprintf("%s/{%s}/build", relPathV2, types.URLParamPorterAppName),
  881. },
  882. Scopes: []types.PermissionScope{
  883. types.UserScope,
  884. types.ProjectScope,
  885. types.ClusterScope,
  886. },
  887. },
  888. )
  889. updateAppBuildSettingsHandler := porter_app.NewUpdateAppBuildSettingsHandler(
  890. config,
  891. factory.GetDecoderValidator(),
  892. factory.GetResultWriter(),
  893. )
  894. routes = append(routes, &router.Route{
  895. Endpoint: updateAppBuildSettingsEndpoint,
  896. Handler: updateAppBuildSettingsHandler,
  897. Router: r,
  898. })
  899. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/revisions -> porter_app.NewLatestAppRevisionsHandler
  900. latestAppRevisionsEndpoint := factory.NewAPIEndpoint(
  901. &types.APIRequestMetadata{
  902. Verb: types.APIVerbGet,
  903. Method: types.HTTPVerbGet,
  904. Path: &types.Path{
  905. Parent: basePath,
  906. RelativePath: fmt.Sprintf("%s/revisions", relPathV2),
  907. },
  908. Scopes: []types.PermissionScope{
  909. types.UserScope,
  910. types.ProjectScope,
  911. types.ClusterScope,
  912. },
  913. },
  914. )
  915. latestAppRevisionsHandler := porter_app.NewLatestAppRevisionsHandler(
  916. config,
  917. factory.GetDecoderValidator(),
  918. factory.GetResultWriter(),
  919. )
  920. routes = append(routes, &router.Route{
  921. Endpoint: latestAppRevisionsEndpoint,
  922. Handler: latestAppRevisionsHandler,
  923. Router: r,
  924. })
  925. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/instances -> porter_app.NewAppInstancesHandler
  926. latestAppInstancesEndpoint := factory.NewAPIEndpoint(
  927. &types.APIRequestMetadata{
  928. Verb: types.APIVerbGet,
  929. Method: types.HTTPVerbGet,
  930. Path: &types.Path{
  931. Parent: basePath,
  932. RelativePath: fmt.Sprintf("%s/instances", relPathV2),
  933. },
  934. Scopes: []types.PermissionScope{
  935. types.UserScope,
  936. types.ProjectScope,
  937. types.ClusterScope,
  938. },
  939. },
  940. )
  941. latestAppInstancesHandler := porter_app.NewAppInstancesHandler(
  942. config,
  943. factory.GetDecoderValidator(),
  944. factory.GetResultWriter(),
  945. )
  946. routes = append(routes, &router.Route{
  947. Endpoint: latestAppInstancesEndpoint,
  948. Handler: latestAppInstancesHandler,
  949. Router: r,
  950. })
  951. // POST /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/subdomain -> porter_app.NewCreateSubdomainHandler
  952. createSubdomainEndpoint := factory.NewAPIEndpoint(
  953. &types.APIRequestMetadata{
  954. Verb: types.APIVerbUpdate,
  955. Method: types.HTTPVerbPost,
  956. Path: &types.Path{
  957. Parent: basePath,
  958. RelativePath: fmt.Sprintf("%s/{%s}/subdomain", relPathV2, types.URLParamPorterAppName),
  959. },
  960. Scopes: []types.PermissionScope{
  961. types.UserScope,
  962. types.ProjectScope,
  963. types.ClusterScope,
  964. },
  965. },
  966. )
  967. createSubdomainHandler := porter_app.NewCreateSubdomainHandler(
  968. config,
  969. factory.GetDecoderValidator(),
  970. factory.GetResultWriter(),
  971. )
  972. routes = append(routes, &router.Route{
  973. Endpoint: createSubdomainEndpoint,
  974. Handler: createSubdomainHandler,
  975. Router: r,
  976. })
  977. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/{app_revision_id}/predeploy-status -> porter_app.NewPredeployStatusHandler
  978. predeployStatusEndpoint := factory.NewAPIEndpoint(
  979. &types.APIRequestMetadata{
  980. Verb: types.APIVerbGet,
  981. Method: types.HTTPVerbGet,
  982. Path: &types.Path{
  983. Parent: basePath,
  984. RelativePath: fmt.Sprintf("%s/{%s}/{%s}/predeploy-status", relPathV2, types.URLParamPorterAppName, types.URLParamAppRevisionID),
  985. },
  986. Scopes: []types.PermissionScope{
  987. types.UserScope,
  988. types.ProjectScope,
  989. types.ClusterScope,
  990. },
  991. },
  992. )
  993. predeployStatusHandler := porter_app.NewPredeployStatusHandler(
  994. config,
  995. factory.GetDecoderValidator(),
  996. factory.GetResultWriter(),
  997. )
  998. routes = append(routes, &router.Route{
  999. Endpoint: predeployStatusEndpoint,
  1000. Handler: predeployStatusHandler,
  1001. Router: r,
  1002. })
  1003. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/logs -> cluster.NewAppLogsHandler
  1004. appLogsEndpoint := factory.NewAPIEndpoint(
  1005. &types.APIRequestMetadata{
  1006. Verb: types.APIVerbGet,
  1007. Method: types.HTTPVerbGet,
  1008. Path: &types.Path{
  1009. Parent: basePath,
  1010. RelativePath: fmt.Sprintf("%s/{%s}/logs", relPathV2, types.URLParamPorterAppName),
  1011. },
  1012. Scopes: []types.PermissionScope{
  1013. types.UserScope,
  1014. types.ProjectScope,
  1015. types.ClusterScope,
  1016. },
  1017. },
  1018. )
  1019. appLogsHandler := porter_app.NewAppLogsHandler(
  1020. config,
  1021. factory.GetDecoderValidator(),
  1022. factory.GetResultWriter(),
  1023. )
  1024. routes = append(routes, &router.Route{
  1025. Endpoint: appLogsEndpoint,
  1026. Handler: appLogsHandler,
  1027. Router: r,
  1028. })
  1029. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/logs/loki -> namespace.NewStreamLogsLokiHandler
  1030. streamLogsLokiEndpoint := factory.NewAPIEndpoint(
  1031. &types.APIRequestMetadata{
  1032. Verb: types.APIVerbGet,
  1033. Method: types.HTTPVerbGet,
  1034. Path: &types.Path{
  1035. Parent: basePath,
  1036. RelativePath: fmt.Sprintf("%s/{%s}/logs/loki", relPathV2, types.URLParamPorterAppName),
  1037. },
  1038. Scopes: []types.PermissionScope{
  1039. types.UserScope,
  1040. types.ProjectScope,
  1041. types.ClusterScope,
  1042. },
  1043. IsWebsocket: true,
  1044. },
  1045. )
  1046. streamLogsLokiHandler := porter_app.NewStreamLogsLokiHandler(
  1047. config,
  1048. factory.GetDecoderValidator(),
  1049. factory.GetResultWriter(),
  1050. )
  1051. routes = append(routes, &router.Route{
  1052. Endpoint: streamLogsLokiEndpoint,
  1053. Handler: streamLogsLokiHandler,
  1054. Router: r,
  1055. })
  1056. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/metrics -> cluster.NewGetPodMetricsHandler
  1057. appMetricsEndpoint := factory.NewAPIEndpoint(
  1058. &types.APIRequestMetadata{
  1059. Verb: types.APIVerbGet,
  1060. Method: types.HTTPVerbGet,
  1061. Path: &types.Path{
  1062. Parent: basePath,
  1063. RelativePath: fmt.Sprintf("%s/metrics", relPathV2),
  1064. },
  1065. Scopes: []types.PermissionScope{
  1066. types.UserScope,
  1067. types.ProjectScope,
  1068. types.ClusterScope,
  1069. },
  1070. },
  1071. )
  1072. appMetricsHandler := porter_app.NewAppMetricsHandler(
  1073. config,
  1074. factory.GetDecoderValidator(),
  1075. factory.GetResultWriter(),
  1076. )
  1077. routes = append(routes, &router.Route{
  1078. Endpoint: appMetricsEndpoint,
  1079. Handler: appMetricsHandler,
  1080. Router: r,
  1081. })
  1082. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/status -> cluster.NewAppStatusHandler
  1083. appStatusEndpoint := factory.NewAPIEndpoint(
  1084. &types.APIRequestMetadata{
  1085. Verb: types.APIVerbGet,
  1086. Method: types.HTTPVerbGet,
  1087. Path: &types.Path{
  1088. Parent: basePath,
  1089. RelativePath: fmt.Sprintf("%s/{%s}/status", relPathV2, types.URLParamKind),
  1090. },
  1091. Scopes: []types.PermissionScope{
  1092. types.UserScope,
  1093. types.ProjectScope,
  1094. types.ClusterScope,
  1095. },
  1096. IsWebsocket: true,
  1097. },
  1098. )
  1099. appStatusHandler := porter_app.NewAppStatusHandler(
  1100. config,
  1101. factory.GetDecoderValidator(),
  1102. factory.GetResultWriter(),
  1103. )
  1104. routes = append(routes, &router.Route{
  1105. Endpoint: appStatusEndpoint,
  1106. Handler: appStatusHandler,
  1107. Router: r,
  1108. })
  1109. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/service_status -> cluster.NewAppServiceStatusHandler
  1110. appServiceStatusEndpoint := factory.NewAPIEndpoint(
  1111. &types.APIRequestMetadata{
  1112. Verb: types.APIVerbGet,
  1113. Method: types.HTTPVerbGet,
  1114. Path: &types.Path{
  1115. Parent: basePath,
  1116. RelativePath: fmt.Sprintf("%s/{%s}/service_status", relPathV2, types.URLParamPorterAppName),
  1117. },
  1118. Scopes: []types.PermissionScope{
  1119. types.UserScope,
  1120. types.ProjectScope,
  1121. types.ClusterScope,
  1122. },
  1123. },
  1124. )
  1125. appServiceStatusHandler := porter_app.NewServiceStatusHandler(
  1126. config,
  1127. factory.GetDecoderValidator(),
  1128. factory.GetResultWriter(),
  1129. )
  1130. routes = append(routes, &router.Route{
  1131. Endpoint: appServiceStatusEndpoint,
  1132. Handler: appServiceStatusHandler,
  1133. Router: r,
  1134. })
  1135. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/jobs -> cluster.NewJobStatusHandler
  1136. appJobStatusEndpoint := factory.NewAPIEndpoint(
  1137. &types.APIRequestMetadata{
  1138. Verb: types.APIVerbGet,
  1139. Method: types.HTTPVerbGet,
  1140. Path: &types.Path{
  1141. Parent: basePath,
  1142. RelativePath: fmt.Sprintf("%s/{%s}/jobs", relPathV2, types.URLParamPorterAppName),
  1143. },
  1144. Scopes: []types.PermissionScope{
  1145. types.UserScope,
  1146. types.ProjectScope,
  1147. types.ClusterScope,
  1148. },
  1149. },
  1150. )
  1151. appJobStatusHandler := porter_app.NewJobStatusHandler(
  1152. config,
  1153. factory.GetDecoderValidator(),
  1154. factory.GetResultWriter(),
  1155. )
  1156. routes = append(routes, &router.Route{
  1157. Endpoint: appJobStatusEndpoint,
  1158. Handler: appJobStatusHandler,
  1159. Router: r,
  1160. })
  1161. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/jobs/{job_run_name} -> porter_app.JobStatusByNameHandler
  1162. appJobStatusByNameEndpoint := factory.NewAPIEndpoint(
  1163. &types.APIRequestMetadata{
  1164. Verb: types.APIVerbGet,
  1165. Method: types.HTTPVerbGet,
  1166. Path: &types.Path{
  1167. Parent: basePath,
  1168. RelativePath: fmt.Sprintf("%s/{%s}/jobs/{%s}", relPathV2, types.URLParamPorterAppName, types.URLParamJobRunName),
  1169. },
  1170. Scopes: []types.PermissionScope{
  1171. types.UserScope,
  1172. types.ProjectScope,
  1173. types.ClusterScope,
  1174. },
  1175. },
  1176. )
  1177. appJobStatusByNameHandler := porter_app.NewJobStatusByNameHandler(
  1178. config,
  1179. factory.GetDecoderValidator(),
  1180. factory.GetResultWriter(),
  1181. )
  1182. routes = append(routes, &router.Route{
  1183. Endpoint: appJobStatusByNameEndpoint,
  1184. Handler: appJobStatusByNameHandler,
  1185. Router: r,
  1186. })
  1187. // POST /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/jobs/{job_run_name}/cancel -> porter_app.CancelJobRunHandler
  1188. appJobCancelEndpoint := factory.NewAPIEndpoint(
  1189. &types.APIRequestMetadata{
  1190. Verb: types.APIVerbUpdate,
  1191. Method: types.HTTPVerbPost,
  1192. Path: &types.Path{
  1193. Parent: basePath,
  1194. RelativePath: fmt.Sprintf("%s/{%s}/jobs/{%s}/cancel", relPathV2, types.URLParamPorterAppName, types.URLParamJobRunName),
  1195. },
  1196. Scopes: []types.PermissionScope{
  1197. types.UserScope,
  1198. types.ProjectScope,
  1199. types.ClusterScope,
  1200. },
  1201. },
  1202. )
  1203. appJobCancelHandler := porter_app.NewCancelJobRunHandler(
  1204. config,
  1205. factory.GetDecoderValidator(),
  1206. factory.GetResultWriter(),
  1207. )
  1208. routes = append(routes, &router.Route{
  1209. Endpoint: appJobCancelEndpoint,
  1210. Handler: appJobCancelHandler,
  1211. Router: r,
  1212. })
  1213. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/revisions/{app_revision_id} -> porter_app.NewGetAppRevisionHandler
  1214. getAppRevisionEndpoint := factory.NewAPIEndpoint(
  1215. &types.APIRequestMetadata{
  1216. Verb: types.APIVerbGet,
  1217. Method: types.HTTPVerbGet,
  1218. Path: &types.Path{
  1219. Parent: basePath,
  1220. RelativePath: fmt.Sprintf("/apps/{%s}/revisions/{%s}", types.URLParamPorterAppName, types.URLParamAppRevisionID),
  1221. },
  1222. Scopes: []types.PermissionScope{
  1223. types.UserScope,
  1224. types.ProjectScope,
  1225. types.ClusterScope,
  1226. },
  1227. },
  1228. )
  1229. getAppRevisionHandler := porter_app.NewGetAppRevisionHandler(
  1230. config,
  1231. factory.GetDecoderValidator(),
  1232. factory.GetResultWriter(),
  1233. )
  1234. routes = append(routes, &router.Route{
  1235. Endpoint: getAppRevisionEndpoint,
  1236. Handler: getAppRevisionHandler,
  1237. Router: r,
  1238. })
  1239. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/revisions/{app_revision_id}/status -> porter_app.NewGetAppRevisionStatusHandler
  1240. getAppRevisionStatusEndpoint := factory.NewAPIEndpoint(
  1241. &types.APIRequestMetadata{
  1242. Verb: types.APIVerbGet,
  1243. Method: types.HTTPVerbGet,
  1244. Path: &types.Path{
  1245. Parent: basePath,
  1246. RelativePath: fmt.Sprintf("/apps/{%s}/revisions/{%s}/status", types.URLParamPorterAppName, types.URLParamAppRevisionID),
  1247. },
  1248. Scopes: []types.PermissionScope{
  1249. types.UserScope,
  1250. types.ProjectScope,
  1251. types.ClusterScope,
  1252. },
  1253. },
  1254. )
  1255. getAppRevisionStatusHandler := porter_app.NewGetAppRevisionStatusHandler(
  1256. config,
  1257. factory.GetDecoderValidator(),
  1258. factory.GetResultWriter(),
  1259. )
  1260. routes = append(routes, &router.Route{
  1261. Endpoint: getAppRevisionStatusEndpoint,
  1262. Handler: getAppRevisionStatusHandler,
  1263. Router: r,
  1264. })
  1265. // POST /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/revisions/{app_revision_id} -> porter_app.NewUpdateAppRevisionStatusHandler
  1266. updateAppRevisionStatusEndpoint := factory.NewAPIEndpoint(
  1267. &types.APIRequestMetadata{
  1268. Verb: types.APIVerbUpdate,
  1269. Method: types.HTTPVerbPost,
  1270. Path: &types.Path{
  1271. Parent: basePath,
  1272. RelativePath: fmt.Sprintf("/apps/{%s}/revisions/{%s}", types.URLParamPorterAppName, types.URLParamAppRevisionID),
  1273. },
  1274. Scopes: []types.PermissionScope{
  1275. types.UserScope,
  1276. types.ProjectScope,
  1277. types.ClusterScope,
  1278. },
  1279. },
  1280. )
  1281. updateAppRevisionStatusHandler := porter_app.NewUpdateAppRevisionStatusHandler(
  1282. config,
  1283. factory.GetDecoderValidator(),
  1284. factory.GetResultWriter(),
  1285. )
  1286. routes = append(routes, &router.Route{
  1287. Endpoint: updateAppRevisionStatusEndpoint,
  1288. Handler: updateAppRevisionStatusHandler,
  1289. Router: r,
  1290. })
  1291. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/revisions/{app_revision_id}/build-env -> porter_app.NewGetBuildEnvHandler
  1292. getBuildEnvEndpoint := factory.NewAPIEndpoint(
  1293. &types.APIRequestMetadata{
  1294. Verb: types.APIVerbGet,
  1295. Method: types.HTTPVerbGet,
  1296. Path: &types.Path{
  1297. Parent: basePath,
  1298. RelativePath: fmt.Sprintf("/apps/{%s}/revisions/{%s}/build-env", types.URLParamPorterAppName, types.URLParamAppRevisionID),
  1299. },
  1300. Scopes: []types.PermissionScope{
  1301. types.UserScope,
  1302. types.ProjectScope,
  1303. types.ClusterScope,
  1304. },
  1305. },
  1306. )
  1307. getBuildEnvHandler := porter_app.NewGetBuildEnvHandler(
  1308. config,
  1309. factory.GetDecoderValidator(),
  1310. factory.GetResultWriter(),
  1311. )
  1312. routes = append(routes, &router.Route{
  1313. Endpoint: getBuildEnvEndpoint,
  1314. Handler: getBuildEnvHandler,
  1315. Router: r,
  1316. })
  1317. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/revisions/{app_revision_id}/build -> porter_app.NewGetBuildFromRevisionHandler
  1318. getBuildFromRevisionEndpoint := factory.NewAPIEndpoint(
  1319. &types.APIRequestMetadata{
  1320. Verb: types.APIVerbGet,
  1321. Method: types.HTTPVerbGet,
  1322. Path: &types.Path{
  1323. Parent: basePath,
  1324. RelativePath: fmt.Sprintf("/apps/{%s}/revisions/{%s}/build", types.URLParamPorterAppName, types.URLParamAppRevisionID),
  1325. },
  1326. Scopes: []types.PermissionScope{
  1327. types.UserScope,
  1328. types.ProjectScope,
  1329. types.ClusterScope,
  1330. },
  1331. },
  1332. )
  1333. getBuildFromRevisionHandler := porter_app.NewGetBuildFromRevisionHandler(
  1334. config,
  1335. factory.GetDecoderValidator(),
  1336. factory.GetResultWriter(),
  1337. )
  1338. routes = append(routes, &router.Route{
  1339. Endpoint: getBuildFromRevisionEndpoint,
  1340. Handler: getBuildFromRevisionHandler,
  1341. Router: r,
  1342. })
  1343. // POST /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/revisions/{app_revision_id}/status -> porter_app.NewReportRevisionStatusHandler
  1344. reportRevisionStatusEndpoint := factory.NewAPIEndpoint(
  1345. &types.APIRequestMetadata{
  1346. Verb: types.APIVerbUpdate,
  1347. Method: types.HTTPVerbPost,
  1348. Path: &types.Path{
  1349. Parent: basePath,
  1350. RelativePath: fmt.Sprintf("/apps/{%s}/revisions/{%s}/status", types.URLParamPorterAppName, types.URLParamAppRevisionID),
  1351. },
  1352. Scopes: []types.PermissionScope{
  1353. types.UserScope,
  1354. types.ProjectScope,
  1355. types.ClusterScope,
  1356. },
  1357. },
  1358. )
  1359. reportRevisionStatusHandler := porter_app.NewReportRevisionStatusHandler(
  1360. config,
  1361. factory.GetDecoderValidator(),
  1362. factory.GetResultWriter(),
  1363. )
  1364. routes = append(routes, &router.Route{
  1365. Endpoint: reportRevisionStatusEndpoint,
  1366. Handler: reportRevisionStatusHandler,
  1367. Router: r,
  1368. })
  1369. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/revisions/{app_revision_id}/env -> porter_app.NewGetAppEnvHandler
  1370. getAppEnvEndpoint := factory.NewAPIEndpoint(
  1371. &types.APIRequestMetadata{
  1372. Verb: types.APIVerbGet,
  1373. Method: types.HTTPVerbGet,
  1374. Path: &types.Path{
  1375. Parent: basePath,
  1376. RelativePath: fmt.Sprintf("/apps/{%s}/revisions/{%s}/env", types.URLParamPorterAppName, types.URLParamAppRevisionID),
  1377. },
  1378. Scopes: []types.PermissionScope{
  1379. types.UserScope,
  1380. types.ProjectScope,
  1381. types.ClusterScope,
  1382. },
  1383. },
  1384. )
  1385. getAppEnvHandler := porter_app.NewGetAppEnvHandler(
  1386. config,
  1387. factory.GetDecoderValidator(),
  1388. factory.GetResultWriter(),
  1389. )
  1390. routes = append(routes, &router.Route{
  1391. Endpoint: getAppEnvEndpoint,
  1392. Handler: getAppEnvHandler,
  1393. Router: r,
  1394. })
  1395. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/events -> porter_app.NewPorterAppV2EventListHandler
  1396. listPorterAppV2EventsEndpoint := factory.NewAPIEndpoint(
  1397. &types.APIRequestMetadata{
  1398. Verb: types.APIVerbList,
  1399. Method: types.HTTPVerbGet,
  1400. Path: &types.Path{
  1401. Parent: basePath,
  1402. RelativePath: fmt.Sprintf("%s/{%s}/events", relPathV2, types.URLParamPorterAppName),
  1403. },
  1404. Scopes: []types.PermissionScope{
  1405. types.UserScope,
  1406. types.ProjectScope,
  1407. types.ClusterScope,
  1408. },
  1409. },
  1410. )
  1411. listPorterAppV2EventsHandler := porter_app.NewPorterAppV2EventListHandler(
  1412. config,
  1413. factory.GetDecoderValidator(),
  1414. factory.GetResultWriter(),
  1415. )
  1416. routes = append(routes, &router.Route{
  1417. Endpoint: listPorterAppV2EventsEndpoint,
  1418. Handler: listPorterAppV2EventsHandler,
  1419. Router: r,
  1420. })
  1421. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/templates -> porter_app.NewListEnvironmentTemplatesHandler
  1422. listEnvironmentTemplatesEndpoint := factory.NewAPIEndpoint(
  1423. &types.APIRequestMetadata{
  1424. Verb: types.APIVerbList,
  1425. Method: types.HTTPVerbGet,
  1426. Path: &types.Path{
  1427. Parent: basePath,
  1428. RelativePath: fmt.Sprintf("%s/templates", relPathV2),
  1429. },
  1430. Scopes: []types.PermissionScope{
  1431. types.UserScope,
  1432. types.ProjectScope,
  1433. types.ClusterScope,
  1434. },
  1435. },
  1436. )
  1437. listEnvironmentTemplatesHandler := porter_app.NewListEnvironmentTemplatesHandler(
  1438. config,
  1439. factory.GetDecoderValidator(),
  1440. factory.GetResultWriter(),
  1441. )
  1442. routes = append(routes, &router.Route{
  1443. Endpoint: listEnvironmentTemplatesEndpoint,
  1444. Handler: listEnvironmentTemplatesHandler,
  1445. Router: r,
  1446. })
  1447. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/templates -> porter_app.NewGetAppTemplateHandler
  1448. getAppTemplateEndpoint := factory.NewAPIEndpoint(
  1449. &types.APIRequestMetadata{
  1450. Verb: types.APIVerbGet,
  1451. Method: types.HTTPVerbGet,
  1452. Path: &types.Path{
  1453. Parent: basePath,
  1454. RelativePath: fmt.Sprintf("%s/{%s}/templates", relPathV2, types.URLParamPorterAppName),
  1455. },
  1456. Scopes: []types.PermissionScope{
  1457. types.UserScope,
  1458. types.ProjectScope,
  1459. types.ClusterScope,
  1460. },
  1461. },
  1462. )
  1463. getAppTemplateHandler := porter_app.NewGetAppTemplateHandler(
  1464. config,
  1465. factory.GetDecoderValidator(),
  1466. factory.GetResultWriter(),
  1467. )
  1468. routes = append(routes, &router.Route{
  1469. Endpoint: getAppTemplateEndpoint,
  1470. Handler: getAppTemplateHandler,
  1471. Router: r,
  1472. })
  1473. // POST /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/templates -> porter_app.NewCreateAppTemplateHandler
  1474. createAppTemplateEndpoint := factory.NewAPIEndpoint(
  1475. &types.APIRequestMetadata{
  1476. Verb: types.APIVerbCreate,
  1477. Method: types.HTTPVerbPost,
  1478. Path: &types.Path{
  1479. Parent: basePath,
  1480. RelativePath: fmt.Sprintf("%s/{%s}/templates", relPathV2, types.URLParamPorterAppName),
  1481. },
  1482. Scopes: []types.PermissionScope{
  1483. types.UserScope,
  1484. types.ProjectScope,
  1485. types.ClusterScope,
  1486. },
  1487. },
  1488. )
  1489. createAppTemplateHandler := porter_app.NewCreateAppTemplateHandler(
  1490. config,
  1491. factory.GetDecoderValidator(),
  1492. factory.GetResultWriter(),
  1493. )
  1494. routes = append(routes, &router.Route{
  1495. Endpoint: createAppTemplateEndpoint,
  1496. Handler: createAppTemplateHandler,
  1497. Router: r,
  1498. })
  1499. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/helm-values -> porter_app.NewAppHelmValuesHandler
  1500. appHelmValuesEndpoint := factory.NewAPIEndpoint(
  1501. &types.APIRequestMetadata{
  1502. Verb: types.APIVerbGet,
  1503. Method: types.HTTPVerbGet,
  1504. Path: &types.Path{
  1505. Parent: basePath,
  1506. RelativePath: fmt.Sprintf("%s/{%s}/helm-values", relPathV2, types.URLParamPorterAppName),
  1507. },
  1508. Scopes: []types.PermissionScope{
  1509. types.UserScope,
  1510. types.ProjectScope,
  1511. types.ClusterScope,
  1512. },
  1513. },
  1514. )
  1515. appHelmValuesHandler := porter_app.NewAppHelmValuesHandler(
  1516. config,
  1517. factory.GetDecoderValidator(),
  1518. factory.GetResultWriter(),
  1519. )
  1520. routes = append(routes, &router.Route{
  1521. Endpoint: appHelmValuesEndpoint,
  1522. Handler: appHelmValuesHandler,
  1523. Router: r,
  1524. })
  1525. // POST /api/projects/{project_id}/clusters/{cluster_id}/apps/{app_name}/run -> porter_app.NewRunAppJobHandler
  1526. runAppJobEndpoint := factory.NewAPIEndpoint(
  1527. &types.APIRequestMetadata{
  1528. Verb: types.APIVerbUpdate,
  1529. Method: types.HTTPVerbPost,
  1530. Path: &types.Path{
  1531. Parent: basePath,
  1532. RelativePath: fmt.Sprintf("%s/{%s}/run", relPathV2, types.URLParamPorterAppName),
  1533. },
  1534. Scopes: []types.PermissionScope{
  1535. types.UserScope,
  1536. types.ProjectScope,
  1537. types.ClusterScope,
  1538. },
  1539. },
  1540. )
  1541. runAppJobHandler := porter_app.NewRunAppJobHandler(
  1542. config,
  1543. factory.GetDecoderValidator(),
  1544. factory.GetResultWriter(),
  1545. )
  1546. routes = append(routes, &router.Route{
  1547. Endpoint: runAppJobEndpoint,
  1548. Handler: runAppJobHandler,
  1549. Router: r,
  1550. })
  1551. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{app_name}/run-status -> porter_app.NewAppJobRunStatusHandler
  1552. appJobRunStatusEndpoint := factory.NewAPIEndpoint(
  1553. &types.APIRequestMetadata{
  1554. Verb: types.APIVerbGet,
  1555. Method: types.HTTPVerbGet,
  1556. Path: &types.Path{
  1557. Parent: basePath,
  1558. RelativePath: fmt.Sprintf("%s/{%s}/run-status", relPathV2, types.URLParamPorterAppName),
  1559. },
  1560. Scopes: []types.PermissionScope{
  1561. types.UserScope,
  1562. types.ProjectScope,
  1563. types.ClusterScope,
  1564. },
  1565. },
  1566. )
  1567. appJobRunStatusHandler := porter_app.NewAppJobRunStatusHandler(
  1568. config,
  1569. factory.GetDecoderValidator(),
  1570. factory.GetResultWriter(),
  1571. )
  1572. routes = append(routes, &router.Route{
  1573. Endpoint: appJobRunStatusEndpoint,
  1574. Handler: appJobRunStatusHandler,
  1575. Router: r,
  1576. })
  1577. return routes, newPath
  1578. }