import {z} from 'zod' export type GetApiV2InfraEnvsInfraEnvIdHostsHostIdInstructionsArgs = {infra_env_id: string, host_id: string, timestamp?: number | undefined, discovery_agent_version?: string | undefined}; export type GetApiV2InfraEnvsInfraEnvIdHostsHostIdInstructionsOptions = {baseUrl?: string | undefined, agentAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const stepType = z.enum(["connectivity-check", "execute", "inventory", "install", "free-network-addresses", "dhcp-lease-allocate", "api-vip-connectivity-check", "tang-connectivity-check", "ntp-synchronizer", "installation-disk-speed-check", "container-image-availability", "domain-resolution", "stop-installation", "logs-gather", "next-step-runner", "upgrade-agent", "download-boot-artifacts", "reboot-for-reclaim", "verify-vips"]); export const step = z.object({step_type: stepType.optional(), step_id: z.string().optional(), args: z.array(z.string()).optional()}); export const steps = z.object({next_instruction_seconds: z.number().int().optional(), post_step_action: z.enum(["exit", "continue"]).optional(), instructions: z.array(step).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 }; /** * Retrieves the next operations that the host agent needs to perform. * * GET /v2/infra-envs/{infra_env_id}/hosts/{host_id}/instructions */ export const getApiV2InfraEnvsInfraEnvIdHostsHostIdInstructions = async (args: GetApiV2InfraEnvsInfraEnvIdHostsHostIdInstructionsArgs, options?: GetApiV2InfraEnvsInfraEnvIdHostsHostIdInstructionsOptions) => { const {baseUrl = "http://api.openshift.com/api/assisted-install", fetch: fetchFn = fetch, agentAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.timestamp != null) query.append("timestamp", String(args.timestamp)) if (args.discovery_agent_version != null) headers.set("discovery_agent_version", String(args.discovery_agent_version)) if (agentAuth !== undefined) headers.set("X-Secret-Key", agentAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v2/infra-envs/${encodeURIComponent(String(args.infra_env_id))}/hosts/${encodeURIComponent(String(args.host_id))}/instructions${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(steps, await res.json()) };