import {z} from 'zod' export type AzureCredentialsRequest = {name: string, azure_subscription_id: string, azure_tenant_id: string}; export type CreateApiOrganizationOrganizationIdAzureCredentialsArgs = {organizationId: string, body: AzureCredentialsRequest}; export type CreateApiOrganizationOrganizationIdAzureCredentialsOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const awsStaticClusterCredentials = z.object({id: z.string(), name: z.string(), access_key_id: z.string(), object_type: z.literal("AWS")}); export const scalewayClusterCredentials = z.object({id: z.string(), name: z.string(), scaleway_access_key: z.string(), object_type: z.literal("SCW"), scaleway_project_id: z.string(), scaleway_organization_id: z.string()}); export const genericClusterCredentials = z.object({id: z.string(), name: z.string(), object_type: z.literal("OTHER")}); export const awsRoleClusterCredentials = z.object({id: z.string(), name: z.string(), role_arn: z.string(), object_type: z.literal("AWS_ROLE")}); export const azureStaticClusterCredentials = z.object({id: z.string(), name: z.string(), azure_subscription_id: z.string(), azure_tenant_id: z.string(), object_type: z.literal("AZURE"), azure_application_id: z.string(), azure_application_object_id: z.string()}); export const gcpStaticClusterCredentials = z.object({id: z.string(), name: z.string(), object_type: z.literal("GCP")}); export const clusterCredentials = z.discriminatedUnion("object_type", [awsStaticClusterCredentials, scalewayClusterCredentials, genericClusterCredentials, awsRoleClusterCredentials, azureStaticClusterCredentials, gcpStaticClusterCredentials]); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Create Azure credentials set * * POST /organization/{organizationId}/azure/credentials * * Also accepts auth: bearerAuth */ export const createApiOrganizationOrganizationIdAzureCredentials = async (args: CreateApiOrganizationOrganizationIdAzureCredentialsArgs, options?: CreateApiOrganizationOrganizationIdAzureCredentialsOptions) => { const {baseUrl = "https://api.qovery.com", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("Authorization", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/organization/${encodeURIComponent(String(args.organizationId))}/azure/credentials${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(clusterCredentials, await res.json()) };