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. // POST /api/projects/{project_id}/clusters/{cluster_id}/applications/analytics -> porter_app.NewPorterAppAnalyticsHandler
  355. porterAppAnalyticsEndpoint := factory.NewAPIEndpoint(
  356. &types.APIRequestMetadata{
  357. Verb: types.APIVerbUpdate,
  358. Method: types.HTTPVerbPost,
  359. Path: &types.Path{
  360. Parent: basePath,
  361. RelativePath: fmt.Sprintf("%s/analytics", relPath),
  362. },
  363. Scopes: []types.PermissionScope{
  364. types.UserScope,
  365. types.ProjectScope,
  366. types.ClusterScope,
  367. },
  368. },
  369. )
  370. porterAppAnalyticsHandler := porter_app.NewPorterAppAnalyticsHandler(
  371. config,
  372. factory.GetDecoderValidator(),
  373. factory.GetResultWriter(),
  374. )
  375. routes = append(routes, &router.Route{
  376. Endpoint: porterAppAnalyticsEndpoint,
  377. Handler: porterAppAnalyticsHandler,
  378. Router: r,
  379. })
  380. // GET /api/projects/{project_id}/clusters/{cluster_id}/applications/logs -> cluster.NewGetChartLogsWithinTimeRangeHandler
  381. getChartLogsWithinTimeRangeEndpoint := factory.NewAPIEndpoint(
  382. &types.APIRequestMetadata{
  383. Verb: types.APIVerbGet,
  384. Method: types.HTTPVerbGet,
  385. Path: &types.Path{
  386. Parent: basePath,
  387. RelativePath: fmt.Sprintf("%s/logs", relPath),
  388. },
  389. Scopes: []types.PermissionScope{
  390. types.UserScope,
  391. types.ProjectScope,
  392. types.ClusterScope,
  393. },
  394. },
  395. )
  396. getChartLogsWithinTimeRangeHandler := porter_app.NewGetLogsWithinTimeRangeHandler(
  397. config,
  398. factory.GetDecoderValidator(),
  399. factory.GetResultWriter(),
  400. )
  401. routes = append(routes, &router.Route{
  402. Endpoint: getChartLogsWithinTimeRangeEndpoint,
  403. Handler: getChartLogsWithinTimeRangeHandler,
  404. Router: r,
  405. })
  406. // POST /api/projects/{project_id}/clusters/{cluster_id}/applications/{porter_app_name}/run -> porter_app.NewRunPorterAppCommandHandler
  407. runPorterAppCommandEndpoint := factory.NewAPIEndpoint(
  408. &types.APIRequestMetadata{
  409. Verb: types.APIVerbCreate,
  410. Method: types.HTTPVerbPost,
  411. Path: &types.Path{
  412. Parent: basePath,
  413. RelativePath: fmt.Sprintf("%s/{%s}/run", relPath, types.URLParamPorterAppName),
  414. },
  415. Scopes: []types.PermissionScope{
  416. types.UserScope,
  417. types.ProjectScope,
  418. types.ClusterScope,
  419. },
  420. },
  421. )
  422. runPorterAppCommandHandler := porter_app.NewRunPorterAppCommandHandler(
  423. config,
  424. factory.GetDecoderValidator(),
  425. factory.GetResultWriter(),
  426. )
  427. routes = append(routes, &router.Route{
  428. Endpoint: runPorterAppCommandEndpoint,
  429. Handler: runPorterAppCommandHandler,
  430. Router: r,
  431. })
  432. // TODO: remove these three endpoints once these three 'stacks' routes are no longer used in telemetry
  433. // GET /api/projects/{project_id}/clusters/{cluster_id}/stacks/{name} -> porter_app.NewPorterAppGetHandler
  434. LEGACY_getPorterAppEndpoint := factory.NewAPIEndpoint(
  435. &types.APIRequestMetadata{
  436. Verb: types.APIVerbGet,
  437. Method: types.HTTPVerbGet,
  438. Path: &types.Path{
  439. Parent: basePath,
  440. RelativePath: fmt.Sprintf("/stacks/{%s}", types.URLParamPorterAppName),
  441. },
  442. Scopes: []types.PermissionScope{
  443. types.UserScope,
  444. types.ProjectScope,
  445. types.ClusterScope,
  446. },
  447. },
  448. )
  449. LEGACY_getPorterAppHandler := porter_app.NewGetPorterAppHandler(
  450. config,
  451. factory.GetResultWriter(),
  452. )
  453. routes = append(routes, &router.Route{
  454. Endpoint: LEGACY_getPorterAppEndpoint,
  455. Handler: LEGACY_getPorterAppHandler,
  456. Router: r,
  457. })
  458. // POST /api/projects/{project_id}/clusters/{cluster_id}/stacks/{porter_app_name} -> porter_app.NewCreatePorterAppHandler
  459. LEGACY_createPorterAppEndpoint := factory.NewAPIEndpoint(
  460. &types.APIRequestMetadata{
  461. Verb: types.APIVerbCreate,
  462. Method: types.HTTPVerbPost,
  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_createPorterAppHandler := porter_app.NewCreatePorterAppHandler(
  475. config,
  476. factory.GetDecoderValidator(),
  477. factory.GetResultWriter(),
  478. )
  479. routes = append(routes, &router.Route{
  480. Endpoint: LEGACY_createPorterAppEndpoint,
  481. Handler: LEGACY_createPorterAppHandler,
  482. Router: r,
  483. })
  484. // POST /api/projects/{project_id}/clusters/{cluster_id}/stacks/{name}/events -> porter_app.NewCreatePorterAppEventHandler
  485. LEGACY_createPorterAppEventEndpoint := factory.NewAPIEndpoint(
  486. &types.APIRequestMetadata{
  487. Verb: types.APIVerbCreate,
  488. Method: types.HTTPVerbPost,
  489. Path: &types.Path{
  490. Parent: basePath,
  491. RelativePath: fmt.Sprintf("/stacks/{%s}/events", types.URLParamPorterAppName),
  492. },
  493. Scopes: []types.PermissionScope{
  494. types.UserScope,
  495. types.ProjectScope,
  496. types.ClusterScope,
  497. },
  498. },
  499. )
  500. LEGACY_createPorterAppEventHandler := porter_app.NewCreateUpdatePorterAppEventHandler(
  501. config,
  502. factory.GetDecoderValidator(),
  503. factory.GetResultWriter(),
  504. )
  505. routes = append(routes, &router.Route{
  506. Endpoint: LEGACY_createPorterAppEventEndpoint,
  507. Handler: LEGACY_createPorterAppEventHandler,
  508. Router: r,
  509. })
  510. // POST /api/projects/{project_id}/clusters/{cluster_id}/apps/parse -> porter_app.NewParsePorterYAMLToProtoHandler
  511. parsePorterYAMLToProtoEndpoint := factory.NewAPIEndpoint(
  512. &types.APIRequestMetadata{
  513. Verb: types.APIVerbGet,
  514. Method: types.HTTPVerbPost,
  515. Path: &types.Path{
  516. Parent: basePath,
  517. RelativePath: fmt.Sprintf("%s/parse", relPathV2),
  518. },
  519. Scopes: []types.PermissionScope{
  520. types.UserScope,
  521. types.ProjectScope,
  522. types.ClusterScope,
  523. },
  524. },
  525. )
  526. parsePorterYAMLToProtoHandler := porter_app.NewParsePorterYAMLToProtoHandler(
  527. config,
  528. factory.GetDecoderValidator(),
  529. factory.GetResultWriter(),
  530. )
  531. routes = append(routes, &router.Route{
  532. Endpoint: parsePorterYAMLToProtoEndpoint,
  533. Handler: parsePorterYAMLToProtoHandler,
  534. Router: r,
  535. })
  536. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/manifests -> porter_app.NewGetAppManifestsHandler
  537. getAppManifestsEndpoint := factory.NewAPIEndpoint(
  538. &types.APIRequestMetadata{
  539. Verb: types.APIVerbGet,
  540. Method: types.HTTPVerbGet,
  541. Path: &types.Path{
  542. Parent: basePath,
  543. RelativePath: fmt.Sprintf("%s/{%s}/manifests", relPathV2, types.URLParamPorterAppName),
  544. },
  545. Scopes: []types.PermissionScope{
  546. types.UserScope,
  547. types.ProjectScope,
  548. types.ClusterScope,
  549. },
  550. },
  551. )
  552. getAppManifestsHandler := porter_app.NewAppManifestsHandler(
  553. config,
  554. factory.GetDecoderValidator(),
  555. factory.GetResultWriter(),
  556. )
  557. routes = append(routes, &router.Route{
  558. Endpoint: getAppManifestsEndpoint,
  559. Handler: getAppManifestsHandler,
  560. Router: r,
  561. })
  562. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/env-variables -> porter_app.AppEnvVariablesHandler
  563. appEnvVariablesEndpoint := factory.NewAPIEndpoint(
  564. &types.APIRequestMetadata{
  565. Verb: types.APIVerbGet,
  566. Method: types.HTTPVerbGet,
  567. Path: &types.Path{
  568. Parent: basePath,
  569. RelativePath: fmt.Sprintf("%s/{%s}/env-variables", relPathV2, types.URLParamPorterAppName),
  570. },
  571. Scopes: []types.PermissionScope{
  572. types.UserScope,
  573. types.ProjectScope,
  574. types.ClusterScope,
  575. },
  576. },
  577. )
  578. appEnvVariablesHandler := porter_app.NewAppEnvVariablesHandler(
  579. config,
  580. factory.GetDecoderValidator(),
  581. factory.GetResultWriter(),
  582. )
  583. routes = append(routes, &router.Route{
  584. Endpoint: appEnvVariablesEndpoint,
  585. Handler: appEnvVariablesHandler,
  586. Router: r,
  587. })
  588. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/revisions/{app_revision_id}/yaml -> porter_app.NewPorterYAMLFromRevisionHandler
  589. porterYAMLFromRevision := factory.NewAPIEndpoint(
  590. &types.APIRequestMetadata{
  591. Verb: types.APIVerbGet,
  592. Method: types.HTTPVerbGet,
  593. Path: &types.Path{
  594. Parent: basePath,
  595. RelativePath: fmt.Sprintf("%s/{%s}/revisions/{%s}/yaml", relPathV2, types.URLParamPorterAppName, types.URLParamAppRevisionID),
  596. },
  597. Scopes: []types.PermissionScope{
  598. types.UserScope,
  599. types.ProjectScope,
  600. types.ClusterScope,
  601. },
  602. },
  603. )
  604. porterYAMLFromRevisionHandler := porter_app.NewPorterYAMLFromRevisionHandler(
  605. config,
  606. factory.GetDecoderValidator(),
  607. factory.GetResultWriter(),
  608. )
  609. routes = append(routes, &router.Route{
  610. Endpoint: porterYAMLFromRevision,
  611. Handler: porterYAMLFromRevisionHandler,
  612. Router: r,
  613. })
  614. // POST /api/projects/{project_id}/clusters/{cluster_id}/apps/create -> porter_app.NewCreateAppHandler
  615. createAppEndpoint := factory.NewAPIEndpoint(
  616. &types.APIRequestMetadata{
  617. Verb: types.APIVerbCreate,
  618. Method: types.HTTPVerbPost,
  619. Path: &types.Path{
  620. Parent: basePath,
  621. RelativePath: fmt.Sprintf("%s/create", relPathV2),
  622. },
  623. Scopes: []types.PermissionScope{
  624. types.UserScope,
  625. types.ProjectScope,
  626. types.ClusterScope,
  627. },
  628. },
  629. )
  630. createAppHandler := porter_app.NewCreateAppHandler(
  631. config,
  632. factory.GetDecoderValidator(),
  633. factory.GetResultWriter(),
  634. )
  635. routes = append(routes, &router.Route{
  636. Endpoint: createAppEndpoint,
  637. Handler: createAppHandler,
  638. Router: r,
  639. })
  640. // POST /api/projects/{project_id}/clusters/{cluster_id}/apps/attach-env-group -> porter_app.NewAttachEnvGroupHandler
  641. attachEnvGroupEndpoint := factory.NewAPIEndpoint(
  642. &types.APIRequestMetadata{
  643. Verb: types.APIVerbUpdate,
  644. Method: types.HTTPVerbPost,
  645. Path: &types.Path{
  646. Parent: basePath,
  647. RelativePath: fmt.Sprintf("%s/attach-env-group", relPathV2),
  648. },
  649. Scopes: []types.PermissionScope{
  650. types.UserScope,
  651. types.ProjectScope,
  652. types.ClusterScope,
  653. },
  654. },
  655. )
  656. attachEnvGroupHandler := porter_app.NewAttachEnvGroupHandler(
  657. config,
  658. factory.GetDecoderValidator(),
  659. factory.GetResultWriter(),
  660. )
  661. routes = append(routes, &router.Route{
  662. Endpoint: attachEnvGroupEndpoint,
  663. Handler: attachEnvGroupHandler,
  664. Router: r,
  665. })
  666. // POST /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/rollback -> porter_app.NewRollbackAppRevisionHandler
  667. rollbackAppRevisionEndpoint := factory.NewAPIEndpoint(
  668. &types.APIRequestMetadata{
  669. Verb: types.APIVerbUpdate,
  670. Method: types.HTTPVerbPost,
  671. Path: &types.Path{
  672. Parent: basePath,
  673. RelativePath: fmt.Sprintf("%s/{%s}/rollback", relPathV2, types.URLParamPorterAppName),
  674. },
  675. Scopes: []types.PermissionScope{
  676. types.UserScope,
  677. types.ProjectScope,
  678. types.ClusterScope,
  679. },
  680. },
  681. )
  682. rollbackAppRevisionHandler := porter_app.NewRollbackAppRevisionHandler(
  683. config,
  684. factory.GetDecoderValidator(),
  685. factory.GetResultWriter(),
  686. )
  687. routes = append(routes, &router.Route{
  688. Endpoint: rollbackAppRevisionEndpoint,
  689. Handler: rollbackAppRevisionHandler,
  690. Router: r,
  691. })
  692. // POST /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/update-image -> porter_app.NewUpdateImageHandler
  693. updatePorterAppImageEndpoint := factory.NewAPIEndpoint(
  694. &types.APIRequestMetadata{
  695. Verb: types.APIVerbUpdate,
  696. Method: types.HTTPVerbPost,
  697. Path: &types.Path{
  698. Parent: basePath,
  699. RelativePath: fmt.Sprintf("%s/{%s}/update-image", relPathV2, types.URLParamPorterAppName),
  700. },
  701. Scopes: []types.PermissionScope{
  702. types.UserScope,
  703. types.ProjectScope,
  704. types.ClusterScope,
  705. },
  706. },
  707. )
  708. updatePorterAppImageHandler := porter_app.NewUpdateImageHandler(
  709. config,
  710. factory.GetDecoderValidator(),
  711. factory.GetResultWriter(),
  712. )
  713. routes = append(routes, &router.Route{
  714. Endpoint: updatePorterAppImageEndpoint,
  715. Handler: updatePorterAppImageHandler,
  716. Router: r,
  717. })
  718. // GET /api/projects/{project_id}/clusters/{cluster_id}/default-deployment-target -> porter_app.NewDefaultDeploymentTargetHandler
  719. defaultDeploymentTargetEndpoint := factory.NewAPIEndpoint(
  720. &types.APIRequestMetadata{
  721. Verb: types.APIVerbGet,
  722. Method: types.HTTPVerbGet,
  723. Path: &types.Path{
  724. Parent: basePath,
  725. RelativePath: "/default-deployment-target",
  726. },
  727. Scopes: []types.PermissionScope{
  728. types.UserScope,
  729. types.ProjectScope,
  730. types.ClusterScope,
  731. },
  732. },
  733. )
  734. defaultDeploymentTargetHandler := porter_app.NewDefaultDeploymentTargetHandler(
  735. config,
  736. factory.GetDecoderValidator(),
  737. factory.GetResultWriter(),
  738. )
  739. routes = append(routes, &router.Route{
  740. Endpoint: defaultDeploymentTargetEndpoint,
  741. Handler: defaultDeploymentTargetHandler,
  742. Router: r,
  743. })
  744. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/latest -> porter_app.NewCurrentAppRevisionHandler
  745. currentAppRevisionEndpoint := factory.NewAPIEndpoint(
  746. &types.APIRequestMetadata{
  747. Verb: types.APIVerbGet,
  748. Method: types.HTTPVerbGet,
  749. Path: &types.Path{
  750. Parent: basePath,
  751. RelativePath: fmt.Sprintf("%s/{%s}/latest", relPathV2, types.URLParamPorterAppName),
  752. },
  753. Scopes: []types.PermissionScope{
  754. types.UserScope,
  755. types.ProjectScope,
  756. types.ClusterScope,
  757. },
  758. },
  759. )
  760. currentAppRevisionHandler := porter_app.NewLatestAppRevisionHandler(
  761. config,
  762. factory.GetDecoderValidator(),
  763. factory.GetResultWriter(),
  764. )
  765. routes = append(routes, &router.Route{
  766. Endpoint: currentAppRevisionEndpoint,
  767. Handler: currentAppRevisionHandler,
  768. Router: r,
  769. })
  770. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/notifications -> porter_app.NewAppNotificationsHandler
  771. appNotificationsEndpoint := factory.NewAPIEndpoint(
  772. &types.APIRequestMetadata{
  773. Verb: types.APIVerbGet,
  774. Method: types.HTTPVerbGet,
  775. Path: &types.Path{
  776. Parent: basePath,
  777. RelativePath: fmt.Sprintf("%s/{%s}/notifications", relPathV2, types.URLParamPorterAppName),
  778. },
  779. Scopes: []types.PermissionScope{
  780. types.UserScope,
  781. types.ProjectScope,
  782. types.ClusterScope,
  783. },
  784. },
  785. )
  786. appNotificationsHandler := porter_app.NewAppNotificationsHandler(
  787. config,
  788. factory.GetDecoderValidator(),
  789. factory.GetResultWriter(),
  790. )
  791. routes = append(routes, &router.Route{
  792. Endpoint: appNotificationsEndpoint,
  793. Handler: appNotificationsHandler,
  794. Router: r,
  795. })
  796. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/revisions -> porter_app.NewCurrentAppRevisionHandler
  797. listAppRevisionsEndpoint := factory.NewAPIEndpoint(
  798. &types.APIRequestMetadata{
  799. Verb: types.APIVerbGet,
  800. Method: types.HTTPVerbGet,
  801. Path: &types.Path{
  802. Parent: basePath,
  803. RelativePath: fmt.Sprintf("%s/{%s}/revisions", relPathV2, types.URLParamPorterAppName),
  804. },
  805. Scopes: []types.PermissionScope{
  806. types.UserScope,
  807. types.ProjectScope,
  808. types.ClusterScope,
  809. },
  810. },
  811. )
  812. listAppRevisionsHandler := porter_app.NewListAppRevisionsHandler(
  813. config,
  814. factory.GetDecoderValidator(),
  815. factory.GetResultWriter(),
  816. )
  817. routes = append(routes, &router.Route{
  818. Endpoint: listAppRevisionsEndpoint,
  819. Handler: listAppRevisionsHandler,
  820. Router: r,
  821. })
  822. // POST /api/projects/{project_id}/clusters/{cluster_id}/apps/update -> porter_app.UpdateAppHandler
  823. updateAppEndpoint := factory.NewAPIEndpoint(
  824. &types.APIRequestMetadata{
  825. Verb: types.APIVerbUpdate,
  826. Method: types.HTTPVerbPost,
  827. Path: &types.Path{
  828. Parent: basePath,
  829. RelativePath: fmt.Sprintf("%s/update", relPathV2),
  830. },
  831. Scopes: []types.PermissionScope{
  832. types.UserScope,
  833. types.ProjectScope,
  834. types.ClusterScope,
  835. },
  836. },
  837. )
  838. updateAppHandler := porter_app.NewUpdateAppHandler(
  839. config,
  840. factory.GetDecoderValidator(),
  841. factory.GetResultWriter(),
  842. )
  843. routes = append(routes, &router.Route{
  844. Endpoint: updateAppEndpoint,
  845. Handler: updateAppHandler,
  846. Router: r,
  847. })
  848. // POST /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/build -> porter_app.NewUpdateAppBuildSettingsHandler
  849. updateAppBuildSettingsEndpoint := factory.NewAPIEndpoint(
  850. &types.APIRequestMetadata{
  851. Verb: types.APIVerbUpdate,
  852. Method: types.HTTPVerbPost,
  853. Path: &types.Path{
  854. Parent: basePath,
  855. RelativePath: fmt.Sprintf("%s/{%s}/build", relPathV2, types.URLParamPorterAppName),
  856. },
  857. Scopes: []types.PermissionScope{
  858. types.UserScope,
  859. types.ProjectScope,
  860. types.ClusterScope,
  861. },
  862. },
  863. )
  864. updateAppBuildSettingsHandler := porter_app.NewUpdateAppBuildSettingsHandler(
  865. config,
  866. factory.GetDecoderValidator(),
  867. factory.GetResultWriter(),
  868. )
  869. routes = append(routes, &router.Route{
  870. Endpoint: updateAppBuildSettingsEndpoint,
  871. Handler: updateAppBuildSettingsHandler,
  872. Router: r,
  873. })
  874. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/revisions -> porter_app.NewLatestAppRevisionsHandler
  875. latestAppRevisionsEndpoint := factory.NewAPIEndpoint(
  876. &types.APIRequestMetadata{
  877. Verb: types.APIVerbGet,
  878. Method: types.HTTPVerbGet,
  879. Path: &types.Path{
  880. Parent: basePath,
  881. RelativePath: fmt.Sprintf("%s/revisions", relPathV2),
  882. },
  883. Scopes: []types.PermissionScope{
  884. types.UserScope,
  885. types.ProjectScope,
  886. types.ClusterScope,
  887. },
  888. },
  889. )
  890. latestAppRevisionsHandler := porter_app.NewLatestAppRevisionsHandler(
  891. config,
  892. factory.GetDecoderValidator(),
  893. factory.GetResultWriter(),
  894. )
  895. routes = append(routes, &router.Route{
  896. Endpoint: latestAppRevisionsEndpoint,
  897. Handler: latestAppRevisionsHandler,
  898. Router: r,
  899. })
  900. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/instances -> porter_app.NewAppInstancesHandler
  901. latestAppInstancesEndpoint := factory.NewAPIEndpoint(
  902. &types.APIRequestMetadata{
  903. Verb: types.APIVerbGet,
  904. Method: types.HTTPVerbGet,
  905. Path: &types.Path{
  906. Parent: basePath,
  907. RelativePath: fmt.Sprintf("%s/instances", relPathV2),
  908. },
  909. Scopes: []types.PermissionScope{
  910. types.UserScope,
  911. types.ProjectScope,
  912. types.ClusterScope,
  913. },
  914. },
  915. )
  916. latestAppInstancesHandler := porter_app.NewAppInstancesHandler(
  917. config,
  918. factory.GetDecoderValidator(),
  919. factory.GetResultWriter(),
  920. )
  921. routes = append(routes, &router.Route{
  922. Endpoint: latestAppInstancesEndpoint,
  923. Handler: latestAppInstancesHandler,
  924. Router: r,
  925. })
  926. // POST /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/subdomain -> porter_app.NewCreateSubdomainHandler
  927. createSubdomainEndpoint := factory.NewAPIEndpoint(
  928. &types.APIRequestMetadata{
  929. Verb: types.APIVerbUpdate,
  930. Method: types.HTTPVerbPost,
  931. Path: &types.Path{
  932. Parent: basePath,
  933. RelativePath: fmt.Sprintf("%s/{%s}/subdomain", relPathV2, types.URLParamPorterAppName),
  934. },
  935. Scopes: []types.PermissionScope{
  936. types.UserScope,
  937. types.ProjectScope,
  938. types.ClusterScope,
  939. },
  940. },
  941. )
  942. createSubdomainHandler := porter_app.NewCreateSubdomainHandler(
  943. config,
  944. factory.GetDecoderValidator(),
  945. factory.GetResultWriter(),
  946. )
  947. routes = append(routes, &router.Route{
  948. Endpoint: createSubdomainEndpoint,
  949. Handler: createSubdomainHandler,
  950. Router: r,
  951. })
  952. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/{app_revision_id}/predeploy-status -> porter_app.NewPredeployStatusHandler
  953. predeployStatusEndpoint := factory.NewAPIEndpoint(
  954. &types.APIRequestMetadata{
  955. Verb: types.APIVerbGet,
  956. Method: types.HTTPVerbGet,
  957. Path: &types.Path{
  958. Parent: basePath,
  959. RelativePath: fmt.Sprintf("%s/{%s}/{%s}/predeploy-status", relPathV2, types.URLParamPorterAppName, types.URLParamAppRevisionID),
  960. },
  961. Scopes: []types.PermissionScope{
  962. types.UserScope,
  963. types.ProjectScope,
  964. types.ClusterScope,
  965. },
  966. },
  967. )
  968. predeployStatusHandler := porter_app.NewPredeployStatusHandler(
  969. config,
  970. factory.GetDecoderValidator(),
  971. factory.GetResultWriter(),
  972. )
  973. routes = append(routes, &router.Route{
  974. Endpoint: predeployStatusEndpoint,
  975. Handler: predeployStatusHandler,
  976. Router: r,
  977. })
  978. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/logs -> cluster.NewAppLogsHandler
  979. appLogsEndpoint := factory.NewAPIEndpoint(
  980. &types.APIRequestMetadata{
  981. Verb: types.APIVerbGet,
  982. Method: types.HTTPVerbGet,
  983. Path: &types.Path{
  984. Parent: basePath,
  985. RelativePath: fmt.Sprintf("%s/{%s}/logs", relPathV2, types.URLParamPorterAppName),
  986. },
  987. Scopes: []types.PermissionScope{
  988. types.UserScope,
  989. types.ProjectScope,
  990. types.ClusterScope,
  991. },
  992. },
  993. )
  994. appLogsHandler := porter_app.NewAppLogsHandler(
  995. config,
  996. factory.GetDecoderValidator(),
  997. factory.GetResultWriter(),
  998. )
  999. routes = append(routes, &router.Route{
  1000. Endpoint: appLogsEndpoint,
  1001. Handler: appLogsHandler,
  1002. Router: r,
  1003. })
  1004. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/logs/loki -> namespace.NewStreamLogsLokiHandler
  1005. streamLogsLokiEndpoint := factory.NewAPIEndpoint(
  1006. &types.APIRequestMetadata{
  1007. Verb: types.APIVerbGet,
  1008. Method: types.HTTPVerbGet,
  1009. Path: &types.Path{
  1010. Parent: basePath,
  1011. RelativePath: fmt.Sprintf("%s/{%s}/logs/loki", relPathV2, types.URLParamPorterAppName),
  1012. },
  1013. Scopes: []types.PermissionScope{
  1014. types.UserScope,
  1015. types.ProjectScope,
  1016. types.ClusterScope,
  1017. },
  1018. IsWebsocket: true,
  1019. },
  1020. )
  1021. streamLogsLokiHandler := porter_app.NewStreamLogsLokiHandler(
  1022. config,
  1023. factory.GetDecoderValidator(),
  1024. factory.GetResultWriter(),
  1025. )
  1026. routes = append(routes, &router.Route{
  1027. Endpoint: streamLogsLokiEndpoint,
  1028. Handler: streamLogsLokiHandler,
  1029. Router: r,
  1030. })
  1031. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/metrics -> cluster.NewGetPodMetricsHandler
  1032. appMetricsEndpoint := factory.NewAPIEndpoint(
  1033. &types.APIRequestMetadata{
  1034. Verb: types.APIVerbGet,
  1035. Method: types.HTTPVerbGet,
  1036. Path: &types.Path{
  1037. Parent: basePath,
  1038. RelativePath: fmt.Sprintf("%s/metrics", relPathV2),
  1039. },
  1040. Scopes: []types.PermissionScope{
  1041. types.UserScope,
  1042. types.ProjectScope,
  1043. types.ClusterScope,
  1044. },
  1045. },
  1046. )
  1047. appMetricsHandler := porter_app.NewAppMetricsHandler(
  1048. config,
  1049. factory.GetDecoderValidator(),
  1050. factory.GetResultWriter(),
  1051. )
  1052. routes = append(routes, &router.Route{
  1053. Endpoint: appMetricsEndpoint,
  1054. Handler: appMetricsHandler,
  1055. Router: r,
  1056. })
  1057. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/status -> cluster.NewAppStatusHandler
  1058. appStatusEndpoint := factory.NewAPIEndpoint(
  1059. &types.APIRequestMetadata{
  1060. Verb: types.APIVerbGet,
  1061. Method: types.HTTPVerbGet,
  1062. Path: &types.Path{
  1063. Parent: basePath,
  1064. RelativePath: fmt.Sprintf("%s/{%s}/status", relPathV2, types.URLParamKind),
  1065. },
  1066. Scopes: []types.PermissionScope{
  1067. types.UserScope,
  1068. types.ProjectScope,
  1069. types.ClusterScope,
  1070. },
  1071. IsWebsocket: true,
  1072. },
  1073. )
  1074. appStatusHandler := porter_app.NewAppStatusHandler(
  1075. config,
  1076. factory.GetDecoderValidator(),
  1077. factory.GetResultWriter(),
  1078. )
  1079. routes = append(routes, &router.Route{
  1080. Endpoint: appStatusEndpoint,
  1081. Handler: appStatusHandler,
  1082. Router: r,
  1083. })
  1084. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/service_status -> cluster.NewAppServiceStatusHandler
  1085. appServiceStatusEndpoint := factory.NewAPIEndpoint(
  1086. &types.APIRequestMetadata{
  1087. Verb: types.APIVerbGet,
  1088. Method: types.HTTPVerbGet,
  1089. Path: &types.Path{
  1090. Parent: basePath,
  1091. RelativePath: fmt.Sprintf("%s/{%s}/service_status", relPathV2, types.URLParamPorterAppName),
  1092. },
  1093. Scopes: []types.PermissionScope{
  1094. types.UserScope,
  1095. types.ProjectScope,
  1096. types.ClusterScope,
  1097. },
  1098. },
  1099. )
  1100. appServiceStatusHandler := porter_app.NewServiceStatusHandler(
  1101. config,
  1102. factory.GetDecoderValidator(),
  1103. factory.GetResultWriter(),
  1104. )
  1105. routes = append(routes, &router.Route{
  1106. Endpoint: appServiceStatusEndpoint,
  1107. Handler: appServiceStatusHandler,
  1108. Router: r,
  1109. })
  1110. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/jobs -> cluster.NewJobStatusHandler
  1111. appJobStatusEndpoint := factory.NewAPIEndpoint(
  1112. &types.APIRequestMetadata{
  1113. Verb: types.APIVerbGet,
  1114. Method: types.HTTPVerbGet,
  1115. Path: &types.Path{
  1116. Parent: basePath,
  1117. RelativePath: fmt.Sprintf("%s/{%s}/jobs", relPathV2, types.URLParamPorterAppName),
  1118. },
  1119. Scopes: []types.PermissionScope{
  1120. types.UserScope,
  1121. types.ProjectScope,
  1122. types.ClusterScope,
  1123. },
  1124. },
  1125. )
  1126. appJobStatusHandler := porter_app.NewJobStatusHandler(
  1127. config,
  1128. factory.GetDecoderValidator(),
  1129. factory.GetResultWriter(),
  1130. )
  1131. routes = append(routes, &router.Route{
  1132. Endpoint: appJobStatusEndpoint,
  1133. Handler: appJobStatusHandler,
  1134. Router: r,
  1135. })
  1136. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/jobs/{job_run_name} -> porter_app.JobStatusByNameHandler
  1137. appJobStatusByNameEndpoint := factory.NewAPIEndpoint(
  1138. &types.APIRequestMetadata{
  1139. Verb: types.APIVerbGet,
  1140. Method: types.HTTPVerbGet,
  1141. Path: &types.Path{
  1142. Parent: basePath,
  1143. RelativePath: fmt.Sprintf("%s/{%s}/jobs/{%s}", relPathV2, types.URLParamPorterAppName, types.URLParamJobRunName),
  1144. },
  1145. Scopes: []types.PermissionScope{
  1146. types.UserScope,
  1147. types.ProjectScope,
  1148. types.ClusterScope,
  1149. },
  1150. },
  1151. )
  1152. appJobStatusByNameHandler := porter_app.NewJobStatusByNameHandler(
  1153. config,
  1154. factory.GetDecoderValidator(),
  1155. factory.GetResultWriter(),
  1156. )
  1157. routes = append(routes, &router.Route{
  1158. Endpoint: appJobStatusByNameEndpoint,
  1159. Handler: appJobStatusByNameHandler,
  1160. Router: r,
  1161. })
  1162. // POST /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/jobs/{job_run_name}/cancel -> porter_app.CancelJobRunHandler
  1163. appJobCancelEndpoint := factory.NewAPIEndpoint(
  1164. &types.APIRequestMetadata{
  1165. Verb: types.APIVerbUpdate,
  1166. Method: types.HTTPVerbPost,
  1167. Path: &types.Path{
  1168. Parent: basePath,
  1169. RelativePath: fmt.Sprintf("%s/{%s}/jobs/{%s}/cancel", relPathV2, types.URLParamPorterAppName, types.URLParamJobRunName),
  1170. },
  1171. Scopes: []types.PermissionScope{
  1172. types.UserScope,
  1173. types.ProjectScope,
  1174. types.ClusterScope,
  1175. },
  1176. },
  1177. )
  1178. appJobCancelHandler := porter_app.NewCancelJobRunHandler(
  1179. config,
  1180. factory.GetDecoderValidator(),
  1181. factory.GetResultWriter(),
  1182. )
  1183. routes = append(routes, &router.Route{
  1184. Endpoint: appJobCancelEndpoint,
  1185. Handler: appJobCancelHandler,
  1186. Router: r,
  1187. })
  1188. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/revisions/{app_revision_id} -> porter_app.NewGetAppRevisionHandler
  1189. getAppRevisionEndpoint := factory.NewAPIEndpoint(
  1190. &types.APIRequestMetadata{
  1191. Verb: types.APIVerbGet,
  1192. Method: types.HTTPVerbGet,
  1193. Path: &types.Path{
  1194. Parent: basePath,
  1195. RelativePath: fmt.Sprintf("/apps/{%s}/revisions/{%s}", types.URLParamPorterAppName, types.URLParamAppRevisionID),
  1196. },
  1197. Scopes: []types.PermissionScope{
  1198. types.UserScope,
  1199. types.ProjectScope,
  1200. types.ClusterScope,
  1201. },
  1202. },
  1203. )
  1204. getAppRevisionHandler := porter_app.NewGetAppRevisionHandler(
  1205. config,
  1206. factory.GetDecoderValidator(),
  1207. factory.GetResultWriter(),
  1208. )
  1209. routes = append(routes, &router.Route{
  1210. Endpoint: getAppRevisionEndpoint,
  1211. Handler: getAppRevisionHandler,
  1212. Router: r,
  1213. })
  1214. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/revisions/{app_revision_id}/status -> porter_app.NewGetAppRevisionStatusHandler
  1215. getAppRevisionStatusEndpoint := factory.NewAPIEndpoint(
  1216. &types.APIRequestMetadata{
  1217. Verb: types.APIVerbGet,
  1218. Method: types.HTTPVerbGet,
  1219. Path: &types.Path{
  1220. Parent: basePath,
  1221. RelativePath: fmt.Sprintf("/apps/{%s}/revisions/{%s}/status", types.URLParamPorterAppName, types.URLParamAppRevisionID),
  1222. },
  1223. Scopes: []types.PermissionScope{
  1224. types.UserScope,
  1225. types.ProjectScope,
  1226. types.ClusterScope,
  1227. },
  1228. },
  1229. )
  1230. getAppRevisionStatusHandler := porter_app.NewGetAppRevisionStatusHandler(
  1231. config,
  1232. factory.GetDecoderValidator(),
  1233. factory.GetResultWriter(),
  1234. )
  1235. routes = append(routes, &router.Route{
  1236. Endpoint: getAppRevisionStatusEndpoint,
  1237. Handler: getAppRevisionStatusHandler,
  1238. Router: r,
  1239. })
  1240. // POST /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/revisions/{app_revision_id} -> porter_app.NewUpdateAppRevisionStatusHandler
  1241. updateAppRevisionStatusEndpoint := factory.NewAPIEndpoint(
  1242. &types.APIRequestMetadata{
  1243. Verb: types.APIVerbUpdate,
  1244. Method: types.HTTPVerbPost,
  1245. Path: &types.Path{
  1246. Parent: basePath,
  1247. RelativePath: fmt.Sprintf("/apps/{%s}/revisions/{%s}", types.URLParamPorterAppName, types.URLParamAppRevisionID),
  1248. },
  1249. Scopes: []types.PermissionScope{
  1250. types.UserScope,
  1251. types.ProjectScope,
  1252. types.ClusterScope,
  1253. },
  1254. },
  1255. )
  1256. updateAppRevisionStatusHandler := porter_app.NewUpdateAppRevisionStatusHandler(
  1257. config,
  1258. factory.GetDecoderValidator(),
  1259. factory.GetResultWriter(),
  1260. )
  1261. routes = append(routes, &router.Route{
  1262. Endpoint: updateAppRevisionStatusEndpoint,
  1263. Handler: updateAppRevisionStatusHandler,
  1264. Router: r,
  1265. })
  1266. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/revisions/{app_revision_id}/build-env -> porter_app.NewGetBuildEnvHandler
  1267. getBuildEnvEndpoint := factory.NewAPIEndpoint(
  1268. &types.APIRequestMetadata{
  1269. Verb: types.APIVerbGet,
  1270. Method: types.HTTPVerbGet,
  1271. Path: &types.Path{
  1272. Parent: basePath,
  1273. RelativePath: fmt.Sprintf("/apps/{%s}/revisions/{%s}/build-env", types.URLParamPorterAppName, types.URLParamAppRevisionID),
  1274. },
  1275. Scopes: []types.PermissionScope{
  1276. types.UserScope,
  1277. types.ProjectScope,
  1278. types.ClusterScope,
  1279. },
  1280. },
  1281. )
  1282. getBuildEnvHandler := porter_app.NewGetBuildEnvHandler(
  1283. config,
  1284. factory.GetDecoderValidator(),
  1285. factory.GetResultWriter(),
  1286. )
  1287. routes = append(routes, &router.Route{
  1288. Endpoint: getBuildEnvEndpoint,
  1289. Handler: getBuildEnvHandler,
  1290. Router: r,
  1291. })
  1292. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/revisions/{app_revision_id}/build -> porter_app.NewGetBuildFromRevisionHandler
  1293. getBuildFromRevisionEndpoint := factory.NewAPIEndpoint(
  1294. &types.APIRequestMetadata{
  1295. Verb: types.APIVerbGet,
  1296. Method: types.HTTPVerbGet,
  1297. Path: &types.Path{
  1298. Parent: basePath,
  1299. RelativePath: fmt.Sprintf("/apps/{%s}/revisions/{%s}/build", types.URLParamPorterAppName, types.URLParamAppRevisionID),
  1300. },
  1301. Scopes: []types.PermissionScope{
  1302. types.UserScope,
  1303. types.ProjectScope,
  1304. types.ClusterScope,
  1305. },
  1306. },
  1307. )
  1308. getBuildFromRevisionHandler := porter_app.NewGetBuildFromRevisionHandler(
  1309. config,
  1310. factory.GetDecoderValidator(),
  1311. factory.GetResultWriter(),
  1312. )
  1313. routes = append(routes, &router.Route{
  1314. Endpoint: getBuildFromRevisionEndpoint,
  1315. Handler: getBuildFromRevisionHandler,
  1316. Router: r,
  1317. })
  1318. // POST /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/revisions/{app_revision_id}/status -> porter_app.NewReportRevisionStatusHandler
  1319. reportRevisionStatusEndpoint := factory.NewAPIEndpoint(
  1320. &types.APIRequestMetadata{
  1321. Verb: types.APIVerbUpdate,
  1322. Method: types.HTTPVerbPost,
  1323. Path: &types.Path{
  1324. Parent: basePath,
  1325. RelativePath: fmt.Sprintf("/apps/{%s}/revisions/{%s}/status", types.URLParamPorterAppName, types.URLParamAppRevisionID),
  1326. },
  1327. Scopes: []types.PermissionScope{
  1328. types.UserScope,
  1329. types.ProjectScope,
  1330. types.ClusterScope,
  1331. },
  1332. },
  1333. )
  1334. reportRevisionStatusHandler := porter_app.NewReportRevisionStatusHandler(
  1335. config,
  1336. factory.GetDecoderValidator(),
  1337. factory.GetResultWriter(),
  1338. )
  1339. routes = append(routes, &router.Route{
  1340. Endpoint: reportRevisionStatusEndpoint,
  1341. Handler: reportRevisionStatusHandler,
  1342. Router: r,
  1343. })
  1344. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/revisions/{app_revision_id}/env -> porter_app.NewGetAppEnvHandler
  1345. getAppEnvEndpoint := factory.NewAPIEndpoint(
  1346. &types.APIRequestMetadata{
  1347. Verb: types.APIVerbGet,
  1348. Method: types.HTTPVerbGet,
  1349. Path: &types.Path{
  1350. Parent: basePath,
  1351. RelativePath: fmt.Sprintf("/apps/{%s}/revisions/{%s}/env", types.URLParamPorterAppName, types.URLParamAppRevisionID),
  1352. },
  1353. Scopes: []types.PermissionScope{
  1354. types.UserScope,
  1355. types.ProjectScope,
  1356. types.ClusterScope,
  1357. },
  1358. },
  1359. )
  1360. getAppEnvHandler := porter_app.NewGetAppEnvHandler(
  1361. config,
  1362. factory.GetDecoderValidator(),
  1363. factory.GetResultWriter(),
  1364. )
  1365. routes = append(routes, &router.Route{
  1366. Endpoint: getAppEnvEndpoint,
  1367. Handler: getAppEnvHandler,
  1368. Router: r,
  1369. })
  1370. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/events -> porter_app.NewPorterAppV2EventListHandler
  1371. listPorterAppV2EventsEndpoint := factory.NewAPIEndpoint(
  1372. &types.APIRequestMetadata{
  1373. Verb: types.APIVerbList,
  1374. Method: types.HTTPVerbGet,
  1375. Path: &types.Path{
  1376. Parent: basePath,
  1377. RelativePath: fmt.Sprintf("%s/{%s}/events", relPathV2, types.URLParamPorterAppName),
  1378. },
  1379. Scopes: []types.PermissionScope{
  1380. types.UserScope,
  1381. types.ProjectScope,
  1382. types.ClusterScope,
  1383. },
  1384. },
  1385. )
  1386. listPorterAppV2EventsHandler := porter_app.NewPorterAppV2EventListHandler(
  1387. config,
  1388. factory.GetDecoderValidator(),
  1389. factory.GetResultWriter(),
  1390. )
  1391. routes = append(routes, &router.Route{
  1392. Endpoint: listPorterAppV2EventsEndpoint,
  1393. Handler: listPorterAppV2EventsHandler,
  1394. Router: r,
  1395. })
  1396. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/templates -> porter_app.NewListEnvironmentTemplatesHandler
  1397. listEnvironmentTemplatesEndpoint := factory.NewAPIEndpoint(
  1398. &types.APIRequestMetadata{
  1399. Verb: types.APIVerbList,
  1400. Method: types.HTTPVerbGet,
  1401. Path: &types.Path{
  1402. Parent: basePath,
  1403. RelativePath: fmt.Sprintf("%s/templates", relPathV2),
  1404. },
  1405. Scopes: []types.PermissionScope{
  1406. types.UserScope,
  1407. types.ProjectScope,
  1408. types.ClusterScope,
  1409. },
  1410. },
  1411. )
  1412. listEnvironmentTemplatesHandler := porter_app.NewListEnvironmentTemplatesHandler(
  1413. config,
  1414. factory.GetDecoderValidator(),
  1415. factory.GetResultWriter(),
  1416. )
  1417. routes = append(routes, &router.Route{
  1418. Endpoint: listEnvironmentTemplatesEndpoint,
  1419. Handler: listEnvironmentTemplatesHandler,
  1420. Router: r,
  1421. })
  1422. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/templates -> porter_app.NewGetAppTemplateHandler
  1423. getAppTemplateEndpoint := factory.NewAPIEndpoint(
  1424. &types.APIRequestMetadata{
  1425. Verb: types.APIVerbGet,
  1426. Method: types.HTTPVerbGet,
  1427. Path: &types.Path{
  1428. Parent: basePath,
  1429. RelativePath: fmt.Sprintf("%s/{%s}/templates", relPathV2, types.URLParamPorterAppName),
  1430. },
  1431. Scopes: []types.PermissionScope{
  1432. types.UserScope,
  1433. types.ProjectScope,
  1434. types.ClusterScope,
  1435. },
  1436. },
  1437. )
  1438. getAppTemplateHandler := porter_app.NewGetAppTemplateHandler(
  1439. config,
  1440. factory.GetDecoderValidator(),
  1441. factory.GetResultWriter(),
  1442. )
  1443. routes = append(routes, &router.Route{
  1444. Endpoint: getAppTemplateEndpoint,
  1445. Handler: getAppTemplateHandler,
  1446. Router: r,
  1447. })
  1448. // POST /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/templates -> porter_app.NewCreateAppTemplateHandler
  1449. createAppTemplateEndpoint := factory.NewAPIEndpoint(
  1450. &types.APIRequestMetadata{
  1451. Verb: types.APIVerbCreate,
  1452. Method: types.HTTPVerbPost,
  1453. Path: &types.Path{
  1454. Parent: basePath,
  1455. RelativePath: fmt.Sprintf("%s/{%s}/templates", relPathV2, types.URLParamPorterAppName),
  1456. },
  1457. Scopes: []types.PermissionScope{
  1458. types.UserScope,
  1459. types.ProjectScope,
  1460. types.ClusterScope,
  1461. },
  1462. },
  1463. )
  1464. createAppTemplateHandler := porter_app.NewCreateAppTemplateHandler(
  1465. config,
  1466. factory.GetDecoderValidator(),
  1467. factory.GetResultWriter(),
  1468. )
  1469. routes = append(routes, &router.Route{
  1470. Endpoint: createAppTemplateEndpoint,
  1471. Handler: createAppTemplateHandler,
  1472. Router: r,
  1473. })
  1474. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/helm-values -> porter_app.NewAppHelmValuesHandler
  1475. appHelmValuesEndpoint := factory.NewAPIEndpoint(
  1476. &types.APIRequestMetadata{
  1477. Verb: types.APIVerbGet,
  1478. Method: types.HTTPVerbGet,
  1479. Path: &types.Path{
  1480. Parent: basePath,
  1481. RelativePath: fmt.Sprintf("%s/{%s}/helm-values", relPathV2, types.URLParamPorterAppName),
  1482. },
  1483. Scopes: []types.PermissionScope{
  1484. types.UserScope,
  1485. types.ProjectScope,
  1486. types.ClusterScope,
  1487. },
  1488. },
  1489. )
  1490. appHelmValuesHandler := porter_app.NewAppHelmValuesHandler(
  1491. config,
  1492. factory.GetDecoderValidator(),
  1493. factory.GetResultWriter(),
  1494. )
  1495. routes = append(routes, &router.Route{
  1496. Endpoint: appHelmValuesEndpoint,
  1497. Handler: appHelmValuesHandler,
  1498. Router: r,
  1499. })
  1500. // POST /api/projects/{project_id}/clusters/{cluster_id}/apps/{app_name}/run -> porter_app.NewRunAppJobHandler
  1501. runAppJobEndpoint := factory.NewAPIEndpoint(
  1502. &types.APIRequestMetadata{
  1503. Verb: types.APIVerbUpdate,
  1504. Method: types.HTTPVerbPost,
  1505. Path: &types.Path{
  1506. Parent: basePath,
  1507. RelativePath: fmt.Sprintf("%s/{%s}/run", relPathV2, types.URLParamPorterAppName),
  1508. },
  1509. Scopes: []types.PermissionScope{
  1510. types.UserScope,
  1511. types.ProjectScope,
  1512. types.ClusterScope,
  1513. },
  1514. },
  1515. )
  1516. runAppJobHandler := porter_app.NewRunAppJobHandler(
  1517. config,
  1518. factory.GetDecoderValidator(),
  1519. factory.GetResultWriter(),
  1520. )
  1521. routes = append(routes, &router.Route{
  1522. Endpoint: runAppJobEndpoint,
  1523. Handler: runAppJobHandler,
  1524. Router: r,
  1525. })
  1526. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{app_name}/run-status -> porter_app.NewAppJobRunStatusHandler
  1527. appJobRunStatusEndpoint := factory.NewAPIEndpoint(
  1528. &types.APIRequestMetadata{
  1529. Verb: types.APIVerbGet,
  1530. Method: types.HTTPVerbGet,
  1531. Path: &types.Path{
  1532. Parent: basePath,
  1533. RelativePath: fmt.Sprintf("%s/{%s}/run-status", relPathV2, types.URLParamPorterAppName),
  1534. },
  1535. Scopes: []types.PermissionScope{
  1536. types.UserScope,
  1537. types.ProjectScope,
  1538. types.ClusterScope,
  1539. },
  1540. },
  1541. )
  1542. appJobRunStatusHandler := porter_app.NewAppJobRunStatusHandler(
  1543. config,
  1544. factory.GetDecoderValidator(),
  1545. factory.GetResultWriter(),
  1546. )
  1547. routes = append(routes, &router.Route{
  1548. Endpoint: appJobRunStatusEndpoint,
  1549. Handler: appJobRunStatusHandler,
  1550. Router: r,
  1551. })
  1552. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/events/id -> porter_app.NewGetPorterAppEventHandler
  1553. getPorterAppEventEndpoint := factory.NewAPIEndpoint(
  1554. &types.APIRequestMetadata{
  1555. Verb: types.APIVerbGet,
  1556. Method: types.HTTPVerbGet,
  1557. Path: &types.Path{
  1558. Parent: basePath,
  1559. RelativePath: fmt.Sprintf("%s/{%s}/events/{%s}", relPathV2, types.URLParamPorterAppName, types.URLParamPorterAppEventID),
  1560. },
  1561. Scopes: []types.PermissionScope{
  1562. types.UserScope,
  1563. types.ProjectScope,
  1564. types.ClusterScope,
  1565. },
  1566. },
  1567. )
  1568. getPorterAppEventHandler := porter_app.NewGetPorterAppEventHandler(
  1569. config,
  1570. factory.GetResultWriter(),
  1571. )
  1572. routes = append(routes, &router.Route{
  1573. Endpoint: getPorterAppEventEndpoint,
  1574. Handler: getPorterAppEventHandler,
  1575. Router: r,
  1576. })
  1577. return routes, newPath
  1578. }