import {z} from 'zod' export type CreateApiProjectsProjectIdKubernetesClustersClusterIdGetCredentialsArgs = {project_id: string, cluster_id: string, auth_type?: ('oidc' | 'admin_cert') | undefined}; export type CreateApiProjectsProjectIdKubernetesClustersClusterIdGetCredentialsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const kubernetesAuthenticationDetails = z.object({cluster_address: z.string(), cluster_ca_certificate: z.string(), cluster_name: z.string(), kube_config: z.string().optional(), user_client_certificate: z.string(), user_client_key: z.string(), user_name: 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 }; /** * Returns credentials for the user to authenticate to the cluster. * * POST /projects/{project_id}/kubernetes/clusters/{cluster_id}/get-credentials */ export const createApiProjectsProjectIdKubernetesClustersClusterIdGetCredentials = async (args: CreateApiProjectsProjectIdKubernetesClustersClusterIdGetCredentialsArgs, options?: CreateApiProjectsProjectIdKubernetesClustersClusterIdGetCredentialsOptions) => { 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.auth_type != null) query.append("auth_type", String(args.auth_type)) const url = `${baseUrl.replace(/\/+$/, '')}/projects/${encodeURIComponent(String(args.project_id))}/kubernetes/clusters/${encodeURIComponent(String(args.cluster_id))}/get-credentials${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(kubernetesAuthenticationDetails, await res.json()) };