import {z} from 'zod' export type GetApiCloudCredentialsCredentialIdArgs = {credential_id: string}; export type GetApiCloudCredentialsCredentialIdOptions = {baseUrl?: string | undefined, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const nocCloudProvider = z.enum(["amazons3", "amazons3gov", "azure", "google", "googles3", "atmos", "ironmountain", "rackspace", "nirvanix", "synaptic", "castor", "delldx", "cloudone", "hp", "cleversafe", "vipr", "ibmcos", "hcp", "s3_compatible"]); export const nocCloudStorageProtocol = z.enum(["amazons3", "amazons3gov", "azure", "ibmcos", "hcp", "vipr", "cleversafe", "googles3", "s3_compatible"]); export const nocCloudVendor = z.enum(["customer", "private", "nasuni"]); export const cloudCredentialStatus = z.enum(["synced", "pending", "failed", "creating"]); export const cloudCredentialErrorDto = z.object({task_id: z.string(), action: z.string().nullable().optional(), can_acknowledge: z.boolean().optional(), code: z.number().int().nullable().optional(), error: z.string(), message: z.string(), detected_at: z.string()}); export const cloudCredentialVolumeDto = z.object({volume_id: z.string(), name: z.string()}); export const cloudCredentialDto = z.object({id: z.string(), appliance_id: z.string(), appliance_name: z.string(), appliance_serial: z.string(), appliance_credential_uuid: z.string(), name: z.string(), shortname: nocCloudProvider, cred_type: nocCloudStorageProtocol, hostname: z.string(), access_key: z.string(), vendor: nocCloudVendor, note: z.string().nullable().optional(), verify_certificates: z.boolean().optional(), certificate: z.string().nullable().optional(), region_code: z.string().nullable().optional(), is_stub: z.boolean().optional(), status: cloudCredentialStatus, error: cloudCredentialErrorDto.nullable().optional(), volumes: z.array(cloudCredentialVolumeDto).optional(), created_at: z.string(), updated_at: 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 }; /** * Get Cloud Credential by ID * * GET /cloud-credentials/{credential_id} */ export const getApiCloudCredentialsCredentialId = async (args: GetApiCloudCredentialsCredentialIdArgs, options?: GetApiCloudCredentialsCredentialIdOptions) => { const {baseUrl = "https://am1.portal.api.nasuni.com", fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() 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: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(cloudCredentialDto, await res.json()) };