import {z} from 'zod' export type GetApiProjectsProjectIdKubernetesClustersArgs = {project_id: string, cluster_id?: string | undefined, cluster_name?: string | undefined, cluster_search_names?: Array | undefined, locations?: Array | undefined, states?: Array | undefined, versions?: Array | undefined, sort?: string | undefined, show_inactive?: boolean | undefined, next_token?: string | undefined, prev_token?: string | undefined}; export type GetApiProjectsProjectIdKubernetesClustersOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const oIDCAuthConfig = z.object({ca_cert: z.string().optional(), client_id: z.string().optional(), groups_claim: z.string().optional(), issuer_url: z.string().optional(), username_claim: z.string().optional(), username_prefix: z.string().optional()}); export const kubernetesClusterAuthConfig = z.object({oidc: oIDCAuthConfig.optional()}); export const kubernetesCluster = z.object({add_ons: z.array(z.string()), apiserver_extra_args: z.record(z.string(), z.string()).optional(), auth_config: kubernetesClusterAuthConfig.optional(), cluster_cidr: z.string().optional(), configuration: z.literal("ha"), controller_manager_extra_args: z.record(z.string(), z.string()).optional(), created_at: z.string(), dns_name: z.string(), id: z.string(), kubelogin_args: z.record(z.string(), z.string()), location: z.string(), name: z.string(), node_cidr_mask_size: z.number().int().optional(), node_pools: z.array(z.string()), private: z.boolean().optional(), project_id: z.string(), scheduler_extra_args: z.record(z.string(), z.string()).optional(), service_cluster_ip_range: z.string().optional(), state: z.string(), subnet_id: z.string(), updated_at: z.string(), version: z.string()}); export const listKubernetesClustersResponse = z.object({items: z.array(kubernetesCluster)}); 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 }; /** * Lists all Kubernetes clusters in the project and returns their details. * * GET /projects/{project_id}/kubernetes/clusters */ export const getApiProjectsProjectIdKubernetesClusters = async (args: GetApiProjectsProjectIdKubernetesClustersArgs, options?: GetApiProjectsProjectIdKubernetesClustersOptions) => { const {baseUrl = "https://api.cloud.crusoe.ai/v1", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.cluster_id != null) query.append("cluster_id", String(args.cluster_id)) if (args.cluster_name != null) query.append("cluster_name", String(args.cluster_name)) for (const item of args.cluster_search_names ?? []) query.append("cluster_search_names", String(item)) for (const item of args.locations ?? []) query.append("locations", String(item)) for (const item of args.states ?? []) query.append("states", String(item)) for (const item of args.versions ?? []) query.append("versions", String(item)) if (args.sort != null) query.append("sort", String(args.sort)) if (args.show_inactive != null) query.append("show_inactive", String(args.show_inactive)) if (args.next_token != null) query.append("next_token", String(args.next_token)) if (args.prev_token != null) query.append("prev_token", String(args.prev_token)) const url = `${baseUrl.replace(/\/+$/, '')}/projects/${encodeURIComponent(String(args.project_id))}/kubernetes/clusters${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(listKubernetesClustersResponse, await res.json()) };