import {z} from 'zod' export type AWSS3CredentialUpdateRequest = {name: string, hostname?: string | undefined, username: string, secret?: (string | null) | undefined, verify_certs?: boolean | undefined, note?: string | undefined, appliance_ids: Array, cred_type?: 'amazons3' | undefined, region_code?: (string | null) | undefined, skip_validation?: boolean | undefined}; export type AWSS3GovCloudCredentialUpdateRequest = {name: string, hostname?: string | undefined, username: string, secret?: (string | null) | undefined, verify_certs?: boolean | undefined, note?: string | undefined, appliance_ids: Array, cred_type?: 'amazons3gov' | undefined, region_code?: (string | null) | undefined, skip_validation?: boolean | undefined}; export type S3CompatibleCredentialUpdateRequest = {name: string, hostname?: string | undefined, username: string, secret?: (string | null) | undefined, verify_certs?: boolean | undefined, note?: string | undefined, appliance_ids: Array, cred_type?: 's3_compatible' | undefined, region_code?: (string | null) | undefined, skip_validation?: boolean | undefined}; export type AzureCredentialUpdateRequest = {name: string, hostname?: string | undefined, username: string, secret?: (string | null) | undefined, verify_certs?: boolean | undefined, note?: string | undefined, appliance_ids: Array, cred_type?: 'azure' | undefined, region_code?: (string | null) | undefined}; export type GCSCredentialUpdateRequest = {name: string, hostname?: string | undefined, username: string, secret?: (string | null) | undefined, verify_certs?: boolean | undefined, note?: string | undefined, appliance_ids: Array, cred_type?: 'googles3' | undefined}; export type IBMCredentialUpdateRequest = {name: string, hostname?: string | undefined, username: string, secret?: (string | null) | undefined, verify_certs?: boolean | undefined, note?: string | undefined, appliance_ids: Array, cred_type?: 'ibmcos' | undefined}; export type HCPCredentialUpdateRequest = {name: string, hostname?: string | undefined, username: string, secret?: (string | null) | undefined, verify_certs?: boolean | undefined, note?: string | undefined, appliance_ids: Array, cred_type?: 'hcp' | undefined}; export type ViprCredentialUpdateRequest = {name: string, hostname?: string | undefined, username: string, secret?: (string | null) | undefined, verify_certs?: boolean | undefined, note?: string | undefined, appliance_ids: Array, cred_type?: 'vipr' | undefined}; export type PatchApiCloudCredentialsCredentialIdArgs = {credential_id: string, body: AWSS3CredentialUpdateRequest | AWSS3GovCloudCredentialUpdateRequest | S3CompatibleCredentialUpdateRequest | AzureCredentialUpdateRequest | GCSCredentialUpdateRequest | IBMCredentialUpdateRequest | HCPCredentialUpdateRequest | ViprCredentialUpdateRequest}; export type PatchApiCloudCredentialsCredentialIdOptions = {baseUrl?: string | undefined, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const failedUnreachableEdgeDto = z.object({edge_id: z.string(), task_id: z.string(), last_seen_at: z.string().nullable().optional()}); export const cloudCredentialUpdateResponseDto = z.object({task_ids: z.array(z.string()), failed_unreachable: z.array(failedUnreachableEdgeDto).optional()}); 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 Cloud Credential * * PATCH /cloud-credentials/{credential_id} */ export const patchApiCloudCredentialsCredentialId = async (args: PatchApiCloudCredentialsCredentialIdArgs, options?: PatchApiCloudCredentialsCredentialIdOptions) => { const {baseUrl = "https://am1.portal.api.nasuni.com", fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/cloud-credentials/${encodeURIComponent(String(args.credential_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(cloudCredentialUpdateResponseDto, await res.json()) };