import {z} from 'zod' export type AntiAffinityGroupRef = {id?: string | undefined}; export type PublicIpAssignment = 'inet4' | 'dual' | 'none'; export type Labels = {[key: string]: string}; export type SecurityGroupRef = {id?: string | undefined}; export type ElasticIpRef = {id?: string | undefined}; export type ZoneName = 'ch-dk-2' | 'de-muc-1' | 'ch-gva-2' | 'at-vie-1' | 'de-fra-1' | 'bg-sof-1' | 'at-vie-2' | 'hr-zag-1'; export type InstanceType = {id?: string | undefined, size?: ('large' | 'huge' | 'jumbo' | 'medium' | 'mega' | 'small' | 'extra-large' | 'titan48c' | 'titan' | 'micro' | 'colossus' | 'tiny') | undefined, family?: ('gpu3' | 'gpua30' | 'gpu3080ti' | 'gpu2' | 'gpu' | 'memory' | 'gpua5000' | 'gpub300' | 'gpurtx6000pro' | 'storage' | 'standard' | 'colossus' | 'cpu') | undefined, cpus?: number | undefined, gpus?: number | undefined, authorized?: boolean | undefined, memory?: number | undefined, zones?: Array | undefined}; export type Template = {'application-consistent-snapshot-enabled'?: boolean | undefined, maintainer?: string | undefined, description?: string | undefined, 'ssh-key-enabled'?: boolean | undefined, family?: string | undefined, name?: string | undefined, 'default-user'?: string | undefined, size?: number | undefined, 'password-enabled'?: boolean | undefined, build?: string | undefined, checksum?: string | undefined, 'boot-mode'?: ('legacy' | 'uefi') | undefined, id?: string | undefined, zones?: Array | undefined, url?: string | undefined, version?: string | undefined, 'created-at'?: string | undefined, visibility?: ('private' | 'public') | undefined}; export type InstanceState = 'expunging' | 'starting' | 'destroying' | 'running' | 'stopping' | 'stopped' | 'migrating' | 'error' | 'destroyed'; export type SshKey = {name?: string | undefined, fingerprint?: string | undefined}; export type Manager = {id?: string | undefined, type?: ('sks-nodepool' | 'instance-pool') | undefined}; export type DeployTargetRef = {id?: string | undefined}; export type SnapshotRef = {id?: string | undefined}; export type Instance = {'application-consistent-snapshot-enabled'?: boolean | undefined, 'anti-affinity-groups'?: Array | undefined, 'public-ip-assignment'?: PublicIpAssignment | undefined, labels?: Labels | undefined, 'security-groups'?: Array | undefined, 'elastic-ips'?: Array | undefined, name?: string | undefined, 'instance-type'?: InstanceType | undefined, 'private-networks'?: (Array<{id?: string | undefined, 'mac-address'?: string | undefined}>) | undefined, template?: Template | undefined, state?: InstanceState | undefined, 'secureboot-enabled'?: boolean | undefined, 'ssh-key'?: SshKey | undefined, 'user-data'?: string | undefined, 'mac-address'?: string | undefined, manager?: Manager | undefined, 'tpm-enabled'?: boolean | undefined, 'deploy-target'?: DeployTargetRef | undefined, 'ipv6-address'?: string | undefined, id?: string | undefined, snapshots?: Array | undefined, 'disk-size'?: number | undefined, 'disk-encrypted'?: boolean | undefined, 'ssh-keys'?: Array | undefined, 'created-at'?: string | undefined, 'public-ip'?: string | undefined}; export type UpdateApiSecurityGroupIdAttachArgs = {id: string, body: {instance: Instance}}; export type UpdateApiSecurityGroupIdAttachOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const operation = z.object({id: z.string().optional(), reason: z.enum(["incorrect", "unknown", "unavailable", "forbidden", "busy", "fault", "partial", "not-found", "interrupted", "unsupported", "conflict"]).optional(), reference: z.object({id: z.string().optional(), link: z.string().optional(), command: z.string().optional()}).optional(), message: z.string().optional(), state: z.enum(["failure", "pending", "success", "timeout"]).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 }; /** * Attach a Compute instance to a Security Group * * PUT /security-group/{id}:attach */ export const updateApiSecurityGroupIdAttach = async (args: UpdateApiSecurityGroupIdAttachArgs, options?: UpdateApiSecurityGroupIdAttachOptions) => { const {baseUrl = "https://api-ch-gva-2.exoscale.com/v2", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/security-group/${encodeURIComponent(String(args.id))}:attach${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(operation, await res.json()) };