import {z} from 'zod' export type HostUpdateSpec = {hostName?: string | undefined, ip?: string | undefined, port?: number | undefined, accessMode?: ('agent' | 'agentless') | undefined, username?: string | undefined, password?: string | undefined, availabilityZones?: (Array | null) | undefined, initiators?: (Array<{portName?: string | undefined, protocol?: ('iscsi' | 'fibre_channel' | 'nvmeof') | undefined}> | null) | undefined}; export type UpdateApiV1betaTenantIdHostHostsHostIdArgs = {body: HostUpdateSpec}; export type UpdateApiV1betaTenantIdHostHostsHostIdOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const hostRespSpec = z.object({id: z.string().optional(), createdAt: z.string().optional(), updatedAt: z.string().optional(), tenantId: z.string().optional(), hostName: z.string().optional(), osType: z.string().optional(), accessMode: z.string().optional(), ip: z.string().optional(), port: z.string().optional(), username: z.string().optional(), availabilityZones: z.array(z.string()).optional(), initiators: z.array(z.object({portName: z.string().optional(), protocol: z.enum(["iscsi", "fibre_channel", "nvmeof"]).optional()})).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 }; /** * Modify host details * * PUT /v1beta/{tenantId}/host/hosts/{hostId} */ export const updateApiV1betaTenantIdHostHostsHostId = async (args: UpdateApiV1betaTenantIdHostHostsHostIdArgs, options?: UpdateApiV1betaTenantIdHostHostsHostIdOptions) => { const {baseUrl = "https://localhost:50040", fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1beta/${encodeURIComponent(String(args.tenantId))}/host/hosts/${encodeURIComponent(String(args.hostId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(hostRespSpec, await res.json()) };