porter_app.go 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419
  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}/applications/{name}/releases/{version}/pods/all -> porter_app.NewPorterAppPodsGetHandler
  124. getPorterAppPodsEndpoint := factory.NewAPIEndpoint(
  125. &types.APIRequestMetadata{
  126. Verb: types.APIVerbList,
  127. Method: types.HTTPVerbGet,
  128. Path: &types.Path{
  129. Parent: basePath,
  130. RelativePath: fmt.Sprintf("%s/{%s}/releases/{%s}/pods/all", relPath, types.URLParamPorterAppName, types.URLParamReleaseVersion),
  131. },
  132. Scopes: []types.PermissionScope{
  133. types.UserScope,
  134. types.ProjectScope,
  135. types.ClusterScope,
  136. },
  137. },
  138. )
  139. getPorterAppPodsHandler := porter_app.NewPorterAppPodsGetHandler(
  140. config,
  141. factory.GetResultWriter(),
  142. )
  143. routes = append(routes, &router.Route{
  144. Endpoint: getPorterAppPodsEndpoint,
  145. Handler: getPorterAppPodsHandler,
  146. Router: r,
  147. })
  148. // GET /api/projects/{project_id}/clusters/{cluster_id}/applications -> porter_app.NewPorterAppListHandler
  149. listPorterAppEndpoint := factory.NewAPIEndpoint(
  150. &types.APIRequestMetadata{
  151. Verb: types.APIVerbList,
  152. Method: types.HTTPVerbGet,
  153. Path: &types.Path{
  154. Parent: basePath,
  155. RelativePath: relPath,
  156. },
  157. Scopes: []types.PermissionScope{
  158. types.UserScope,
  159. types.ProjectScope,
  160. types.ClusterScope,
  161. },
  162. },
  163. )
  164. listPorterAppHandler := porter_app.NewPorterAppListHandler(
  165. config,
  166. factory.GetResultWriter(),
  167. )
  168. routes = append(routes, &router.Route{
  169. Endpoint: listPorterAppEndpoint,
  170. Handler: listPorterAppHandler,
  171. Router: r,
  172. })
  173. // DELETE /api/projects/{project_id}/clusters/{cluster_id}/applications/{porter_app_name} -> release.NewDeletePorterAppByNameHandler
  174. deletePorterAppByNameEndpoint := factory.NewAPIEndpoint(
  175. &types.APIRequestMetadata{
  176. Verb: types.APIVerbDelete,
  177. Method: types.HTTPVerbDelete,
  178. Path: &types.Path{
  179. Parent: basePath,
  180. RelativePath: fmt.Sprintf("%s/{%s}", relPath, types.URLParamPorterAppName),
  181. },
  182. Scopes: []types.PermissionScope{
  183. types.UserScope,
  184. types.ProjectScope,
  185. types.ClusterScope,
  186. },
  187. },
  188. )
  189. deletePorterAppByNameHandler := porter_app.NewDeletePorterAppByNameHandler(
  190. config,
  191. factory.GetDecoderValidator(),
  192. factory.GetResultWriter(),
  193. )
  194. routes = append(routes, &router.Route{
  195. Endpoint: deletePorterAppByNameEndpoint,
  196. Handler: deletePorterAppByNameHandler,
  197. Router: r,
  198. })
  199. // POST /api/projects/{project_id}/clusters/{cluster_id}/applications/{porter_app_name} -> porter_app.NewCreatePorterAppHandler
  200. createPorterAppEndpoint := factory.NewAPIEndpoint(
  201. &types.APIRequestMetadata{
  202. Verb: types.APIVerbCreate,
  203. Method: types.HTTPVerbPost,
  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. createPorterAppHandler := porter_app.NewCreatePorterAppHandler(
  216. config,
  217. factory.GetDecoderValidator(),
  218. factory.GetResultWriter(),
  219. )
  220. routes = append(routes, &router.Route{
  221. Endpoint: createPorterAppEndpoint,
  222. Handler: createPorterAppHandler,
  223. Router: r,
  224. })
  225. // POST /api/projects/{project_id}/clusters/{cluster_id}/applications/{porter_app_name}/rollback -> porter_app.NewRollbackPorterAppHandler
  226. rollbackPorterAppEndpoint := 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}/rollback", relPath, types.URLParamPorterAppName),
  233. },
  234. Scopes: []types.PermissionScope{
  235. types.UserScope,
  236. types.ProjectScope,
  237. types.ClusterScope,
  238. },
  239. },
  240. )
  241. rollbackPorterAppHandler := porter_app.NewRollbackPorterAppHandler(
  242. config,
  243. factory.GetDecoderValidator(),
  244. factory.GetResultWriter(),
  245. )
  246. routes = append(routes, &router.Route{
  247. Endpoint: rollbackPorterAppEndpoint,
  248. Handler: rollbackPorterAppHandler,
  249. Router: r,
  250. })
  251. // POST /api/projects/{project_id}/clusters/{cluster_id}/applications/{porter_app_name}/pr -> porter_app.NewOpenStackPRHandler
  252. createSecretAndOpenGitHubPullRequestEndpoint := 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}/pr", relPath, types.URLParamPorterAppName),
  259. },
  260. Scopes: []types.PermissionScope{
  261. types.UserScope,
  262. types.ProjectScope,
  263. types.ClusterScope,
  264. },
  265. },
  266. )
  267. createSecretAndOpenGitHubPullRequestHandler := porter_app.NewOpenStackPRHandler(
  268. config,
  269. factory.GetDecoderValidator(),
  270. factory.GetResultWriter(),
  271. )
  272. routes = append(routes, &router.Route{
  273. Endpoint: createSecretAndOpenGitHubPullRequestEndpoint,
  274. Handler: createSecretAndOpenGitHubPullRequestHandler,
  275. Router: r,
  276. })
  277. // GET /api/projects/{project_id}/clusters/{cluster_id}/applications/{porter_app_name}/events -> porter_app.NewPorterAppEventListHandler
  278. listPorterAppEventsEndpoint := factory.NewAPIEndpoint(
  279. &types.APIRequestMetadata{
  280. Verb: types.APIVerbList,
  281. Method: types.HTTPVerbGet,
  282. Path: &types.Path{
  283. Parent: basePath,
  284. RelativePath: fmt.Sprintf("%s/{%s}/events", relPath, types.URLParamPorterAppName),
  285. },
  286. Scopes: []types.PermissionScope{
  287. types.UserScope,
  288. types.ProjectScope,
  289. types.ClusterScope,
  290. },
  291. },
  292. )
  293. listPorterAppEventsHandler := porter_app.NewPorterAppEventListHandler(
  294. config,
  295. factory.GetResultWriter(),
  296. )
  297. routes = append(routes, &router.Route{
  298. Endpoint: listPorterAppEventsEndpoint,
  299. Handler: listPorterAppEventsHandler,
  300. Router: r,
  301. })
  302. // POST /api/projects/{project_id}/clusters/{cluster_id}/applications/{name}/events -> porter_app.NewCreatePorterAppEventHandler
  303. createPorterAppEventEndpoint := factory.NewAPIEndpoint(
  304. &types.APIRequestMetadata{
  305. Verb: types.APIVerbCreate,
  306. Method: types.HTTPVerbPost,
  307. Path: &types.Path{
  308. Parent: basePath,
  309. RelativePath: fmt.Sprintf("%s/{%s}/events", relPath, types.URLParamPorterAppName),
  310. },
  311. Scopes: []types.PermissionScope{
  312. types.UserScope,
  313. types.ProjectScope,
  314. types.ClusterScope,
  315. },
  316. },
  317. )
  318. createPorterAppEventHandler := porter_app.NewCreateUpdatePorterAppEventHandler(
  319. config,
  320. factory.GetDecoderValidator(),
  321. factory.GetResultWriter(),
  322. )
  323. routes = append(routes, &router.Route{
  324. Endpoint: createPorterAppEventEndpoint,
  325. Handler: createPorterAppEventHandler,
  326. Router: r,
  327. })
  328. // GET /api/projects/{project_id}/clusters/{cluster_id}/events/id -> porter_app.NewGetPorterAppEventHandler
  329. getPorterAppEventEndpoint := factory.NewAPIEndpoint(
  330. &types.APIRequestMetadata{
  331. Verb: types.APIVerbCreate,
  332. Method: types.HTTPVerbGet,
  333. Path: &types.Path{
  334. Parent: basePath,
  335. RelativePath: fmt.Sprintf("/events/{%s}", types.URLParamPorterAppEventID),
  336. },
  337. Scopes: []types.PermissionScope{
  338. types.UserScope,
  339. types.ProjectScope,
  340. types.ClusterScope,
  341. },
  342. },
  343. )
  344. getPorterAppEventHandler := porter_app.NewGetPorterAppEventHandler(
  345. config,
  346. factory.GetResultWriter(),
  347. )
  348. routes = append(routes, &router.Route{
  349. Endpoint: getPorterAppEventEndpoint,
  350. Handler: getPorterAppEventHandler,
  351. Router: r,
  352. })
  353. // POST /api/projects/{project_id}/clusters/{cluster_id}/applications/analytics -> porter_app.NewPorterAppAnalyticsHandler
  354. porterAppAnalyticsEndpoint := factory.NewAPIEndpoint(
  355. &types.APIRequestMetadata{
  356. Verb: types.APIVerbUpdate,
  357. Method: types.HTTPVerbPost,
  358. Path: &types.Path{
  359. Parent: basePath,
  360. RelativePath: fmt.Sprintf("%s/analytics", relPath),
  361. },
  362. Scopes: []types.PermissionScope{
  363. types.UserScope,
  364. types.ProjectScope,
  365. types.ClusterScope,
  366. },
  367. },
  368. )
  369. porterAppAnalyticsHandler := porter_app.NewPorterAppAnalyticsHandler(
  370. config,
  371. factory.GetDecoderValidator(),
  372. factory.GetResultWriter(),
  373. )
  374. routes = append(routes, &router.Route{
  375. Endpoint: porterAppAnalyticsEndpoint,
  376. Handler: porterAppAnalyticsHandler,
  377. Router: r,
  378. })
  379. // GET /api/projects/{project_id}/clusters/{cluster_id}/applications/logs -> cluster.NewGetChartLogsWithinTimeRangeHandler
  380. getChartLogsWithinTimeRangeEndpoint := factory.NewAPIEndpoint(
  381. &types.APIRequestMetadata{
  382. Verb: types.APIVerbGet,
  383. Method: types.HTTPVerbGet,
  384. Path: &types.Path{
  385. Parent: basePath,
  386. RelativePath: fmt.Sprintf("%s/logs", relPath),
  387. },
  388. Scopes: []types.PermissionScope{
  389. types.UserScope,
  390. types.ProjectScope,
  391. types.ClusterScope,
  392. },
  393. },
  394. )
  395. getChartLogsWithinTimeRangeHandler := porter_app.NewGetLogsWithinTimeRangeHandler(
  396. config,
  397. factory.GetDecoderValidator(),
  398. factory.GetResultWriter(),
  399. )
  400. routes = append(routes, &router.Route{
  401. Endpoint: getChartLogsWithinTimeRangeEndpoint,
  402. Handler: getChartLogsWithinTimeRangeHandler,
  403. Router: r,
  404. })
  405. // POST /api/projects/{project_id}/clusters/{cluster_id}/applications/{porter_app_name}/run -> porter_app.NewRunPorterAppCommandHandler
  406. runPorterAppCommandEndpoint := factory.NewAPIEndpoint(
  407. &types.APIRequestMetadata{
  408. Verb: types.APIVerbCreate,
  409. Method: types.HTTPVerbPost,
  410. Path: &types.Path{
  411. Parent: basePath,
  412. RelativePath: fmt.Sprintf("%s/{%s}/run", relPath, types.URLParamPorterAppName),
  413. },
  414. Scopes: []types.PermissionScope{
  415. types.UserScope,
  416. types.ProjectScope,
  417. types.ClusterScope,
  418. },
  419. },
  420. )
  421. runPorterAppCommandHandler := porter_app.NewRunPorterAppCommandHandler(
  422. config,
  423. factory.GetDecoderValidator(),
  424. factory.GetResultWriter(),
  425. )
  426. routes = append(routes, &router.Route{
  427. Endpoint: runPorterAppCommandEndpoint,
  428. Handler: runPorterAppCommandHandler,
  429. Router: r,
  430. })
  431. // TODO: remove these three endpoints once these three 'stacks' routes are no longer used in telemetry
  432. // GET /api/projects/{project_id}/clusters/{cluster_id}/stacks/{name} -> porter_app.NewPorterAppGetHandler
  433. LEGACY_getPorterAppEndpoint := factory.NewAPIEndpoint(
  434. &types.APIRequestMetadata{
  435. Verb: types.APIVerbGet,
  436. Method: types.HTTPVerbGet,
  437. Path: &types.Path{
  438. Parent: basePath,
  439. RelativePath: fmt.Sprintf("/stacks/{%s}", types.URLParamPorterAppName),
  440. },
  441. Scopes: []types.PermissionScope{
  442. types.UserScope,
  443. types.ProjectScope,
  444. types.ClusterScope,
  445. },
  446. },
  447. )
  448. LEGACY_getPorterAppHandler := porter_app.NewGetPorterAppHandler(
  449. config,
  450. factory.GetResultWriter(),
  451. )
  452. routes = append(routes, &router.Route{
  453. Endpoint: LEGACY_getPorterAppEndpoint,
  454. Handler: LEGACY_getPorterAppHandler,
  455. Router: r,
  456. })
  457. // POST /api/projects/{project_id}/clusters/{cluster_id}/stacks/{porter_app_name} -> porter_app.NewCreatePorterAppHandler
  458. LEGACY_createPorterAppEndpoint := factory.NewAPIEndpoint(
  459. &types.APIRequestMetadata{
  460. Verb: types.APIVerbCreate,
  461. Method: types.HTTPVerbPost,
  462. Path: &types.Path{
  463. Parent: basePath,
  464. RelativePath: fmt.Sprintf("/stacks/{%s}", types.URLParamPorterAppName),
  465. },
  466. Scopes: []types.PermissionScope{
  467. types.UserScope,
  468. types.ProjectScope,
  469. types.ClusterScope,
  470. },
  471. },
  472. )
  473. LEGACY_createPorterAppHandler := porter_app.NewCreatePorterAppHandler(
  474. config,
  475. factory.GetDecoderValidator(),
  476. factory.GetResultWriter(),
  477. )
  478. routes = append(routes, &router.Route{
  479. Endpoint: LEGACY_createPorterAppEndpoint,
  480. Handler: LEGACY_createPorterAppHandler,
  481. Router: r,
  482. })
  483. // POST /api/projects/{project_id}/clusters/{cluster_id}/stacks/{name}/events -> porter_app.NewCreatePorterAppEventHandler
  484. LEGACY_createPorterAppEventEndpoint := 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}/events", types.URLParamPorterAppName),
  491. },
  492. Scopes: []types.PermissionScope{
  493. types.UserScope,
  494. types.ProjectScope,
  495. types.ClusterScope,
  496. },
  497. },
  498. )
  499. LEGACY_createPorterAppEventHandler := porter_app.NewCreateUpdatePorterAppEventHandler(
  500. config,
  501. factory.GetDecoderValidator(),
  502. factory.GetResultWriter(),
  503. )
  504. routes = append(routes, &router.Route{
  505. Endpoint: LEGACY_createPorterAppEventEndpoint,
  506. Handler: LEGACY_createPorterAppEventHandler,
  507. Router: r,
  508. })
  509. // POST /api/projects/{project_id}/clusters/{cluster_id}/apps/parse -> porter_app.NewParsePorterYAMLToProtoHandler
  510. parsePorterYAMLToProtoEndpoint := factory.NewAPIEndpoint(
  511. &types.APIRequestMetadata{
  512. Verb: types.APIVerbGet,
  513. Method: types.HTTPVerbPost,
  514. Path: &types.Path{
  515. Parent: basePath,
  516. RelativePath: fmt.Sprintf("%s/parse", relPathV2),
  517. },
  518. Scopes: []types.PermissionScope{
  519. types.UserScope,
  520. types.ProjectScope,
  521. types.ClusterScope,
  522. },
  523. },
  524. )
  525. parsePorterYAMLToProtoHandler := porter_app.NewParsePorterYAMLToProtoHandler(
  526. config,
  527. factory.GetDecoderValidator(),
  528. factory.GetResultWriter(),
  529. )
  530. routes = append(routes, &router.Route{
  531. Endpoint: parsePorterYAMLToProtoEndpoint,
  532. Handler: parsePorterYAMLToProtoHandler,
  533. Router: r,
  534. })
  535. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/revisions/{app_revision_id}/yaml -> porter_app.NewPorterYAMLFromRevisionHandler
  536. porterYAMLFromRevision := factory.NewAPIEndpoint(
  537. &types.APIRequestMetadata{
  538. Verb: types.APIVerbGet,
  539. Method: types.HTTPVerbGet,
  540. Path: &types.Path{
  541. Parent: basePath,
  542. RelativePath: fmt.Sprintf("%s/{%s}/revisions/{%s}/yaml", relPathV2, types.URLParamPorterAppName, types.URLParamAppRevisionID),
  543. },
  544. Scopes: []types.PermissionScope{
  545. types.UserScope,
  546. types.ProjectScope,
  547. types.ClusterScope,
  548. },
  549. },
  550. )
  551. porterYAMLFromRevisionHandler := porter_app.NewPorterYAMLFromRevisionHandler(
  552. config,
  553. factory.GetDecoderValidator(),
  554. factory.GetResultWriter(),
  555. )
  556. routes = append(routes, &router.Route{
  557. Endpoint: porterYAMLFromRevision,
  558. Handler: porterYAMLFromRevisionHandler,
  559. Router: r,
  560. })
  561. // POST /api/projects/{project_id}/clusters/{cluster_id}/apps/validate -> porter_app.NewValidatePorterAppHandler
  562. validatePorterAppEndpoint := factory.NewAPIEndpoint(
  563. &types.APIRequestMetadata{
  564. Verb: types.APIVerbGet,
  565. Method: types.HTTPVerbPost,
  566. Path: &types.Path{
  567. Parent: basePath,
  568. RelativePath: fmt.Sprintf("%s/validate", relPathV2),
  569. },
  570. Scopes: []types.PermissionScope{
  571. types.UserScope,
  572. types.ProjectScope,
  573. types.ClusterScope,
  574. },
  575. },
  576. )
  577. validatePorterAppHandler := porter_app.NewValidatePorterAppHandler(
  578. config,
  579. factory.GetDecoderValidator(),
  580. factory.GetResultWriter(),
  581. )
  582. routes = append(routes, &router.Route{
  583. Endpoint: validatePorterAppEndpoint,
  584. Handler: validatePorterAppHandler,
  585. Router: r,
  586. })
  587. // POST /api/projects/{project_id}/clusters/{cluster_id}/apps/create -> porter_app.NewCreateAppHandler
  588. createAppEndpoint := factory.NewAPIEndpoint(
  589. &types.APIRequestMetadata{
  590. Verb: types.APIVerbCreate,
  591. Method: types.HTTPVerbPost,
  592. Path: &types.Path{
  593. Parent: basePath,
  594. RelativePath: fmt.Sprintf("%s/create", relPathV2),
  595. },
  596. Scopes: []types.PermissionScope{
  597. types.UserScope,
  598. types.ProjectScope,
  599. types.ClusterScope,
  600. },
  601. },
  602. )
  603. createAppHandler := porter_app.NewCreateAppHandler(
  604. config,
  605. factory.GetDecoderValidator(),
  606. factory.GetResultWriter(),
  607. )
  608. routes = append(routes, &router.Route{
  609. Endpoint: createAppEndpoint,
  610. Handler: createAppHandler,
  611. Router: r,
  612. })
  613. // POST /api/projects/{project_id}/clusters/{cluster_id}/apps/apply -> porter_app.NewApplyPorterAppHandler
  614. applyPorterAppEndpoint := factory.NewAPIEndpoint(
  615. &types.APIRequestMetadata{
  616. Verb: types.APIVerbUpdate,
  617. Method: types.HTTPVerbPost,
  618. Path: &types.Path{
  619. Parent: basePath,
  620. RelativePath: fmt.Sprintf("%s/apply", relPathV2),
  621. },
  622. Scopes: []types.PermissionScope{
  623. types.UserScope,
  624. types.ProjectScope,
  625. types.ClusterScope,
  626. },
  627. },
  628. )
  629. applyPorterAppHandler := porter_app.NewApplyPorterAppHandler(
  630. config,
  631. factory.GetDecoderValidator(),
  632. factory.GetResultWriter(),
  633. )
  634. routes = append(routes, &router.Route{
  635. Endpoint: applyPorterAppEndpoint,
  636. Handler: applyPorterAppHandler,
  637. Router: r,
  638. })
  639. // POST /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/rollback -> porter_app.NewRollbackAppRevisionHandler
  640. rollbackAppRevisionEndpoint := factory.NewAPIEndpoint(
  641. &types.APIRequestMetadata{
  642. Verb: types.APIVerbUpdate,
  643. Method: types.HTTPVerbPost,
  644. Path: &types.Path{
  645. Parent: basePath,
  646. RelativePath: fmt.Sprintf("%s/{%s}/rollback", relPathV2, types.URLParamPorterAppName),
  647. },
  648. Scopes: []types.PermissionScope{
  649. types.UserScope,
  650. types.ProjectScope,
  651. types.ClusterScope,
  652. },
  653. },
  654. )
  655. rollbackAppRevisionHandler := porter_app.NewRollbackAppRevisionHandler(
  656. config,
  657. factory.GetDecoderValidator(),
  658. factory.GetResultWriter(),
  659. )
  660. routes = append(routes, &router.Route{
  661. Endpoint: rollbackAppRevisionEndpoint,
  662. Handler: rollbackAppRevisionHandler,
  663. Router: r,
  664. })
  665. // POST /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/update-image -> porter_app.NewUpdateImageHandler
  666. updatePorterAppImageEndpoint := 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/{%s}/update-image", relPathV2, types.URLParamPorterAppName),
  673. },
  674. Scopes: []types.PermissionScope{
  675. types.UserScope,
  676. types.ProjectScope,
  677. types.ClusterScope,
  678. },
  679. },
  680. )
  681. updatePorterAppImageHandler := porter_app.NewUpdateImageHandler(
  682. config,
  683. factory.GetDecoderValidator(),
  684. factory.GetResultWriter(),
  685. )
  686. routes = append(routes, &router.Route{
  687. Endpoint: updatePorterAppImageEndpoint,
  688. Handler: updatePorterAppImageHandler,
  689. Router: r,
  690. })
  691. // GET /api/projects/{project_id}/clusters/{cluster_id}/default-deployment-target -> porter_app.NewDefaultDeploymentTargetHandler
  692. defaultDeploymentTargetEndpoint := factory.NewAPIEndpoint(
  693. &types.APIRequestMetadata{
  694. Verb: types.APIVerbGet,
  695. Method: types.HTTPVerbGet,
  696. Path: &types.Path{
  697. Parent: basePath,
  698. RelativePath: "/default-deployment-target",
  699. },
  700. Scopes: []types.PermissionScope{
  701. types.UserScope,
  702. types.ProjectScope,
  703. types.ClusterScope,
  704. },
  705. },
  706. )
  707. defaultDeploymentTargetHandler := porter_app.NewDefaultDeploymentTargetHandler(
  708. config,
  709. factory.GetDecoderValidator(),
  710. factory.GetResultWriter(),
  711. )
  712. routes = append(routes, &router.Route{
  713. Endpoint: defaultDeploymentTargetEndpoint,
  714. Handler: defaultDeploymentTargetHandler,
  715. Router: r,
  716. })
  717. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/latest -> porter_app.NewCurrentAppRevisionHandler
  718. currentAppRevisionEndpoint := factory.NewAPIEndpoint(
  719. &types.APIRequestMetadata{
  720. Verb: types.APIVerbGet,
  721. Method: types.HTTPVerbGet,
  722. Path: &types.Path{
  723. Parent: basePath,
  724. RelativePath: fmt.Sprintf("%s/{%s}/latest", relPathV2, types.URLParamPorterAppName),
  725. },
  726. Scopes: []types.PermissionScope{
  727. types.UserScope,
  728. types.ProjectScope,
  729. types.ClusterScope,
  730. },
  731. },
  732. )
  733. currentAppRevisionHandler := porter_app.NewLatestAppRevisionHandler(
  734. config,
  735. factory.GetDecoderValidator(),
  736. factory.GetResultWriter(),
  737. )
  738. routes = append(routes, &router.Route{
  739. Endpoint: currentAppRevisionEndpoint,
  740. Handler: currentAppRevisionHandler,
  741. Router: r,
  742. })
  743. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/revisions -> porter_app.NewCurrentAppRevisionHandler
  744. listAppRevisionsEndpoint := factory.NewAPIEndpoint(
  745. &types.APIRequestMetadata{
  746. Verb: types.APIVerbGet,
  747. Method: types.HTTPVerbGet,
  748. Path: &types.Path{
  749. Parent: basePath,
  750. RelativePath: fmt.Sprintf("%s/{%s}/revisions", relPathV2, types.URLParamPorterAppName),
  751. },
  752. Scopes: []types.PermissionScope{
  753. types.UserScope,
  754. types.ProjectScope,
  755. types.ClusterScope,
  756. },
  757. },
  758. )
  759. listAppRevisionsHandler := porter_app.NewListAppRevisionsHandler(
  760. config,
  761. factory.GetDecoderValidator(),
  762. factory.GetResultWriter(),
  763. )
  764. routes = append(routes, &router.Route{
  765. Endpoint: listAppRevisionsEndpoint,
  766. Handler: listAppRevisionsHandler,
  767. Router: r,
  768. })
  769. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/revisions -> porter_app.NewCurrentAppRevisionHandler
  770. latestAppRevisionsEndpoint := 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/revisions", relPathV2),
  777. },
  778. Scopes: []types.PermissionScope{
  779. types.UserScope,
  780. types.ProjectScope,
  781. types.ClusterScope,
  782. },
  783. },
  784. )
  785. latestAppRevisionsHandler := porter_app.NewLatestAppRevisionsHandler(
  786. config,
  787. factory.GetDecoderValidator(),
  788. factory.GetResultWriter(),
  789. )
  790. routes = append(routes, &router.Route{
  791. Endpoint: latestAppRevisionsEndpoint,
  792. Handler: latestAppRevisionsHandler,
  793. Router: r,
  794. })
  795. // POST /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/subdomain -> porter_app.NewCreateSubdomainHandler
  796. createSubdomainEndpoint := factory.NewAPIEndpoint(
  797. &types.APIRequestMetadata{
  798. Verb: types.APIVerbUpdate,
  799. Method: types.HTTPVerbPost,
  800. Path: &types.Path{
  801. Parent: basePath,
  802. RelativePath: fmt.Sprintf("%s/{%s}/subdomain", relPathV2, types.URLParamPorterAppName),
  803. },
  804. Scopes: []types.PermissionScope{
  805. types.UserScope,
  806. types.ProjectScope,
  807. types.ClusterScope,
  808. },
  809. },
  810. )
  811. createSubdomainHandler := porter_app.NewCreateSubdomainHandler(
  812. config,
  813. factory.GetDecoderValidator(),
  814. factory.GetResultWriter(),
  815. )
  816. routes = append(routes, &router.Route{
  817. Endpoint: createSubdomainEndpoint,
  818. Handler: createSubdomainHandler,
  819. Router: r,
  820. })
  821. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/{app_revision_id}/predeploy-status -> porter_app.NewPredeployStatusHandler
  822. predeployStatusEndpoint := 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}/{%s}/predeploy-status", relPathV2, types.URLParamPorterAppName, types.URLParamAppRevisionID),
  829. },
  830. Scopes: []types.PermissionScope{
  831. types.UserScope,
  832. types.ProjectScope,
  833. types.ClusterScope,
  834. },
  835. },
  836. )
  837. predeployStatusHandler := porter_app.NewPredeployStatusHandler(
  838. config,
  839. factory.GetDecoderValidator(),
  840. factory.GetResultWriter(),
  841. )
  842. routes = append(routes, &router.Route{
  843. Endpoint: predeployStatusEndpoint,
  844. Handler: predeployStatusHandler,
  845. Router: r,
  846. })
  847. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/logs -> cluster.NewAppLogsHandler
  848. appLogsEndpoint := factory.NewAPIEndpoint(
  849. &types.APIRequestMetadata{
  850. Verb: types.APIVerbGet,
  851. Method: types.HTTPVerbGet,
  852. Path: &types.Path{
  853. Parent: basePath,
  854. RelativePath: fmt.Sprintf("%s/{%s}/logs", relPathV2, types.URLParamPorterAppName),
  855. },
  856. Scopes: []types.PermissionScope{
  857. types.UserScope,
  858. types.ProjectScope,
  859. types.ClusterScope,
  860. },
  861. },
  862. )
  863. appLogsHandler := porter_app.NewAppLogsHandler(
  864. config,
  865. factory.GetDecoderValidator(),
  866. factory.GetResultWriter(),
  867. )
  868. routes = append(routes, &router.Route{
  869. Endpoint: appLogsEndpoint,
  870. Handler: appLogsHandler,
  871. Router: r,
  872. })
  873. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/logs/loki -> namespace.NewStreamLogsLokiHandler
  874. streamLogsLokiEndpoint := factory.NewAPIEndpoint(
  875. &types.APIRequestMetadata{
  876. Verb: types.APIVerbGet,
  877. Method: types.HTTPVerbGet,
  878. Path: &types.Path{
  879. Parent: basePath,
  880. RelativePath: fmt.Sprintf("%s/{%s}/logs/loki", relPathV2, types.URLParamPorterAppName),
  881. },
  882. Scopes: []types.PermissionScope{
  883. types.UserScope,
  884. types.ProjectScope,
  885. types.ClusterScope,
  886. },
  887. IsWebsocket: true,
  888. },
  889. )
  890. streamLogsLokiHandler := porter_app.NewStreamLogsLokiHandler(
  891. config,
  892. factory.GetDecoderValidator(),
  893. factory.GetResultWriter(),
  894. )
  895. routes = append(routes, &router.Route{
  896. Endpoint: streamLogsLokiEndpoint,
  897. Handler: streamLogsLokiHandler,
  898. Router: r,
  899. })
  900. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/metrics -> cluster.NewGetPodMetricsHandler
  901. appMetricsEndpoint := 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/metrics", relPathV2),
  908. },
  909. Scopes: []types.PermissionScope{
  910. types.UserScope,
  911. types.ProjectScope,
  912. types.ClusterScope,
  913. },
  914. },
  915. )
  916. appMetricsHandler := porter_app.NewAppMetricsHandler(
  917. config,
  918. factory.GetDecoderValidator(),
  919. factory.GetResultWriter(),
  920. )
  921. routes = append(routes, &router.Route{
  922. Endpoint: appMetricsEndpoint,
  923. Handler: appMetricsHandler,
  924. Router: r,
  925. })
  926. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/status -> cluster.NewAppStatusHandler
  927. appStatusEndpoint := factory.NewAPIEndpoint(
  928. &types.APIRequestMetadata{
  929. Verb: types.APIVerbGet,
  930. Method: types.HTTPVerbGet,
  931. Path: &types.Path{
  932. Parent: basePath,
  933. RelativePath: fmt.Sprintf("%s/{%s}/status", relPathV2, types.URLParamKind),
  934. },
  935. Scopes: []types.PermissionScope{
  936. types.UserScope,
  937. types.ProjectScope,
  938. types.ClusterScope,
  939. },
  940. IsWebsocket: true,
  941. },
  942. )
  943. appStatusHandler := porter_app.NewAppStatusHandler(
  944. config,
  945. factory.GetDecoderValidator(),
  946. factory.GetResultWriter(),
  947. )
  948. routes = append(routes, &router.Route{
  949. Endpoint: appStatusEndpoint,
  950. Handler: appStatusHandler,
  951. Router: r,
  952. })
  953. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/pods -> cluster.NewPodStatusHandler
  954. appPodStatusEndpoint := factory.NewAPIEndpoint(
  955. &types.APIRequestMetadata{
  956. Verb: types.APIVerbGet,
  957. Method: types.HTTPVerbGet,
  958. Path: &types.Path{
  959. Parent: basePath,
  960. RelativePath: fmt.Sprintf("%s/{%s}/pods", relPathV2, types.URLParamPorterAppName),
  961. },
  962. Scopes: []types.PermissionScope{
  963. types.UserScope,
  964. types.ProjectScope,
  965. types.ClusterScope,
  966. },
  967. },
  968. )
  969. appPodStatusHandler := porter_app.NewPodStatusHandler(
  970. config,
  971. factory.GetDecoderValidator(),
  972. factory.GetResultWriter(),
  973. )
  974. routes = append(routes, &router.Route{
  975. Endpoint: appPodStatusEndpoint,
  976. Handler: appPodStatusHandler,
  977. Router: r,
  978. })
  979. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/jobs -> cluster.NewJobStatusHandler
  980. appJobStatusEndpoint := factory.NewAPIEndpoint(
  981. &types.APIRequestMetadata{
  982. Verb: types.APIVerbGet,
  983. Method: types.HTTPVerbGet,
  984. Path: &types.Path{
  985. Parent: basePath,
  986. RelativePath: fmt.Sprintf("%s/{%s}/jobs", relPathV2, types.URLParamPorterAppName),
  987. },
  988. Scopes: []types.PermissionScope{
  989. types.UserScope,
  990. types.ProjectScope,
  991. types.ClusterScope,
  992. },
  993. },
  994. )
  995. appJobStatusHandler := porter_app.NewJobStatusHandler(
  996. config,
  997. factory.GetDecoderValidator(),
  998. factory.GetResultWriter(),
  999. )
  1000. routes = append(routes, &router.Route{
  1001. Endpoint: appJobStatusEndpoint,
  1002. Handler: appJobStatusHandler,
  1003. Router: r,
  1004. })
  1005. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/revisions/{app_revision_id} -> porter_app.NewGetAppRevisionHandler
  1006. getAppRevisionEndpoint := factory.NewAPIEndpoint(
  1007. &types.APIRequestMetadata{
  1008. Verb: types.APIVerbGet,
  1009. Method: types.HTTPVerbGet,
  1010. Path: &types.Path{
  1011. Parent: basePath,
  1012. RelativePath: fmt.Sprintf("/apps/{%s}/revisions/{%s}", types.URLParamPorterAppName, types.URLParamAppRevisionID),
  1013. },
  1014. Scopes: []types.PermissionScope{
  1015. types.UserScope,
  1016. types.ProjectScope,
  1017. types.ClusterScope,
  1018. },
  1019. },
  1020. )
  1021. getAppRevisionHandler := porter_app.NewGetAppRevisionHandler(
  1022. config,
  1023. factory.GetDecoderValidator(),
  1024. factory.GetResultWriter(),
  1025. )
  1026. routes = append(routes, &router.Route{
  1027. Endpoint: getAppRevisionEndpoint,
  1028. Handler: getAppRevisionHandler,
  1029. Router: r,
  1030. })
  1031. // POST /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/revisions/{app_revision_id} -> porter_app.NewUpdateAppRevisionStatusHandler
  1032. updateAppRevisionStatusEndpoint := factory.NewAPIEndpoint(
  1033. &types.APIRequestMetadata{
  1034. Verb: types.APIVerbUpdate,
  1035. Method: types.HTTPVerbPost,
  1036. Path: &types.Path{
  1037. Parent: basePath,
  1038. RelativePath: fmt.Sprintf("/apps/{%s}/revisions/{%s}", types.URLParamPorterAppName, types.URLParamAppRevisionID),
  1039. },
  1040. Scopes: []types.PermissionScope{
  1041. types.UserScope,
  1042. types.ProjectScope,
  1043. types.ClusterScope,
  1044. },
  1045. },
  1046. )
  1047. updateAppRevisionStatusHandler := porter_app.NewUpdateAppRevisionStatusHandler(
  1048. config,
  1049. factory.GetDecoderValidator(),
  1050. factory.GetResultWriter(),
  1051. )
  1052. routes = append(routes, &router.Route{
  1053. Endpoint: updateAppRevisionStatusEndpoint,
  1054. Handler: updateAppRevisionStatusHandler,
  1055. Router: r,
  1056. })
  1057. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/revisions/{app_revision_id}/build-env -> porter_app.NewGetBuildEnvHandler
  1058. getBuildEnvEndpoint := factory.NewAPIEndpoint(
  1059. &types.APIRequestMetadata{
  1060. Verb: types.APIVerbGet,
  1061. Method: types.HTTPVerbGet,
  1062. Path: &types.Path{
  1063. Parent: basePath,
  1064. RelativePath: fmt.Sprintf("/apps/{%s}/revisions/{%s}/build-env", types.URLParamPorterAppName, types.URLParamAppRevisionID),
  1065. },
  1066. Scopes: []types.PermissionScope{
  1067. types.UserScope,
  1068. types.ProjectScope,
  1069. types.ClusterScope,
  1070. },
  1071. },
  1072. )
  1073. getBuildEnvHandler := porter_app.NewGetBuildEnvHandler(
  1074. config,
  1075. factory.GetDecoderValidator(),
  1076. factory.GetResultWriter(),
  1077. )
  1078. routes = append(routes, &router.Route{
  1079. Endpoint: getBuildEnvEndpoint,
  1080. Handler: getBuildEnvHandler,
  1081. Router: r,
  1082. })
  1083. // POST /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/revisions/{app_revision_id}/status -> porter_app.NewReportRevisionStatusHandler
  1084. reportRevisionStatusEndpoint := factory.NewAPIEndpoint(
  1085. &types.APIRequestMetadata{
  1086. Verb: types.APIVerbUpdate,
  1087. Method: types.HTTPVerbPost,
  1088. Path: &types.Path{
  1089. Parent: basePath,
  1090. RelativePath: fmt.Sprintf("/apps/{%s}/revisions/{%s}/status", types.URLParamPorterAppName, types.URLParamAppRevisionID),
  1091. },
  1092. Scopes: []types.PermissionScope{
  1093. types.UserScope,
  1094. types.ProjectScope,
  1095. types.ClusterScope,
  1096. },
  1097. },
  1098. )
  1099. reportRevisionStatusHandler := porter_app.NewReportRevisionStatusHandler(
  1100. config,
  1101. factory.GetDecoderValidator(),
  1102. factory.GetResultWriter(),
  1103. )
  1104. routes = append(routes, &router.Route{
  1105. Endpoint: reportRevisionStatusEndpoint,
  1106. Handler: reportRevisionStatusHandler,
  1107. Router: r,
  1108. })
  1109. // POST /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/update-environment -> porter_app.NewUpdateAppEnvironmentHandler
  1110. updateAppEnvironmentGroupEndpoint := factory.NewAPIEndpoint(
  1111. &types.APIRequestMetadata{
  1112. Verb: types.APIVerbUpdate,
  1113. Method: types.HTTPVerbPost,
  1114. Path: &types.Path{
  1115. Parent: basePath,
  1116. RelativePath: fmt.Sprintf("/apps/{%s}/update-environment", types.URLParamPorterAppName),
  1117. },
  1118. Scopes: []types.PermissionScope{
  1119. types.UserScope,
  1120. types.ProjectScope,
  1121. types.ClusterScope,
  1122. },
  1123. },
  1124. )
  1125. updateAppEnvironmentGroupHandler := porter_app.NewUpdateAppEnvironmentHandler(
  1126. config,
  1127. factory.GetDecoderValidator(),
  1128. factory.GetResultWriter(),
  1129. )
  1130. routes = append(routes, &router.Route{
  1131. Endpoint: updateAppEnvironmentGroupEndpoint,
  1132. Handler: updateAppEnvironmentGroupHandler,
  1133. Router: r,
  1134. })
  1135. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/revisions/{app_revision_id}/env -> porter_app.NewGetAppEnvHandler
  1136. getAppEnvEndpoint := factory.NewAPIEndpoint(
  1137. &types.APIRequestMetadata{
  1138. Verb: types.APIVerbGet,
  1139. Method: types.HTTPVerbGet,
  1140. Path: &types.Path{
  1141. Parent: basePath,
  1142. RelativePath: fmt.Sprintf("/apps/{%s}/revisions/{%s}/env", types.URLParamPorterAppName, types.URLParamAppRevisionID),
  1143. },
  1144. Scopes: []types.PermissionScope{
  1145. types.UserScope,
  1146. types.ProjectScope,
  1147. types.ClusterScope,
  1148. },
  1149. },
  1150. )
  1151. getAppEnvHandler := porter_app.NewGetAppEnvHandler(
  1152. config,
  1153. factory.GetDecoderValidator(),
  1154. factory.GetResultWriter(),
  1155. )
  1156. routes = append(routes, &router.Route{
  1157. Endpoint: getAppEnvEndpoint,
  1158. Handler: getAppEnvHandler,
  1159. Router: r,
  1160. })
  1161. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/events -> porter_app.NewPorterAppV2EventListHandler
  1162. listPorterAppV2EventsEndpoint := factory.NewAPIEndpoint(
  1163. &types.APIRequestMetadata{
  1164. Verb: types.APIVerbList,
  1165. Method: types.HTTPVerbGet,
  1166. Path: &types.Path{
  1167. Parent: basePath,
  1168. RelativePath: fmt.Sprintf("%s/{%s}/events", relPathV2, types.URLParamPorterAppName),
  1169. },
  1170. Scopes: []types.PermissionScope{
  1171. types.UserScope,
  1172. types.ProjectScope,
  1173. types.ClusterScope,
  1174. },
  1175. },
  1176. )
  1177. listPorterAppV2EventsHandler := porter_app.NewPorterAppV2EventListHandler(
  1178. config,
  1179. factory.GetDecoderValidator(),
  1180. factory.GetResultWriter(),
  1181. )
  1182. routes = append(routes, &router.Route{
  1183. Endpoint: listPorterAppV2EventsEndpoint,
  1184. Handler: listPorterAppV2EventsHandler,
  1185. Router: r,
  1186. })
  1187. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/templates -> porter_app.NewGetAppTemplateHandler
  1188. getAppTemplateEndpoint := factory.NewAPIEndpoint(
  1189. &types.APIRequestMetadata{
  1190. Verb: types.APIVerbGet,
  1191. Method: types.HTTPVerbGet,
  1192. Path: &types.Path{
  1193. Parent: basePath,
  1194. RelativePath: fmt.Sprintf("%s/{%s}/templates", relPathV2, types.URLParamPorterAppName),
  1195. },
  1196. Scopes: []types.PermissionScope{
  1197. types.UserScope,
  1198. types.ProjectScope,
  1199. types.ClusterScope,
  1200. },
  1201. },
  1202. )
  1203. getAppTemplateHandler := porter_app.NewGetAppTemplateHandler(
  1204. config,
  1205. factory.GetDecoderValidator(),
  1206. factory.GetResultWriter(),
  1207. )
  1208. routes = append(routes, &router.Route{
  1209. Endpoint: getAppTemplateEndpoint,
  1210. Handler: getAppTemplateHandler,
  1211. Router: r,
  1212. })
  1213. // POST /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/templates -> porter_app.NewCreateAppTemplateHandler
  1214. createAppTemplateEndpoint := factory.NewAPIEndpoint(
  1215. &types.APIRequestMetadata{
  1216. Verb: types.APIVerbCreate,
  1217. Method: types.HTTPVerbPost,
  1218. Path: &types.Path{
  1219. Parent: basePath,
  1220. RelativePath: fmt.Sprintf("%s/{%s}/templates", relPathV2, types.URLParamPorterAppName),
  1221. },
  1222. Scopes: []types.PermissionScope{
  1223. types.UserScope,
  1224. types.ProjectScope,
  1225. types.ClusterScope,
  1226. },
  1227. },
  1228. )
  1229. createAppTemplateHandler := porter_app.NewCreateAppTemplateHandler(
  1230. config,
  1231. factory.GetDecoderValidator(),
  1232. factory.GetResultWriter(),
  1233. )
  1234. routes = append(routes, &router.Route{
  1235. Endpoint: createAppTemplateEndpoint,
  1236. Handler: createAppTemplateHandler,
  1237. Router: r,
  1238. })
  1239. // GET /api/projects/{project_id}/clusters/{cluster_id}/apps/{porter_app_name}/helm-values -> porter_app.NewAppHelmValuesHandler
  1240. appHelmValuesEndpoint := factory.NewAPIEndpoint(
  1241. &types.APIRequestMetadata{
  1242. Verb: types.APIVerbGet,
  1243. Method: types.HTTPVerbGet,
  1244. Path: &types.Path{
  1245. Parent: basePath,
  1246. RelativePath: fmt.Sprintf("%s/{%s}/helm-values", relPathV2, types.URLParamPorterAppName),
  1247. },
  1248. Scopes: []types.PermissionScope{
  1249. types.UserScope,
  1250. types.ProjectScope,
  1251. types.ClusterScope,
  1252. },
  1253. },
  1254. )
  1255. appHelmValuesHandler := porter_app.NewAppHelmValuesHandler(
  1256. config,
  1257. factory.GetDecoderValidator(),
  1258. factory.GetResultWriter(),
  1259. )
  1260. routes = append(routes, &router.Route{
  1261. Endpoint: appHelmValuesEndpoint,
  1262. Handler: appHelmValuesHandler,
  1263. Router: r,
  1264. })
  1265. return routes, newPath
  1266. }