useCloudProvider.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import { z } from "zod";
  2. import api from "shared/api";
  3. export const connectToAwsAccount = async ({
  4. targetArn,
  5. externalId,
  6. projectId,
  7. }: {
  8. targetArn: string;
  9. externalId: string;
  10. projectId: number;
  11. }): Promise<void> => {
  12. await api.createAWSIntegration(
  13. "<token>",
  14. {
  15. aws_target_arn: targetArn,
  16. aws_external_id: externalId,
  17. },
  18. { id: projectId }
  19. );
  20. };
  21. export const connectToAzureAccount = async ({
  22. subscriptionId,
  23. clientId,
  24. tenantId,
  25. servicePrincipalKey,
  26. projectId,
  27. }: {
  28. subscriptionId: string;
  29. clientId: string;
  30. tenantId: string;
  31. servicePrincipalKey: string;
  32. projectId: number;
  33. }): Promise<string> => {
  34. const res = await api.createAzureIntegration(
  35. "<token",
  36. {
  37. azure_subscription_id: subscriptionId,
  38. azure_client_id: clientId,
  39. azure_tenant_id: tenantId,
  40. service_principal_key: servicePrincipalKey,
  41. },
  42. { id: projectId }
  43. );
  44. const parsed = await z
  45. .object({
  46. cloud_provider_credentials_id: z.string(),
  47. })
  48. .parseAsync(res.data);
  49. return parsed.cloud_provider_credentials_id;
  50. };
  51. export const connectToGCPAccount = async ({
  52. projectId,
  53. serviceAccountKey,
  54. gcpProjectId,
  55. }: {
  56. projectId: number;
  57. serviceAccountKey: string;
  58. gcpProjectId: string;
  59. }): Promise<string> => {
  60. const res = await api.createGCPIntegration(
  61. "<token",
  62. {
  63. gcp_key_data: serviceAccountKey,
  64. gcp_project_id: gcpProjectId,
  65. },
  66. { project_id: projectId }
  67. );
  68. const parsed = await z
  69. .object({
  70. cloud_provider_credentials_id: z.string(),
  71. })
  72. .parseAsync(res.data);
  73. return parsed.cloud_provider_credentials_id;
  74. };