api.tsx 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331
  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. build_config?: any;
  288. },
  289. {
  290. id: number;
  291. cluster_id: number;
  292. namespace: string;
  293. repo_url?: string;
  294. }
  295. >("POST", (pathParams) => {
  296. let { cluster_id, id, namespace, repo_url } = pathParams;
  297. if (repo_url) {
  298. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/releases?repo_url=${repo_url}`;
  299. }
  300. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/releases`;
  301. });
  302. const deployAddon = baseApi<
  303. {
  304. template_name: string;
  305. template_version: string;
  306. values?: any;
  307. name: string;
  308. },
  309. {
  310. id: number;
  311. cluster_id: number;
  312. namespace: string;
  313. repo_url?: string;
  314. }
  315. >("POST", (pathParams) => {
  316. let { cluster_id, id, namespace, repo_url } = pathParams;
  317. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/addons?repo_url=${repo_url}`;
  318. });
  319. const detectBuildpack = baseApi<
  320. {},
  321. {
  322. project_id: number;
  323. git_repo_id: number;
  324. kind: string;
  325. owner: string;
  326. name: string;
  327. branch: string;
  328. }
  329. >("GET", (pathParams) => {
  330. return `/api/projects/${pathParams.project_id}/gitrepos/${
  331. pathParams.git_repo_id
  332. }/repos/${pathParams.kind}/${pathParams.owner}/${
  333. pathParams.name
  334. }/${encodeURIComponent(pathParams.branch)}/buildpack/detect`;
  335. });
  336. const getBranchContents = baseApi<
  337. {
  338. dir: string;
  339. },
  340. {
  341. project_id: number;
  342. git_repo_id: number;
  343. kind: string;
  344. owner: string;
  345. name: string;
  346. branch: string;
  347. }
  348. >("GET", (pathParams) => {
  349. return `/api/projects/${pathParams.project_id}/gitrepos/${
  350. pathParams.git_repo_id
  351. }/repos/${pathParams.kind}/${pathParams.owner}/${
  352. pathParams.name
  353. }/${encodeURIComponent(pathParams.branch)}/contents`;
  354. });
  355. const getProcfileContents = baseApi<
  356. {
  357. path: string;
  358. },
  359. {
  360. project_id: number;
  361. git_repo_id: number;
  362. kind: string;
  363. owner: string;
  364. name: string;
  365. branch: string;
  366. }
  367. >("GET", (pathParams) => {
  368. return `/api/projects/${pathParams.project_id}/gitrepos/${
  369. pathParams.git_repo_id
  370. }/repos/${pathParams.kind}/${pathParams.owner}/${
  371. pathParams.name
  372. }/${encodeURIComponent(pathParams.branch)}/procfile`;
  373. });
  374. const getBranches = baseApi<
  375. {},
  376. {
  377. project_id: number;
  378. git_repo_id: number;
  379. kind: string;
  380. owner: string;
  381. name: string;
  382. }
  383. >("GET", (pathParams) => {
  384. return `/api/projects/${pathParams.project_id}/gitrepos/${pathParams.git_repo_id}/repos/${pathParams.kind}/${pathParams.owner}/${pathParams.name}/branches`;
  385. });
  386. const getChart = baseApi<
  387. {},
  388. {
  389. id: number;
  390. cluster_id: number;
  391. namespace: string;
  392. name: string;
  393. revision: number;
  394. }
  395. >("GET", (pathParams) => {
  396. let { id, cluster_id, namespace, name, revision } = pathParams;
  397. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/releases/${name}/${revision}`;
  398. });
  399. const getCharts = baseApi<
  400. {
  401. limit: number;
  402. skip: number;
  403. byDate: boolean;
  404. statusFilter: string[];
  405. },
  406. {
  407. id: number;
  408. cluster_id: number;
  409. namespace: string;
  410. }
  411. >("GET", (pathParams) => {
  412. return `/api/projects/${pathParams.id}/clusters/${pathParams.cluster_id}/namespaces/${pathParams.namespace}/releases`;
  413. });
  414. const getChartComponents = baseApi<
  415. {},
  416. {
  417. id: number;
  418. cluster_id: number;
  419. namespace: string;
  420. name: string;
  421. revision: number;
  422. }
  423. >("GET", (pathParams) => {
  424. let { id, cluster_id, namespace, name, revision } = pathParams;
  425. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/releases/${name}/${revision}/components`;
  426. });
  427. const getChartControllers = baseApi<
  428. {},
  429. {
  430. id: number;
  431. cluster_id: number;
  432. namespace: string;
  433. name: string;
  434. revision: number;
  435. }
  436. >("GET", (pathParams) => {
  437. let { id, cluster_id, namespace, name, revision } = pathParams;
  438. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/releases/${name}/${revision}/controllers`;
  439. });
  440. const getClusterIntegrations = baseApi("GET", "/api/integrations/cluster");
  441. const getClusters = baseApi<{}, { id: number }>("GET", (pathParams) => {
  442. return `/api/projects/${pathParams.id}/clusters`;
  443. });
  444. const getCluster = baseApi<
  445. {},
  446. {
  447. project_id: number;
  448. cluster_id: number;
  449. }
  450. >("GET", (pathParams) => {
  451. return `/api/projects/${pathParams.project_id}/clusters/${pathParams.cluster_id}`;
  452. });
  453. const getClusterNodes = baseApi<
  454. {},
  455. {
  456. project_id: number;
  457. cluster_id: number;
  458. }
  459. >("GET", (pathParams) => {
  460. return `/api/projects/${pathParams.project_id}/clusters/${pathParams.cluster_id}/nodes`;
  461. });
  462. const getClusterNode = baseApi<
  463. {},
  464. {
  465. project_id: number;
  466. cluster_id: number;
  467. nodeName: string;
  468. }
  469. >(
  470. "GET",
  471. (pathParams) =>
  472. `/api/projects/${pathParams.project_id}/clusters/${pathParams.cluster_id}/nodes/${pathParams.nodeName}`
  473. );
  474. const getGitRepoList = baseApi<
  475. {},
  476. {
  477. project_id: number;
  478. git_repo_id: number;
  479. }
  480. >("GET", (pathParams) => {
  481. return `/api/projects/${pathParams.project_id}/gitrepos/${pathParams.git_repo_id}/repos`;
  482. });
  483. const getGitRepos = baseApi<
  484. {},
  485. {
  486. project_id: number;
  487. }
  488. >("GET", (pathParams) => {
  489. return `/api/projects/${pathParams.project_id}/gitrepos`;
  490. });
  491. const getImageRepos = baseApi<
  492. {},
  493. {
  494. project_id: number;
  495. registry_id: number;
  496. }
  497. >("GET", (pathParams) => {
  498. return `/api/projects/${pathParams.project_id}/registries/${pathParams.registry_id}/repositories`;
  499. });
  500. const getImageTags = baseApi<
  501. {},
  502. {
  503. project_id: number;
  504. registry_id: number;
  505. repo_name: string;
  506. }
  507. >("GET", (pathParams) => {
  508. return `/api/projects/${pathParams.project_id}/registries/${pathParams.registry_id}/repositories/${pathParams.repo_name}`;
  509. });
  510. const getInfra = baseApi<
  511. {},
  512. {
  513. project_id: number;
  514. }
  515. >("GET", (pathParams) => {
  516. return `/api/projects/${pathParams.project_id}/infra`;
  517. });
  518. const getInfraDesired = baseApi<
  519. {},
  520. {
  521. project_id: number;
  522. infra_id: number;
  523. }
  524. >("GET", (pathParams) => {
  525. return `/api/projects/${pathParams.project_id}/infras/${pathParams.infra_id}/desired`;
  526. });
  527. const getInfraCurrent = baseApi<
  528. {},
  529. {
  530. project_id: number;
  531. infra_id: number;
  532. }
  533. >("GET", (pathParams) => {
  534. return `/api/projects/${pathParams.project_id}/infras/${pathParams.infra_id}/current`;
  535. });
  536. const getIngress = baseApi<
  537. {},
  538. { namespace: string; cluster_id: number; name: string; id: number }
  539. >("GET", (pathParams) => {
  540. let { id, name, cluster_id, namespace } = pathParams;
  541. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/ingresses/${name}`;
  542. });
  543. const getInvites = baseApi<{}, { id: number }>("GET", (pathParams) => {
  544. return `/api/projects/${pathParams.id}/invites`;
  545. });
  546. const getJobs = baseApi<
  547. {},
  548. { namespace: string; cluster_id: number; release_name: string; id: number }
  549. >("GET", (pathParams) => {
  550. let { id, release_name, cluster_id, namespace } = pathParams;
  551. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/releases/${release_name}/0/jobs`;
  552. });
  553. const getJobStatus = baseApi<
  554. {},
  555. { namespace: string; cluster_id: number; release_name: string; id: number }
  556. >("GET", (pathParams) => {
  557. let { id, release_name, cluster_id, namespace } = pathParams;
  558. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/releases/${release_name}/0/jobs/status`;
  559. });
  560. const getJobPods = baseApi<
  561. {},
  562. { name: string; namespace: string; id: number; cluster_id: number }
  563. >("GET", (pathParams) => {
  564. let { id, name, cluster_id, namespace } = pathParams;
  565. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/jobs/${name}/pods`;
  566. });
  567. const getPodByName = baseApi<
  568. {},
  569. {
  570. project_id: number;
  571. cluster_id: number;
  572. namespace: string;
  573. name: string;
  574. }
  575. >(
  576. "GET",
  577. ({ project_id, cluster_id, namespace, name }) =>
  578. `/api/projects/${project_id}/clusters/${cluster_id}/namespaces/${namespace}/pods/${name}`
  579. );
  580. const getMatchingPods = baseApi<
  581. {
  582. namespace: string;
  583. selectors: string[];
  584. },
  585. { id: number; cluster_id: number }
  586. >("GET", (pathParams) => {
  587. return `/api/projects/${pathParams.id}/clusters/${pathParams.cluster_id}/pods`;
  588. });
  589. const getMetrics = baseApi<
  590. {
  591. metric: string;
  592. shouldsum: boolean;
  593. pods?: string[];
  594. kind?: string; // the controller kind
  595. name?: string;
  596. percentile?: number;
  597. namespace: string;
  598. startrange: number;
  599. endrange: number;
  600. resolution: string;
  601. },
  602. {
  603. id: number;
  604. cluster_id: number;
  605. }
  606. >("GET", (pathParams) => {
  607. return `/api/projects/${pathParams.id}/clusters/${pathParams.cluster_id}/metrics`;
  608. });
  609. const getNamespaces = baseApi<
  610. {},
  611. {
  612. id: number;
  613. cluster_id: number;
  614. }
  615. >("GET", (pathParams) => {
  616. return `/api/projects/${pathParams.id}/clusters/${pathParams.cluster_id}/namespaces`;
  617. });
  618. const getNGINXIngresses = baseApi<
  619. {},
  620. {
  621. id: number;
  622. cluster_id: number;
  623. }
  624. >("GET", (pathParams) => {
  625. return `/api/projects/${pathParams.id}/clusters/${pathParams.cluster_id}/prometheus/ingresses`;
  626. });
  627. const getOAuthIds = baseApi<
  628. {},
  629. {
  630. project_id: number;
  631. }
  632. >("GET", (pathParams) => {
  633. return `/api/projects/${pathParams.project_id}/integrations/oauth`;
  634. });
  635. const getProjectClusters = baseApi<{}, { id: number }>("GET", (pathParams) => {
  636. return `/api/projects/${pathParams.id}/clusters`;
  637. });
  638. const getProjectRegistries = baseApi<{}, { id: number }>(
  639. "GET",
  640. (pathParams) => {
  641. return `/api/projects/${pathParams.id}/registries`;
  642. }
  643. );
  644. const getProjectRepos = baseApi<{}, { id: number }>("GET", (pathParams) => {
  645. return `/api/projects/${pathParams.id}/repos`;
  646. });
  647. const getProjects = baseApi("GET", "/api/projects");
  648. const getPrometheusIsInstalled = baseApi<
  649. {},
  650. {
  651. id: number;
  652. cluster_id: number;
  653. }
  654. >("GET", (pathParams) => {
  655. return `/api/projects/${pathParams.id}/clusters/${pathParams.cluster_id}/prometheus/detect`;
  656. });
  657. const getRegistryIntegrations = baseApi("GET", "/api/integrations/registry");
  658. const getReleaseToken = baseApi<
  659. {},
  660. { name: string; id: number; namespace: string; cluster_id: number }
  661. >("GET", (pathParams) => {
  662. let { id, cluster_id, namespace, name } = pathParams;
  663. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/releases/${name}/webhook`;
  664. });
  665. const getReleaseSteps = baseApi<
  666. {},
  667. { name: string; id: number; namespace: string; cluster_id: number }
  668. >("GET", (pathParams) => {
  669. let { id, cluster_id, namespace, name } = pathParams;
  670. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/releases/${name}/steps`;
  671. });
  672. const destroyInfra = baseApi<
  673. {
  674. name: string;
  675. },
  676. {
  677. project_id: number;
  678. infra_id: number;
  679. }
  680. >("DELETE", (pathParams) => {
  681. return `/api/projects/${pathParams.project_id}/infras/${pathParams.infra_id}`;
  682. });
  683. const getRepoIntegrations = baseApi("GET", "/api/integrations/repo");
  684. const getRepos = baseApi<{}, { id: number }>("GET", (pathParams) => {
  685. return `/api/projects/${pathParams.id}/repos`;
  686. });
  687. const getSlackIntegrations = baseApi<{}, { id: number }>(
  688. "GET",
  689. (pathParams) => {
  690. return `/api/projects/${pathParams.id}/slack_integrations`;
  691. }
  692. );
  693. const getRevisions = baseApi<
  694. {},
  695. { id: number; cluster_id: number; namespace: string; name: string }
  696. >("GET", (pathParams) => {
  697. let { id, cluster_id, namespace, name } = pathParams;
  698. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/releases/${name}/history`;
  699. });
  700. const getTemplateInfo = baseApi<
  701. {
  702. repo_url?: string;
  703. },
  704. { name: string; version: string }
  705. >("GET", (pathParams) => {
  706. return `/api/templates/${pathParams.name}/${pathParams.version}`;
  707. });
  708. const getTemplateUpgradeNotes = baseApi<
  709. {
  710. repo_url?: string;
  711. prev_version: string;
  712. },
  713. { name: string; version: string }
  714. >("GET", (pathParams) => {
  715. return `/api/templates/${pathParams.name}/${pathParams.version}/upgrade_notes`;
  716. });
  717. const getTemplates = baseApi<
  718. {
  719. repo_url?: string;
  720. },
  721. {}
  722. >("GET", "/api/templates");
  723. const getMetadata = baseApi<{}, {}>("GET", () => {
  724. return `/api/metadata`;
  725. });
  726. const postWelcome = baseApi<{
  727. email: string;
  728. isCompany: boolean;
  729. company: string;
  730. role: string;
  731. }>("POST", () => {
  732. return `/api/welcome`;
  733. });
  734. const linkGithubProject = baseApi<
  735. {},
  736. {
  737. project_id: number;
  738. }
  739. >("GET", (pathParams) => {
  740. return `/api/oauth/projects/${pathParams.project_id}/github`;
  741. });
  742. const getGithubAccounts = baseApi<{}, {}>("GET", () => {
  743. return `/api/integrations/github-app/accounts`;
  744. });
  745. const logInUser = baseApi<{
  746. email: string;
  747. password: string;
  748. }>("POST", "/api/login");
  749. const logOutUser = baseApi("POST", "/api/logout");
  750. const provisionECR = baseApi<
  751. {
  752. ecr_name: string;
  753. aws_integration_id: number;
  754. },
  755. { id: number }
  756. >("POST", (pathParams) => {
  757. return `/api/projects/${pathParams.id}/provision/ecr`;
  758. });
  759. const provisionEKS = baseApi<
  760. {
  761. eks_name: string;
  762. aws_integration_id: number;
  763. machine_type: string;
  764. issuer_email: string;
  765. },
  766. { id: number }
  767. >("POST", (pathParams) => {
  768. return `/api/projects/${pathParams.id}/provision/eks`;
  769. });
  770. const registerUser = baseApi<{
  771. email: string;
  772. password: string;
  773. }>("POST", "/api/users");
  774. const rollbackChart = baseApi<
  775. {
  776. revision: number;
  777. },
  778. {
  779. id: number;
  780. name: string;
  781. namespace: string;
  782. cluster_id: number;
  783. }
  784. >("POST", (pathParams) => {
  785. let { id, name, cluster_id, namespace } = pathParams;
  786. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/releases/${name}/0/rollback`;
  787. });
  788. const uninstallTemplate = baseApi<
  789. {},
  790. {
  791. id: number;
  792. name: string;
  793. cluster_id: number;
  794. namespace: string;
  795. }
  796. >("DELETE", (pathParams) => {
  797. let { id, name, cluster_id, namespace } = pathParams;
  798. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/releases/${name}/0`;
  799. });
  800. const updateUser = baseApi<
  801. {
  802. rawKubeConfig?: string;
  803. allowedContexts?: string[];
  804. },
  805. { id: number }
  806. >("PUT", (pathParams) => {
  807. return `/api/users/${pathParams.id}`;
  808. });
  809. const upgradeChartValues = baseApi<
  810. {
  811. values: string;
  812. version?: string;
  813. },
  814. {
  815. id: number;
  816. name: string;
  817. namespace: string;
  818. cluster_id: number;
  819. }
  820. >("POST", (pathParams) => {
  821. let { id, name, cluster_id, namespace } = pathParams;
  822. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/releases/${name}/0/upgrade`;
  823. });
  824. const listConfigMaps = baseApi<
  825. {},
  826. {
  827. id: number;
  828. namespace: string;
  829. cluster_id: number;
  830. }
  831. >("GET", (pathParams) => {
  832. return `/api/projects/${pathParams.id}/clusters/${pathParams.cluster_id}/namespaces/${pathParams.namespace}/configmap/list`;
  833. });
  834. const getConfigMap = baseApi<
  835. {
  836. name: string;
  837. },
  838. {
  839. id: number;
  840. namespace: string;
  841. cluster_id: number;
  842. }
  843. >("GET", (pathParams) => {
  844. return `/api/projects/${pathParams.id}/clusters/${pathParams.cluster_id}/namespaces/${pathParams.namespace}/configmap`;
  845. });
  846. const createConfigMap = baseApi<
  847. {
  848. name: string;
  849. variables: Record<string, string>;
  850. secret_variables?: Record<string, string>;
  851. },
  852. {
  853. id: number;
  854. cluster_id: number;
  855. namespace: string;
  856. }
  857. >("POST", (pathParams) => {
  858. return `/api/projects/${pathParams.id}/clusters/${pathParams.cluster_id}/namespaces/${pathParams.namespace}/configmap/create`;
  859. });
  860. const updateConfigMap = baseApi<
  861. {
  862. name: string;
  863. variables: Record<string, string>;
  864. secret_variables?: Record<string, string>;
  865. },
  866. {
  867. id: number;
  868. cluster_id: number;
  869. namespace: string;
  870. }
  871. >("POST", (pathParams) => {
  872. let { id, cluster_id } = pathParams;
  873. return `/api/projects/${pathParams.id}/clusters/${pathParams.cluster_id}/namespaces/${pathParams.namespace}/configmap/update`;
  874. });
  875. const renameConfigMap = baseApi<
  876. {
  877. name: string;
  878. new_name: string;
  879. },
  880. {
  881. id: number;
  882. cluster_id: number;
  883. namespace: string;
  884. }
  885. >("POST", (pathParams) => {
  886. return `/api/projects/${pathParams.id}/clusters/${pathParams.cluster_id}/namespaces/${pathParams.namespace}/configmap/rename`;
  887. });
  888. const deleteConfigMap = baseApi<
  889. {
  890. name: string;
  891. },
  892. {
  893. id: number;
  894. namespace: string;
  895. cluster_id: number;
  896. }
  897. >("DELETE", (pathParams) => {
  898. return `/api/projects/${pathParams.id}/clusters/${pathParams.cluster_id}/namespaces/${pathParams.namespace}/configmap/delete`;
  899. });
  900. const createNamespace = baseApi<
  901. {
  902. name: string;
  903. },
  904. { id: number; cluster_id: number }
  905. >("POST", (pathParams) => {
  906. let { id, cluster_id } = pathParams;
  907. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/create`;
  908. });
  909. const deleteNamespace = baseApi<
  910. {
  911. name: string;
  912. },
  913. {
  914. id: number;
  915. cluster_id: number;
  916. }
  917. >("DELETE", (pathParams) => {
  918. let { id, cluster_id } = pathParams;
  919. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/delete`;
  920. });
  921. const deleteJob = baseApi<
  922. {},
  923. { name: string; namespace: string; id: number; cluster_id: number }
  924. >("DELETE", (pathParams) => {
  925. let { id, name, cluster_id, namespace } = pathParams;
  926. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/jobs/${name}`;
  927. });
  928. const stopJob = baseApi<
  929. {},
  930. { name: string; namespace: string; id: number; cluster_id: number }
  931. >("POST", (pathParams) => {
  932. let { id, name, namespace, cluster_id } = pathParams;
  933. return `/api/projects/${id}/clusters/${cluster_id}/namespaces/${namespace}/jobs/${name}/stop`;
  934. });
  935. const getAvailableRoles = baseApi<{}, { project_id: number }>(
  936. "GET",
  937. ({ project_id }) => `/api/projects/${project_id}/roles`
  938. );
  939. const updateInvite = baseApi<
  940. { kind: string },
  941. { project_id: number; invite_id: number }
  942. >(
  943. "POST",
  944. ({ project_id, invite_id }) =>
  945. `/api/projects/${project_id}/invites/${invite_id}`
  946. );
  947. const getCollaborators = baseApi<{}, { project_id: number }>(
  948. "GET",
  949. ({ project_id }) => `/api/projects/${project_id}/collaborators`
  950. );
  951. const updateCollaborator = baseApi<
  952. {
  953. kind: string;
  954. user_id: number;
  955. },
  956. { project_id: number }
  957. >("POST", ({ project_id }) => `/api/projects/${project_id}/roles`);
  958. const removeCollaborator = baseApi<{ user_id: number }, { project_id: number }>(
  959. "DELETE",
  960. ({ project_id }) => `/api/projects/${project_id}/roles`
  961. );
  962. const getPolicyDocument = baseApi<{}, { project_id: number }>(
  963. "GET",
  964. ({ project_id }) => `/api/projects/${project_id}/policy`
  965. );
  966. const createWebhookToken = baseApi<
  967. {},
  968. {
  969. project_id: number;
  970. chart_name: string;
  971. namespace: string;
  972. cluster_id: number;
  973. }
  974. >(
  975. "POST",
  976. ({ project_id, chart_name, namespace, cluster_id }) =>
  977. `/api/projects/${project_id}/clusters/${cluster_id}/namespaces/${namespace}/releases/${chart_name}/0/webhook`
  978. );
  979. const getUsage = baseApi<{}, { project_id: number }>(
  980. "GET",
  981. ({ project_id }) => `/api/projects/${project_id}/usage`
  982. );
  983. // Used for billing purposes
  984. const getCustomerToken = baseApi<{}, { project_id: number }>(
  985. "GET",
  986. ({ project_id }) => `/api/projects/${project_id}/billing/token`
  987. );
  988. const getHasBilling = baseApi<{}, { project_id: number }>(
  989. "GET",
  990. ({ project_id }) => `/api/projects/${project_id}/billing`
  991. );
  992. const getOnboardingState = baseApi<{}, { project_id: number }>(
  993. "GET",
  994. ({ project_id }) => `/api/projects/${project_id}/onboarding`
  995. );
  996. const saveOnboardingState = baseApi<{}, { project_id: number }>(
  997. "POST",
  998. ({ project_id }) => `/api/projects/${project_id}/onboarding`
  999. );
  1000. const getOnboardingInfra = baseApi<
  1001. {},
  1002. { project_id: number; registry_infra_id: number }
  1003. >(
  1004. "GET",
  1005. ({ project_id, registry_infra_id }) =>
  1006. `/api/projects/${project_id}/infras/${registry_infra_id}`
  1007. );
  1008. const getOnboardingRegistry = baseApi<
  1009. {},
  1010. { project_id: number; registry_connection_id: number }
  1011. >(
  1012. "GET",
  1013. ({ project_id, registry_connection_id }) =>
  1014. `/api/projects/${project_id}/registries/${registry_connection_id}`
  1015. );
  1016. const detectPorterAgent = baseApi<
  1017. {},
  1018. { project_id: number; cluster_id: number }
  1019. >(
  1020. "GET",
  1021. ({ project_id, cluster_id }) =>
  1022. `/api/projects/${project_id}/clusters/${cluster_id}/agent/detect`
  1023. );
  1024. const installPorterAgent = baseApi<
  1025. {},
  1026. { project_id: number; cluster_id: number }
  1027. >(
  1028. "POST",
  1029. ({ cluster_id, project_id }) =>
  1030. `/api/projects/${project_id}/clusters/${cluster_id}/agent/install`
  1031. );
  1032. const getKubeEvents = baseApi<
  1033. {
  1034. skip: number;
  1035. resource_type: string;
  1036. owner_type?: string;
  1037. owner_name?: string;
  1038. },
  1039. { project_id: number; cluster_id: number }
  1040. >("GET", ({ project_id, cluster_id }) => {
  1041. return `/api/projects/${project_id}/clusters/${cluster_id}/kube_events`;
  1042. });
  1043. const getKubeEvent = baseApi<
  1044. {},
  1045. { project_id: number; cluster_id: number; kube_event_id: number }
  1046. >(
  1047. "GET",
  1048. ({ project_id, cluster_id, kube_event_id }) =>
  1049. `/api/projects/${project_id}/clusters/${cluster_id}/kube_events/${kube_event_id}`
  1050. );
  1051. const getLogBuckets = baseApi<
  1052. {},
  1053. { project_id: number; cluster_id: number; kube_event_id: number }
  1054. >(
  1055. "GET",
  1056. ({ project_id, cluster_id, kube_event_id }) =>
  1057. `/api/projects/${project_id}/clusters/${cluster_id}/kube_events/${kube_event_id}/log_buckets`
  1058. );
  1059. const getLogBucketLogs = baseApi<
  1060. { timestamp: number },
  1061. { project_id: number; cluster_id: number; kube_event_id: number }
  1062. >(
  1063. "GET",
  1064. ({ project_id, cluster_id, kube_event_id }) =>
  1065. `/api/projects/${project_id}/clusters/${cluster_id}/kube_events/${kube_event_id}/logs`
  1066. );
  1067. // Bundle export to allow default api import (api.<method> is more readable)
  1068. export default {
  1069. checkAuth,
  1070. connectECRRegistry,
  1071. connectGCRRegistry,
  1072. connectDORegistry,
  1073. getAWSIntegration,
  1074. getGCPIntegration,
  1075. createAWSIntegration,
  1076. overwriteAWSIntegration,
  1077. createDOCR,
  1078. createDOKS,
  1079. createEmailVerification,
  1080. createGCPIntegration,
  1081. createGCR,
  1082. createGKE,
  1083. createInvite,
  1084. createNamespace,
  1085. createPasswordReset,
  1086. createPasswordResetVerify,
  1087. createPasswordResetFinalize,
  1088. createProject,
  1089. createConfigMap,
  1090. deleteCluster,
  1091. deleteConfigMap,
  1092. deleteInvite,
  1093. deleteNamespace,
  1094. deletePod,
  1095. deleteProject,
  1096. deleteRegistryIntegration,
  1097. deleteSlackIntegration,
  1098. updateNotificationConfig,
  1099. getNotificationConfig,
  1100. createSubdomain,
  1101. deployTemplate,
  1102. deployAddon,
  1103. destroyInfra,
  1104. detectBuildpack,
  1105. getBranchContents,
  1106. getBranches,
  1107. getMetadata,
  1108. postWelcome,
  1109. getChart,
  1110. getCharts,
  1111. getChartComponents,
  1112. getChartControllers,
  1113. getClusterIntegrations,
  1114. getClusters,
  1115. getCluster,
  1116. getClusterNodes,
  1117. getClusterNode,
  1118. getConfigMap,
  1119. getGHAWorkflowTemplate,
  1120. getGitRepoList,
  1121. getGitRepos,
  1122. getImageRepos,
  1123. getImageTags,
  1124. getInfra,
  1125. getInfraDesired,
  1126. getInfraCurrent,
  1127. getIngress,
  1128. getInvites,
  1129. getJobs,
  1130. getJobStatus,
  1131. getJobPods,
  1132. getPodByName,
  1133. getMatchingPods,
  1134. getMetrics,
  1135. getNamespaces,
  1136. getNGINXIngresses,
  1137. getOAuthIds,
  1138. getPodEvents,
  1139. getProcfileContents,
  1140. getProjectClusters,
  1141. getProjectRegistries,
  1142. getProjectRepos,
  1143. getProjects,
  1144. getPrometheusIsInstalled,
  1145. getRegistryIntegrations,
  1146. getReleaseToken,
  1147. getReleaseSteps,
  1148. getRepoIntegrations,
  1149. getSlackIntegrations,
  1150. getRepos,
  1151. getRevisions,
  1152. getTemplateInfo,
  1153. getTemplateUpgradeNotes,
  1154. getTemplates,
  1155. linkGithubProject,
  1156. getGithubAccounts,
  1157. listConfigMaps,
  1158. logInUser,
  1159. logOutUser,
  1160. provisionECR,
  1161. provisionEKS,
  1162. registerUser,
  1163. rollbackChart,
  1164. uninstallTemplate,
  1165. updateUser,
  1166. renameConfigMap,
  1167. updateConfigMap,
  1168. upgradeChartValues,
  1169. deleteJob,
  1170. stopJob,
  1171. updateInvite,
  1172. getAvailableRoles,
  1173. getCollaborators,
  1174. updateCollaborator,
  1175. removeCollaborator,
  1176. getPolicyDocument,
  1177. createWebhookToken,
  1178. getUsage,
  1179. getCustomerToken,
  1180. getHasBilling,
  1181. getOnboardingState,
  1182. saveOnboardingState,
  1183. getOnboardingInfra,
  1184. getOnboardingRegistry,
  1185. detectPorterAgent,
  1186. installPorterAgent,
  1187. getKubeEvents,
  1188. getKubeEvent,
  1189. getLogBuckets,
  1190. getLogBucketLogs,
  1191. };