api.tsx 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330
  1. import { baseApi } from "./baseApi";
  2. import { FullActionConfigType, StorageType } from "./types";
  3. /**
  4. * Generic api call format
  5. * @param {string} token - Bearer token.
  6. * @param {Object} params - Body params.
  7. * @param {Object} pathParams - Path params.
  8. * @param {(err: Object, res: Object) => void} callback - Callback function.
  9. */
  10. const checkAuth = baseApi("GET", "/api/users/current");
  11. const connectECRRegistry = baseApi<
  12. {
  13. name: string;
  14. aws_integration_id: string;
  15. },
  16. { id: number }
  17. >("POST", (pathParams) => {
  18. return `/api/projects/${pathParams.id}/registries`;
  19. });
  20. const connectGCRRegistry = baseApi<
  21. {
  22. name: string;
  23. gcp_integration_id: string;
  24. url: string;
  25. },
  26. { id: number }
  27. >("POST", (pathParams) => {
  28. return `/api/projects/${pathParams.id}/registries`;
  29. });
  30. const connectDORegistry = baseApi<
  31. {
  32. name: string;
  33. do_integration_id: string;
  34. url: string;
  35. },
  36. { project_id: number }
  37. >("POST", (pathParams) => {
  38. return `/api/projects/${pathParams.project_id}/registries`;
  39. });
  40. const getAWSIntegration = baseApi<{}, { project_id: number }>(
  41. "GET",
  42. ({ project_id }) => `/api/projects/${project_id}/integrations/aws`
  43. );
  44. const getGCPIntegration = baseApi<{}, { project_id: number }>(
  45. "GET",
  46. ({ project_id }) => `/api/projects/${project_id}/integrations/gcp`
  47. );
  48. const createAWSIntegration = baseApi<
  49. {
  50. aws_region: string;
  51. aws_cluster_id?: string;
  52. aws_access_key_id: string;
  53. aws_secret_access_key: string;
  54. },
  55. { id: number }
  56. >("POST", (pathParams) => {
  57. return `/api/projects/${pathParams.id}/integrations/aws`;
  58. });
  59. const overwriteAWSIntegration = baseApi<
  60. {
  61. aws_integration_id: number;
  62. aws_access_key_id: string;
  63. aws_secret_access_key: string;
  64. cluster_id: number;
  65. },
  66. {
  67. project_id: number;
  68. }
  69. >("POST", (pathParams) => {
  70. return `/api/projects/${pathParams.project_id}/integrations/aws/overwrite`;
  71. });
  72. const createDOCR = baseApi<
  73. {
  74. do_integration_id: number;
  75. docr_name: string;
  76. docr_subscription_tier: string;
  77. },
  78. {
  79. project_id: number;
  80. }
  81. >("POST", (pathParams) => {
  82. return `/api/projects/${pathParams.project_id}/provision/docr`;
  83. });
  84. const createDOKS = baseApi<
  85. {
  86. do_integration_id: number;
  87. doks_name: string;
  88. do_region: string;
  89. issuer_email: string;
  90. },
  91. {
  92. project_id: number;
  93. }
  94. >("POST", (pathParams) => {
  95. return `/api/projects/${pathParams.project_id}/provision/doks`;
  96. });
  97. const createEmailVerification = baseApi<{}, {}>("POST", (pathParams) => {
  98. return `/api/email/verify/initiate`;
  99. });
  100. const createGCPIntegration = baseApi<
  101. {
  102. gcp_key_data: string;
  103. gcp_project_id: string;
  104. },
  105. {
  106. project_id: number;
  107. }
  108. >("POST", (pathParams) => {
  109. return `/api/projects/${pathParams.project_id}/integrations/gcp`;
  110. });
  111. const createGCR = baseApi<
  112. {
  113. gcp_integration_id: number;
  114. },
  115. {
  116. project_id: number;
  117. }
  118. >("POST", (pathParams) => {
  119. return `/api/projects/${pathParams.project_id}/provision/gcr`;
  120. });
  121. const createGKE = baseApi<
  122. {
  123. gcp_region: string;
  124. gcp_integration_id: number;
  125. gke_name: string;
  126. issuer_email: string;
  127. },
  128. {
  129. project_id: number;
  130. }
  131. >("POST", (pathParams) => {
  132. return `/api/projects/${pathParams.project_id}/provision/gke`;
  133. });
  134. const createInvite = baseApi<
  135. {
  136. email: string;
  137. kind: string;
  138. },
  139. {
  140. id: number;
  141. }
  142. >("POST", (pathParams) => {
  143. return `/api/projects/${pathParams.id}/invites`;
  144. });
  145. const createPasswordReset = baseApi<
  146. {
  147. email: string;
  148. },
  149. {}
  150. >("POST", (pathParams) => {
  151. return `/api/password/reset/initiate`;
  152. });
  153. const createPasswordResetVerify = baseApi<
  154. {
  155. email: string;
  156. token: string;
  157. token_id: number;
  158. },
  159. {}
  160. >("POST", (pathParams) => {
  161. return `/api/password/reset/verify`;
  162. });
  163. const createPasswordResetFinalize = baseApi<
  164. {
  165. email: string;
  166. token: string;
  167. token_id: number;
  168. new_password: string;
  169. },
  170. {}
  171. >("POST", (pathParams) => {
  172. return `/api/password/reset/finalize`;
  173. });
  174. const createProject = baseApi<{ name: string }, {}>("POST", (pathParams) => {
  175. return `/api/projects`;
  176. });
  177. const createSubdomain = baseApi<
  178. {},
  179. {
  180. id: number;
  181. release_name: string;
  182. namespace: string;
  183. cluster_id: number;
  184. }
  185. >("POST", (pathParams) => {
  186. let { cluster_id, id, namespace, release_name } = pathParams;
  187. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/releases/${release_name}/subdomain`;
  188. });
  189. const deleteCluster = baseApi<
  190. {},
  191. {
  192. project_id: number;
  193. cluster_id: number;
  194. }
  195. >("DELETE", (pathParams) => {
  196. return `/api/projects/${pathParams.project_id}/clusters/${pathParams.cluster_id}`;
  197. });
  198. const deleteInvite = baseApi<{}, { id: number; invId: number }>(
  199. "DELETE",
  200. (pathParams) => {
  201. return `/api/projects/${pathParams.id}/invites/${pathParams.invId}`;
  202. }
  203. );
  204. const deletePod = baseApi<
  205. {},
  206. { name: string; namespace: string; id: number; cluster_id: number }
  207. >("DELETE", (pathParams) => {
  208. let { id, name, cluster_id, namespace } = pathParams;
  209. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/pods/${name}`;
  210. });
  211. const getPodEvents = baseApi<
  212. {},
  213. { name: string; namespace: string; id: number; cluster_id: number }
  214. >("GET", (pathParams) => {
  215. let { id, name, cluster_id, namespace } = pathParams;
  216. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/pods/${name}/events`;
  217. });
  218. const deleteProject = baseApi<{}, { id: number }>("DELETE", (pathParams) => {
  219. return `/api/projects/${pathParams.id}`;
  220. });
  221. const deleteRegistryIntegration = baseApi<
  222. {},
  223. {
  224. project_id: number;
  225. registry_id: number;
  226. }
  227. >("DELETE", (pathParams) => {
  228. return `/api/projects/${pathParams.project_id}/registries/${pathParams.registry_id}`;
  229. });
  230. const deleteSlackIntegration = baseApi<
  231. {},
  232. {
  233. project_id: number;
  234. slack_integration_id: number;
  235. }
  236. >("DELETE", (pathParams) => {
  237. return `/api/projects/${pathParams.project_id}/slack_integrations/${pathParams.slack_integration_id}`;
  238. });
  239. const updateNotificationConfig = baseApi<
  240. {
  241. payload: any;
  242. },
  243. {
  244. project_id: number;
  245. cluster_id: number;
  246. namespace: string;
  247. name: string;
  248. }
  249. >("POST", (pathParams) => {
  250. let { project_id, cluster_id, namespace, name } = pathParams;
  251. return `/api/projects/${project_id}/clusters/${cluster_id}/namespaces/${namespace}/releases/${name}/notifications`;
  252. });
  253. const getNotificationConfig = baseApi<
  254. {},
  255. {
  256. project_id: number;
  257. cluster_id: number;
  258. namespace: string;
  259. name: string;
  260. }
  261. >("GET", (pathParams) => {
  262. let { project_id, cluster_id, namespace, name } = pathParams;
  263. return `/api/projects/${project_id}/clusters/${cluster_id}/namespaces/${namespace}/releases/${name}/notifications`;
  264. });
  265. const getGHAWorkflowTemplate = baseApi<
  266. {
  267. release_name: string;
  268. github_action_config: FullActionConfigType;
  269. },
  270. {
  271. cluster_id: number;
  272. project_id: number;
  273. namespace: string;
  274. }
  275. >("POST", (pathParams) => {
  276. const { cluster_id, project_id, namespace } = pathParams;
  277. return `/api/projects/${project_id}/clusters/${cluster_id}/namespaces/${namespace}/releases/gha_template`;
  278. });
  279. const deployTemplate = baseApi<
  280. {
  281. template_name: string;
  282. template_version: string;
  283. image_url?: string;
  284. values?: any;
  285. name: string;
  286. github_action_config?: FullActionConfigType;
  287. },
  288. {
  289. id: number;
  290. cluster_id: number;
  291. namespace: string;
  292. repo_url?: string;
  293. }
  294. >("POST", (pathParams) => {
  295. let { cluster_id, id, namespace, repo_url } = pathParams;
  296. if (repo_url) {
  297. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/releases?repo_url=${repo_url}`;
  298. }
  299. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/releases`;
  300. });
  301. const deployAddon = baseApi<
  302. {
  303. template_name: string;
  304. template_version: string;
  305. values?: any;
  306. name: string;
  307. },
  308. {
  309. id: number;
  310. cluster_id: number;
  311. namespace: string;
  312. repo_url?: string;
  313. }
  314. >("POST", (pathParams) => {
  315. let { cluster_id, id, namespace, repo_url } = pathParams;
  316. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/addons?repo_url=${repo_url}`;
  317. });
  318. const detectBuildpack = baseApi<
  319. {},
  320. {
  321. project_id: number;
  322. git_repo_id: number;
  323. kind: string;
  324. owner: string;
  325. name: string;
  326. branch: string;
  327. }
  328. >("GET", (pathParams) => {
  329. return `/api/projects/${pathParams.project_id}/gitrepos/${
  330. pathParams.git_repo_id
  331. }/repos/${pathParams.kind}/${pathParams.owner}/${
  332. pathParams.name
  333. }/${encodeURIComponent(pathParams.branch)}/buildpack/detect`;
  334. });
  335. const getBranchContents = baseApi<
  336. {
  337. dir: string;
  338. },
  339. {
  340. project_id: number;
  341. git_repo_id: number;
  342. kind: string;
  343. owner: string;
  344. name: string;
  345. branch: string;
  346. }
  347. >("GET", (pathParams) => {
  348. return `/api/projects/${pathParams.project_id}/gitrepos/${
  349. pathParams.git_repo_id
  350. }/repos/${pathParams.kind}/${pathParams.owner}/${
  351. pathParams.name
  352. }/${encodeURIComponent(pathParams.branch)}/contents`;
  353. });
  354. const getProcfileContents = baseApi<
  355. {
  356. path: string;
  357. },
  358. {
  359. project_id: number;
  360. git_repo_id: number;
  361. kind: string;
  362. owner: string;
  363. name: string;
  364. branch: string;
  365. }
  366. >("GET", (pathParams) => {
  367. return `/api/projects/${pathParams.project_id}/gitrepos/${
  368. pathParams.git_repo_id
  369. }/repos/${pathParams.kind}/${pathParams.owner}/${
  370. pathParams.name
  371. }/${encodeURIComponent(pathParams.branch)}/procfile`;
  372. });
  373. const getBranches = baseApi<
  374. {},
  375. {
  376. project_id: number;
  377. git_repo_id: number;
  378. kind: string;
  379. owner: string;
  380. name: string;
  381. }
  382. >("GET", (pathParams) => {
  383. return `/api/projects/${pathParams.project_id}/gitrepos/${pathParams.git_repo_id}/repos/${pathParams.kind}/${pathParams.owner}/${pathParams.name}/branches`;
  384. });
  385. const getChart = baseApi<
  386. {},
  387. {
  388. id: number;
  389. cluster_id: number;
  390. namespace: string;
  391. name: string;
  392. revision: number;
  393. }
  394. >("GET", (pathParams) => {
  395. let { id, cluster_id, namespace, name, revision } = pathParams;
  396. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/releases/${name}/${revision}`;
  397. });
  398. const getCharts = baseApi<
  399. {
  400. limit: number;
  401. skip: number;
  402. byDate: boolean;
  403. statusFilter: string[];
  404. },
  405. {
  406. id: number;
  407. cluster_id: number;
  408. namespace: string;
  409. }
  410. >("GET", (pathParams) => {
  411. return `/api/projects/${pathParams.id}/clusters/${pathParams.cluster_id}/namespaces/${pathParams.namespace}/releases`;
  412. });
  413. const getChartComponents = baseApi<
  414. {},
  415. {
  416. id: number;
  417. cluster_id: number;
  418. namespace: string;
  419. name: string;
  420. revision: number;
  421. }
  422. >("GET", (pathParams) => {
  423. let { id, cluster_id, namespace, name, revision } = pathParams;
  424. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/releases/${name}/${revision}/components`;
  425. });
  426. const getChartControllers = baseApi<
  427. {},
  428. {
  429. id: number;
  430. cluster_id: number;
  431. namespace: string;
  432. name: string;
  433. revision: number;
  434. }
  435. >("GET", (pathParams) => {
  436. let { id, cluster_id, namespace, name, revision } = pathParams;
  437. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/releases/${name}/${revision}/controllers`;
  438. });
  439. const getClusterIntegrations = baseApi("GET", "/api/integrations/cluster");
  440. const getClusters = baseApi<{}, { id: number }>("GET", (pathParams) => {
  441. return `/api/projects/${pathParams.id}/clusters`;
  442. });
  443. const getCluster = baseApi<
  444. {},
  445. {
  446. project_id: number;
  447. cluster_id: number;
  448. }
  449. >("GET", (pathParams) => {
  450. return `/api/projects/${pathParams.project_id}/clusters/${pathParams.cluster_id}`;
  451. });
  452. const getClusterNodes = baseApi<
  453. {},
  454. {
  455. project_id: number;
  456. cluster_id: number;
  457. }
  458. >("GET", (pathParams) => {
  459. return `/api/projects/${pathParams.project_id}/clusters/${pathParams.cluster_id}/nodes`;
  460. });
  461. const getClusterNode = baseApi<
  462. {},
  463. {
  464. project_id: number;
  465. cluster_id: number;
  466. nodeName: string;
  467. }
  468. >(
  469. "GET",
  470. (pathParams) =>
  471. `/api/projects/${pathParams.project_id}/clusters/${pathParams.cluster_id}/nodes/${pathParams.nodeName}`
  472. );
  473. const getGitRepoList = baseApi<
  474. {},
  475. {
  476. project_id: number;
  477. git_repo_id: number;
  478. }
  479. >("GET", (pathParams) => {
  480. return `/api/projects/${pathParams.project_id}/gitrepos/${pathParams.git_repo_id}/repos`;
  481. });
  482. const getGitRepos = baseApi<
  483. {},
  484. {
  485. project_id: number;
  486. }
  487. >("GET", (pathParams) => {
  488. return `/api/projects/${pathParams.project_id}/gitrepos`;
  489. });
  490. const getImageRepos = baseApi<
  491. {},
  492. {
  493. project_id: number;
  494. registry_id: number;
  495. }
  496. >("GET", (pathParams) => {
  497. return `/api/projects/${pathParams.project_id}/registries/${pathParams.registry_id}/repositories`;
  498. });
  499. const getImageTags = baseApi<
  500. {},
  501. {
  502. project_id: number;
  503. registry_id: number;
  504. repo_name: string;
  505. }
  506. >("GET", (pathParams) => {
  507. return `/api/projects/${pathParams.project_id}/registries/${pathParams.registry_id}/repositories/${pathParams.repo_name}`;
  508. });
  509. const getInfra = baseApi<
  510. {},
  511. {
  512. project_id: number;
  513. }
  514. >("GET", (pathParams) => {
  515. return `/api/projects/${pathParams.project_id}/infra`;
  516. });
  517. const getInfraDesired = baseApi<
  518. {},
  519. {
  520. project_id: number;
  521. infra_id: number;
  522. }
  523. >("GET", (pathParams) => {
  524. return `/api/projects/${pathParams.project_id}/infras/${pathParams.infra_id}/desired`;
  525. });
  526. const getInfraCurrent = baseApi<
  527. {},
  528. {
  529. project_id: number;
  530. infra_id: number;
  531. }
  532. >("GET", (pathParams) => {
  533. return `/api/projects/${pathParams.project_id}/infras/${pathParams.infra_id}/current`;
  534. });
  535. const getIngress = baseApi<
  536. {},
  537. { namespace: string; cluster_id: number; name: string; id: number }
  538. >("GET", (pathParams) => {
  539. let { id, name, cluster_id, namespace } = pathParams;
  540. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/ingresses/${name}`;
  541. });
  542. const getInvites = baseApi<{}, { id: number }>("GET", (pathParams) => {
  543. return `/api/projects/${pathParams.id}/invites`;
  544. });
  545. const getJobs = baseApi<
  546. {},
  547. { namespace: string; cluster_id: number; release_name: string; id: number }
  548. >("GET", (pathParams) => {
  549. let { id, release_name, cluster_id, namespace } = pathParams;
  550. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/releases/${release_name}/0/jobs`;
  551. });
  552. const getJobStatus = baseApi<
  553. {},
  554. { namespace: string; cluster_id: number; release_name: string; id: number }
  555. >("GET", (pathParams) => {
  556. let { id, release_name, cluster_id, namespace } = pathParams;
  557. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/releases/${release_name}/0/jobs/status`;
  558. });
  559. const getJobPods = baseApi<
  560. {},
  561. { name: string; namespace: string; id: number; cluster_id: number }
  562. >("GET", (pathParams) => {
  563. let { id, name, cluster_id, namespace } = pathParams;
  564. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/jobs/${name}/pods`;
  565. });
  566. const getPodByName = baseApi<
  567. {},
  568. {
  569. project_id: number;
  570. cluster_id: number;
  571. namespace: string;
  572. name: string;
  573. }
  574. >(
  575. "GET",
  576. ({ project_id, cluster_id, namespace, name }) =>
  577. `/api/projects/${project_id}/clusters/${cluster_id}/namespaces/${namespace}/pods/${name}`
  578. );
  579. const getMatchingPods = baseApi<
  580. {
  581. namespace: string;
  582. selectors: string[];
  583. },
  584. { id: number; cluster_id: number }
  585. >("GET", (pathParams) => {
  586. return `/api/projects/${pathParams.id}/clusters/${pathParams.cluster_id}/pods`;
  587. });
  588. const getMetrics = baseApi<
  589. {
  590. metric: string;
  591. shouldsum: boolean;
  592. pods?: string[];
  593. kind?: string; // the controller kind
  594. name?: string;
  595. percentile?: number;
  596. namespace: string;
  597. startrange: number;
  598. endrange: number;
  599. resolution: string;
  600. },
  601. {
  602. id: number;
  603. cluster_id: number;
  604. }
  605. >("GET", (pathParams) => {
  606. return `/api/projects/${pathParams.id}/clusters/${pathParams.cluster_id}/metrics`;
  607. });
  608. const getNamespaces = baseApi<
  609. {},
  610. {
  611. id: number;
  612. cluster_id: number;
  613. }
  614. >("GET", (pathParams) => {
  615. return `/api/projects/${pathParams.id}/clusters/${pathParams.cluster_id}/namespaces`;
  616. });
  617. const getNGINXIngresses = baseApi<
  618. {},
  619. {
  620. id: number;
  621. cluster_id: number;
  622. }
  623. >("GET", (pathParams) => {
  624. return `/api/projects/${pathParams.id}/clusters/${pathParams.cluster_id}/prometheus/ingresses`;
  625. });
  626. const getOAuthIds = baseApi<
  627. {},
  628. {
  629. project_id: number;
  630. }
  631. >("GET", (pathParams) => {
  632. return `/api/projects/${pathParams.project_id}/integrations/oauth`;
  633. });
  634. const getProjectClusters = baseApi<{}, { id: number }>("GET", (pathParams) => {
  635. return `/api/projects/${pathParams.id}/clusters`;
  636. });
  637. const getProjectRegistries = baseApi<{}, { id: number }>(
  638. "GET",
  639. (pathParams) => {
  640. return `/api/projects/${pathParams.id}/registries`;
  641. }
  642. );
  643. const getProjectRepos = baseApi<{}, { id: number }>("GET", (pathParams) => {
  644. return `/api/projects/${pathParams.id}/repos`;
  645. });
  646. const getProjects = baseApi("GET", "/api/projects");
  647. const getPrometheusIsInstalled = baseApi<
  648. {},
  649. {
  650. id: number;
  651. cluster_id: number;
  652. }
  653. >("GET", (pathParams) => {
  654. return `/api/projects/${pathParams.id}/clusters/${pathParams.cluster_id}/prometheus/detect`;
  655. });
  656. const getRegistryIntegrations = baseApi("GET", "/api/integrations/registry");
  657. const getReleaseToken = baseApi<
  658. {},
  659. { name: string; id: number; namespace: string; cluster_id: number }
  660. >("GET", (pathParams) => {
  661. let { id, cluster_id, namespace, name } = pathParams;
  662. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/releases/${name}/webhook`;
  663. });
  664. const getReleaseSteps = baseApi<
  665. {},
  666. { name: string; id: number; namespace: string; cluster_id: number }
  667. >("GET", (pathParams) => {
  668. let { id, cluster_id, namespace, name } = pathParams;
  669. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/releases/${name}/steps`;
  670. });
  671. const destroyInfra = baseApi<
  672. {
  673. name: string;
  674. },
  675. {
  676. project_id: number;
  677. infra_id: number;
  678. }
  679. >("DELETE", (pathParams) => {
  680. return `/api/projects/${pathParams.project_id}/infras/${pathParams.infra_id}`;
  681. });
  682. const getRepoIntegrations = baseApi("GET", "/api/integrations/repo");
  683. const getRepos = baseApi<{}, { id: number }>("GET", (pathParams) => {
  684. return `/api/projects/${pathParams.id}/repos`;
  685. });
  686. const getSlackIntegrations = baseApi<{}, { id: number }>(
  687. "GET",
  688. (pathParams) => {
  689. return `/api/projects/${pathParams.id}/slack_integrations`;
  690. }
  691. );
  692. const getRevisions = baseApi<
  693. {},
  694. { id: number; cluster_id: number; namespace: string; name: string }
  695. >("GET", (pathParams) => {
  696. let { id, cluster_id, namespace, name } = pathParams;
  697. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/releases/${name}/history`;
  698. });
  699. const getTemplateInfo = baseApi<
  700. {
  701. repo_url?: string;
  702. },
  703. { name: string; version: string }
  704. >("GET", (pathParams) => {
  705. return `/api/templates/${pathParams.name}/${pathParams.version}`;
  706. });
  707. const getTemplateUpgradeNotes = baseApi<
  708. {
  709. repo_url?: string;
  710. prev_version: string;
  711. },
  712. { name: string; version: string }
  713. >("GET", (pathParams) => {
  714. return `/api/templates/${pathParams.name}/${pathParams.version}/upgrade_notes`;
  715. });
  716. const getTemplates = baseApi<
  717. {
  718. repo_url?: string;
  719. },
  720. {}
  721. >("GET", "/api/templates");
  722. const getMetadata = baseApi<{}, {}>("GET", () => {
  723. return `/api/metadata`;
  724. });
  725. const postWelcome = baseApi<{
  726. email: string;
  727. isCompany: boolean;
  728. company: string;
  729. role: string;
  730. }>("POST", () => {
  731. return `/api/welcome`;
  732. });
  733. const linkGithubProject = baseApi<
  734. {},
  735. {
  736. project_id: number;
  737. }
  738. >("GET", (pathParams) => {
  739. return `/api/oauth/projects/${pathParams.project_id}/github`;
  740. });
  741. const getGithubAccounts = baseApi<{}, {}>("GET", () => {
  742. return `/api/integrations/github-app/accounts`;
  743. });
  744. const logInUser = baseApi<{
  745. email: string;
  746. password: string;
  747. }>("POST", "/api/login");
  748. const logOutUser = baseApi("POST", "/api/logout");
  749. const provisionECR = baseApi<
  750. {
  751. ecr_name: string;
  752. aws_integration_id: number;
  753. },
  754. { id: number }
  755. >("POST", (pathParams) => {
  756. return `/api/projects/${pathParams.id}/provision/ecr`;
  757. });
  758. const provisionEKS = baseApi<
  759. {
  760. eks_name: string;
  761. aws_integration_id: number;
  762. machine_type: string;
  763. issuer_email: string;
  764. },
  765. { id: number }
  766. >("POST", (pathParams) => {
  767. return `/api/projects/${pathParams.id}/provision/eks`;
  768. });
  769. const registerUser = baseApi<{
  770. email: string;
  771. password: string;
  772. }>("POST", "/api/users");
  773. const rollbackChart = baseApi<
  774. {
  775. revision: number;
  776. },
  777. {
  778. id: number;
  779. name: string;
  780. namespace: string;
  781. cluster_id: number;
  782. }
  783. >("POST", (pathParams) => {
  784. let { id, name, cluster_id, namespace } = pathParams;
  785. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/releases/${name}/0/rollback`;
  786. });
  787. const uninstallTemplate = baseApi<
  788. {},
  789. {
  790. id: number;
  791. name: string;
  792. cluster_id: number;
  793. namespace: string;
  794. }
  795. >("DELETE", (pathParams) => {
  796. let { id, name, cluster_id, namespace } = pathParams;
  797. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/releases/${name}/0`;
  798. });
  799. const updateUser = baseApi<
  800. {
  801. rawKubeConfig?: string;
  802. allowedContexts?: string[];
  803. },
  804. { id: number }
  805. >("PUT", (pathParams) => {
  806. return `/api/users/${pathParams.id}`;
  807. });
  808. const upgradeChartValues = baseApi<
  809. {
  810. values: string;
  811. version?: string;
  812. },
  813. {
  814. id: number;
  815. name: string;
  816. namespace: string;
  817. cluster_id: number;
  818. }
  819. >("POST", (pathParams) => {
  820. let { id, name, cluster_id, namespace } = pathParams;
  821. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/releases/${name}/0/upgrade`;
  822. });
  823. const listConfigMaps = baseApi<
  824. {},
  825. {
  826. id: number;
  827. namespace: string;
  828. cluster_id: number;
  829. }
  830. >("GET", (pathParams) => {
  831. return `/api/projects/${pathParams.id}/clusters/${pathParams.cluster_id}/namespaces/${pathParams.namespace}/configmap/list`;
  832. });
  833. const getConfigMap = baseApi<
  834. {
  835. name: string;
  836. },
  837. {
  838. id: number;
  839. namespace: string;
  840. cluster_id: number;
  841. }
  842. >("GET", (pathParams) => {
  843. return `/api/projects/${pathParams.id}/clusters/${pathParams.cluster_id}/namespaces/${pathParams.namespace}/configmap`;
  844. });
  845. const createConfigMap = baseApi<
  846. {
  847. name: string;
  848. variables: Record<string, string>;
  849. secret_variables?: Record<string, string>;
  850. },
  851. {
  852. id: number;
  853. cluster_id: number;
  854. namespace: string;
  855. }
  856. >("POST", (pathParams) => {
  857. return `/api/projects/${pathParams.id}/clusters/${pathParams.cluster_id}/namespaces/${pathParams.namespace}/configmap/create`;
  858. });
  859. const updateConfigMap = baseApi<
  860. {
  861. name: string;
  862. variables: Record<string, string>;
  863. secret_variables?: Record<string, string>;
  864. },
  865. {
  866. id: number;
  867. cluster_id: number;
  868. namespace: string;
  869. }
  870. >("POST", (pathParams) => {
  871. let { id, cluster_id } = pathParams;
  872. return `/api/projects/${pathParams.id}/clusters/${pathParams.cluster_id}/namespaces/${pathParams.namespace}/configmap/update`;
  873. });
  874. const renameConfigMap = baseApi<
  875. {
  876. name: string;
  877. new_name: string;
  878. },
  879. {
  880. id: number;
  881. cluster_id: number;
  882. namespace: string;
  883. }
  884. >("POST", (pathParams) => {
  885. return `/api/projects/${pathParams.id}/clusters/${pathParams.cluster_id}/namespaces/${pathParams.namespace}/configmap/rename`;
  886. });
  887. const deleteConfigMap = baseApi<
  888. {
  889. name: string;
  890. },
  891. {
  892. id: number;
  893. namespace: string;
  894. cluster_id: number;
  895. }
  896. >("DELETE", (pathParams) => {
  897. return `/api/projects/${pathParams.id}/clusters/${pathParams.cluster_id}/namespaces/${pathParams.namespace}/configmap/delete`;
  898. });
  899. const createNamespace = baseApi<
  900. {
  901. name: string;
  902. },
  903. { id: number; cluster_id: number }
  904. >("POST", (pathParams) => {
  905. let { id, cluster_id } = pathParams;
  906. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/create`;
  907. });
  908. const deleteNamespace = baseApi<
  909. {
  910. name: string;
  911. },
  912. {
  913. id: number;
  914. cluster_id: number;
  915. }
  916. >("DELETE", (pathParams) => {
  917. let { id, cluster_id } = pathParams;
  918. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/delete`;
  919. });
  920. const deleteJob = baseApi<
  921. {},
  922. { name: string; namespace: string; id: number; cluster_id: number }
  923. >("DELETE", (pathParams) => {
  924. let { id, name, cluster_id, namespace } = pathParams;
  925. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/jobs/${name}`;
  926. });
  927. const stopJob = baseApi<
  928. {},
  929. { name: string; namespace: string; id: number; cluster_id: number }
  930. >("POST", (pathParams) => {
  931. let { id, name, namespace, cluster_id } = pathParams;
  932. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/jobs/${name}/stop`;
  933. });
  934. const getAvailableRoles = baseApi<{}, { project_id: number }>(
  935. "GET",
  936. ({ project_id }) => `/api/projects/${project_id}/roles`
  937. );
  938. const updateInvite = baseApi<
  939. { kind: string },
  940. { project_id: number; invite_id: number }
  941. >(
  942. "POST",
  943. ({ project_id, invite_id }) =>
  944. `/api/projects/${project_id}/invites/${invite_id}`
  945. );
  946. const getCollaborators = baseApi<{}, { project_id: number }>(
  947. "GET",
  948. ({ project_id }) => `/api/projects/${project_id}/collaborators`
  949. );
  950. const updateCollaborator = baseApi<
  951. {
  952. kind: string;
  953. user_id: number;
  954. },
  955. { project_id: number }
  956. >("POST", ({ project_id }) => `/api/projects/${project_id}/roles`);
  957. const removeCollaborator = baseApi<{ user_id: number }, { project_id: number }>(
  958. "DELETE",
  959. ({ project_id }) => `/api/projects/${project_id}/roles`
  960. );
  961. const getPolicyDocument = baseApi<{}, { project_id: number }>(
  962. "GET",
  963. ({ project_id }) => `/api/projects/${project_id}/policy`
  964. );
  965. const createWebhookToken = baseApi<
  966. {},
  967. {
  968. project_id: number;
  969. chart_name: string;
  970. namespace: string;
  971. cluster_id: number;
  972. }
  973. >(
  974. "POST",
  975. ({ project_id, chart_name, namespace, cluster_id }) =>
  976. `/api/projects/${project_id}/clusters/${cluster_id}/namespaces/${namespace}/releases/${chart_name}/0/webhook`
  977. );
  978. const getUsage = baseApi<{}, { project_id: number }>(
  979. "GET",
  980. ({ project_id }) => `/api/projects/${project_id}/usage`
  981. );
  982. // Used for billing purposes
  983. const getCustomerToken = baseApi<{}, { project_id: number }>(
  984. "GET",
  985. ({ project_id }) => `/api/projects/${project_id}/billing/token`
  986. );
  987. const getHasBilling = baseApi<{}, { project_id: number }>(
  988. "GET",
  989. ({ project_id }) => `/api/projects/${project_id}/billing`
  990. );
  991. const getOnboardingState = baseApi<{}, { project_id: number }>(
  992. "GET",
  993. ({ project_id }) => `/api/projects/${project_id}/onboarding`
  994. );
  995. const saveOnboardingState = baseApi<{}, { project_id: number }>(
  996. "POST",
  997. ({ project_id }) => `/api/projects/${project_id}/onboarding`
  998. );
  999. const getOnboardingInfra = baseApi<
  1000. {},
  1001. { project_id: number; registry_infra_id: number }
  1002. >(
  1003. "GET",
  1004. ({ project_id, registry_infra_id }) =>
  1005. `/api/projects/${project_id}/infras/${registry_infra_id}`
  1006. );
  1007. const getOnboardingRegistry = baseApi<
  1008. {},
  1009. { project_id: number; registry_connection_id: number }
  1010. >(
  1011. "GET",
  1012. ({ project_id, registry_connection_id }) =>
  1013. `/api/projects/${project_id}/registries/${registry_connection_id}`
  1014. );
  1015. const detectPorterAgent = baseApi<
  1016. {},
  1017. { project_id: number; cluster_id: number }
  1018. >(
  1019. "GET",
  1020. ({ project_id, cluster_id }) =>
  1021. `/api/projects/${project_id}/clusters/${cluster_id}/agent/detect`
  1022. );
  1023. const installPorterAgent = baseApi<
  1024. {},
  1025. { project_id: number; cluster_id: number }
  1026. >(
  1027. "POST",
  1028. ({ cluster_id, project_id }) =>
  1029. `/api/projects/${project_id}/clusters/${cluster_id}/agent/install`
  1030. );
  1031. const getKubeEvents = baseApi<
  1032. {
  1033. skip: number;
  1034. resource_type: string;
  1035. owner_type?: string;
  1036. owner_name?: string;
  1037. },
  1038. { project_id: number; cluster_id: number }
  1039. >("GET", ({ project_id, cluster_id }) => {
  1040. return `/api/projects/${project_id}/clusters/${cluster_id}/kube_events`;
  1041. });
  1042. const getKubeEvent = baseApi<
  1043. {},
  1044. { project_id: number; cluster_id: number; kube_event_id: number }
  1045. >(
  1046. "GET",
  1047. ({ project_id, cluster_id, kube_event_id }) =>
  1048. `/api/projects/${project_id}/clusters/${cluster_id}/kube_events/${kube_event_id}`
  1049. );
  1050. const getLogBuckets = baseApi<
  1051. {},
  1052. { project_id: number; cluster_id: number; kube_event_id: number }
  1053. >(
  1054. "GET",
  1055. ({ project_id, cluster_id, kube_event_id }) =>
  1056. `/api/projects/${project_id}/clusters/${cluster_id}/kube_events/${kube_event_id}/log_buckets`
  1057. );
  1058. const getLogBucketLogs = baseApi<
  1059. { timestamp: number },
  1060. { project_id: number; cluster_id: number; kube_event_id: number }
  1061. >(
  1062. "GET",
  1063. ({ project_id, cluster_id, kube_event_id }) =>
  1064. `/api/projects/${project_id}/clusters/${cluster_id}/kube_events/${kube_event_id}/logs`
  1065. );
  1066. // Bundle export to allow default api import (api.<method> is more readable)
  1067. export default {
  1068. checkAuth,
  1069. connectECRRegistry,
  1070. connectGCRRegistry,
  1071. connectDORegistry,
  1072. getAWSIntegration,
  1073. getGCPIntegration,
  1074. createAWSIntegration,
  1075. overwriteAWSIntegration,
  1076. createDOCR,
  1077. createDOKS,
  1078. createEmailVerification,
  1079. createGCPIntegration,
  1080. createGCR,
  1081. createGKE,
  1082. createInvite,
  1083. createNamespace,
  1084. createPasswordReset,
  1085. createPasswordResetVerify,
  1086. createPasswordResetFinalize,
  1087. createProject,
  1088. createConfigMap,
  1089. deleteCluster,
  1090. deleteConfigMap,
  1091. deleteInvite,
  1092. deleteNamespace,
  1093. deletePod,
  1094. deleteProject,
  1095. deleteRegistryIntegration,
  1096. deleteSlackIntegration,
  1097. updateNotificationConfig,
  1098. getNotificationConfig,
  1099. createSubdomain,
  1100. deployTemplate,
  1101. deployAddon,
  1102. destroyInfra,
  1103. detectBuildpack,
  1104. getBranchContents,
  1105. getBranches,
  1106. getMetadata,
  1107. postWelcome,
  1108. getChart,
  1109. getCharts,
  1110. getChartComponents,
  1111. getChartControllers,
  1112. getClusterIntegrations,
  1113. getClusters,
  1114. getCluster,
  1115. getClusterNodes,
  1116. getClusterNode,
  1117. getConfigMap,
  1118. getGHAWorkflowTemplate,
  1119. getGitRepoList,
  1120. getGitRepos,
  1121. getImageRepos,
  1122. getImageTags,
  1123. getInfra,
  1124. getInfraDesired,
  1125. getInfraCurrent,
  1126. getIngress,
  1127. getInvites,
  1128. getJobs,
  1129. getJobStatus,
  1130. getJobPods,
  1131. getPodByName,
  1132. getMatchingPods,
  1133. getMetrics,
  1134. getNamespaces,
  1135. getNGINXIngresses,
  1136. getOAuthIds,
  1137. getPodEvents,
  1138. getProcfileContents,
  1139. getProjectClusters,
  1140. getProjectRegistries,
  1141. getProjectRepos,
  1142. getProjects,
  1143. getPrometheusIsInstalled,
  1144. getRegistryIntegrations,
  1145. getReleaseToken,
  1146. getReleaseSteps,
  1147. getRepoIntegrations,
  1148. getSlackIntegrations,
  1149. getRepos,
  1150. getRevisions,
  1151. getTemplateInfo,
  1152. getTemplateUpgradeNotes,
  1153. getTemplates,
  1154. linkGithubProject,
  1155. getGithubAccounts,
  1156. listConfigMaps,
  1157. logInUser,
  1158. logOutUser,
  1159. provisionECR,
  1160. provisionEKS,
  1161. registerUser,
  1162. rollbackChart,
  1163. uninstallTemplate,
  1164. updateUser,
  1165. renameConfigMap,
  1166. updateConfigMap,
  1167. upgradeChartValues,
  1168. deleteJob,
  1169. stopJob,
  1170. updateInvite,
  1171. getAvailableRoles,
  1172. getCollaborators,
  1173. updateCollaborator,
  1174. removeCollaborator,
  1175. getPolicyDocument,
  1176. createWebhookToken,
  1177. getUsage,
  1178. getCustomerToken,
  1179. getHasBilling,
  1180. getOnboardingState,
  1181. saveOnboardingState,
  1182. getOnboardingInfra,
  1183. getOnboardingRegistry,
  1184. detectPorterAgent,
  1185. installPorterAgent,
  1186. getKubeEvents,
  1187. getKubeEvent,
  1188. getLogBuckets,
  1189. getLogBucketLogs,
  1190. };