import {z} from 'zod' export type GcsServiceKey = {auth_provider_x509_cert_url: string, auth_uri: string, client_email: string, client_id: string, client_x509_cert_url: string, private_key: string, private_key_id: string, project_id: string, token_uri: string, type: string, universe_domain: string}; export type StorageCredential = {'access-key-id': string, 'external-id'?: (string | null) | undefined, 'secret-access-key': string, 'credential-type': 'access-key', type: 's3'} | {'external-id'?: (string | null) | undefined, 'credential-type': 'aws-system-identity', type: 's3'} | {'access-key-id': string, 'account-id': string, 'secret-access-key': string, token: string, 'credential-type': 'cloudflare-r2', type: 's3'} | {'client-id': string, 'client-secret': string, 'credential-type': 'client-credentials', 'tenant-id': string, type: 'az'} | {'credential-type': 'shared-access-key', key: string, type: 'az'} | {'credential-type': 'azure-system-identity', type: 'az'} | {'credential-type': 'service-account-key', key: GcsServiceKey, type: 'gcs'} | {'credential-type': 'gcp-system-identity', type: 'gcs'}; export type UpdateWarehouseCredentialRequest = {'new-storage-credential'?: (StorageCredential | null) | undefined}; export type CreateApiManagementV1WarehouseWarehouseIdStorageCredentialArgs = {warehouse_id: string, body: UpdateWarehouseCredentialRequest}; export type CreateApiManagementV1WarehouseWarehouseIdStorageCredentialOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const tabularDeleteProfile = z.union([z.object({type: z.literal("hard")}), z.object({"expiration-seconds": z.number().int(), type: z.literal("soft")})]); export const managedBy = z.enum(["self-managed", "instance-admin"]); export const warehouseStatus = z.enum(["active", "inactive"]); export const s3CredentialType = z.enum(["access-key", "aws-system-identity", "cloudflare-r2"]); export const azCredentialType = z.enum(["client-credentials", "shared-access-key", "azure-system-identity"]); export const gcsCredentialType = z.enum(["service-account-key", "gcp-system-identity"]); export const storageCredentialType = z.union([z.object({"credential-type": s3CredentialType, type: z.literal("s3")}), z.object({"credential-type": azCredentialType, type: z.literal("az")}), z.object({"credential-type": gcsCredentialType, type: z.literal("gcs")})]); export const storageLayoutTabularTemplate = z.string(); export const storageLayoutNamespaceTemplate = z.string(); export const storageLayout = z.union([z.object({type: z.literal("default")}), z.object({tabular: storageLayoutTabularTemplate, type: z.literal("tabular-only")}), z.object({namespace: storageLayoutNamespaceTemplate, tabular: storageLayoutTabularTemplate, type: z.literal("full-hierarchy")})]); export const endpointMode = z.union([z.object({type: z.literal("default")}), z.object({region: z.string(), type: z.literal("regional")}), z.object({type: z.literal("workspace-private-link")})]); export const topLevelFolder = z.enum(["Files", "Tables"]); export const s3Flavor = z.enum(["aws", "s3-compat"]); export const s3UrlStyleDetectionMode = z.enum(["path", "virtual_host", "auto"]); export const storageProfile = z.union([z.object({"account-name": z.string(), "allow-alternative-protocols": z.boolean().optional(), "authority-host": z.string().nullable().optional(), filesystem: z.string(), host: z.string().nullable().optional(), "key-prefix": z.string().nullable().optional(), "sas-enabled": z.boolean().optional(), "sas-token-validity-seconds": z.number().int().gte(0).nullable().optional(), "storage-layout": storageLayout.nullable().optional(), type: z.literal("adls")}), z.object({"authority-host": z.string().nullable().optional(), "directory-rel-path": z.string().nullable().optional(), "endpoint-mode": endpointMode.optional(), "lakehouse-id": z.string(), "sas-enabled": z.boolean().optional(), "sas-token-validity-seconds": z.number().int().gte(0).nullable().optional(), "storage-layout": storageLayout.nullable().optional(), "top-level-folder": topLevelFolder.optional(), "workspace-id": z.string(), type: z.literal("onelake")}), z.object({"allow-alternative-protocols": z.boolean().nullable().optional(), "assume-role-arn": z.string().nullable().optional(), "aws-kms-key-arn": z.string().nullable().optional(), bucket: z.string(), endpoint: z.string().nullable().optional(), flavor: s3Flavor.optional(), "key-prefix": z.string().nullable().optional(), "legacy-md5-behavior": z.boolean().nullable().optional(), "path-style-access": z.boolean().nullable().optional(), "push-s3-delete-disabled": z.boolean().optional(), region: z.string(), "remote-signing-enabled": z.boolean().optional(), "remote-signing-url-style": s3UrlStyleDetectionMode.optional(), "storage-layout": storageLayout.nullable().optional(), "sts-enabled": z.boolean(), "sts-endpoint": z.string().nullable().optional(), "sts-role-arn": z.string().nullable().optional(), "sts-session-tags": z.record(z.string(), z.string()).optional(), "sts-token-validity-seconds": z.number().int().gte(0).optional(), type: z.literal("s3")}), z.object({bucket: z.string(), "key-prefix": z.string().nullable().optional(), "storage-layout": storageLayout.nullable().optional(), "sts-enabled": z.boolean().optional(), type: z.literal("gcs")})]); export const getWarehouseResponse = z.object({"allowed-format-versions": z.array(z.number().int()), "default-format-version": z.number().int().nullable().optional(), "delete-profile": tabularDeleteProfile, id: z.string(), "managed-by": managedBy.optional(), name: z.string(), "project-id": z.string(), protected: z.boolean(), status: warehouseStatus, "storage-credential-type": storageCredentialType.nullable().optional(), "storage-profile": storageProfile, "updated-at": z.string().nullable().optional(), "warehouse-id": z.string()}); 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 }; /** * Update Storage Credential * * POST /management/v1/warehouse/{warehouse_id}/storage-credential */ export const createApiManagementV1WarehouseWarehouseIdStorageCredential = async (args: CreateApiManagementV1WarehouseWarehouseIdStorageCredentialArgs, options?: CreateApiManagementV1WarehouseWarehouseIdStorageCredentialOptions) => { const {baseUrl = "https://localhost", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/management/v1/warehouse/${encodeURIComponent(String(args.warehouse_id))}/storage-credential${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(getWarehouseResponse, await res.json()) };