import {z} from 'zod' export type GetApiV1EventGatewaysGatewayIdBackendClustersBackendClusterIdOptions = {baseUrl?: string | undefined, personalAccessToken?: string | undefined, fetch?: typeof fetch | undefined}; export const backendClusterName = z.string().min(1).max(255); export const backendClusterAuthenticationAnonymous = z.object({type: z.literal("anonymous")}); export const gatewaySecretReferenceOrLiteral = z.string().min(1); export const gatewaySecret = z.string().min(1); export const backendClusterAuthenticationSaslPlainSensitiveDataAware = z.object({type: z.literal("sasl_plain"), username: gatewaySecretReferenceOrLiteral, password: gatewaySecret.optional()}); export const backendClusterAuthenticationSaslScramSensitiveDataAware = z.object({type: z.literal("sasl_scram"), algorithm: z.enum(["sha256", "sha512"]), username: gatewaySecretReferenceOrLiteral, password: gatewaySecret.optional()}); export const backendClusterAuthenticationSaslAwsIam = z.object({type: z.literal("sasl_aws_iam"), sasl_aws_iam: z.discriminatedUnion("type", [z.object({type: z.literal("default_provider_chain")}), z.object({type: z.literal("assume_role"), arn: z.string().min(10).max(2048), session_name: z.string().optional()})])}); export const backendClusterAuthenticationSensitiveDataAwareScheme = z.discriminatedUnion("type", [backendClusterAuthenticationAnonymous, backendClusterAuthenticationSaslPlainSensitiveDataAware, backendClusterAuthenticationSaslScramSensitiveDataAware, backendClusterAuthenticationSaslAwsIam]); export const bootstrapServers = z.array(z.string().min(1)); export const backendClusterTLS = z.object({enabled: z.boolean(), insecure_skip_verify: z.boolean().optional(), ca_bundle: gatewaySecretReferenceOrLiteral.optional(), tls_versions: z.array(z.enum(["tls12", "tls13"])).optional(), client_identity: z.object({certificate: gatewaySecretReferenceOrLiteral, key: gatewaySecret}).optional()}); export const backendMetadataUpdateIntervalSeconds = z.number().int().gte(1).lte(43200); export const labels = z.record(z.string(), z.string().min(1).max(63)); export const createdAt = z.string(); export const updatedAt = z.string(); export const backendCluster = z.object({id: z.string(), name: backendClusterName, description: z.string().max(512).optional(), authentication: backendClusterAuthenticationSensitiveDataAwareScheme, insecure_allow_anonymous_virtual_cluster_auth: z.boolean().optional(), bootstrap_servers: bootstrapServers, tls: backendClusterTLS, metadata_update_interval_seconds: backendMetadataUpdateIntervalSeconds.optional(), labels: labels.optional(), created_at: createdAt, updated_at: updatedAt}); 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 }; /** * Get a Backend Cluster * * GET /v1/event-gateways/{gatewayId}/backend-clusters/{backendClusterId} * * Also accepts auth: systemAccountAccessToken, konnectAccessToken, serviceAccessToken */ export const getApiV1EventGatewaysGatewayIdBackendClustersBackendClusterId = async (options?: GetApiV1EventGatewaysGatewayIdBackendClustersBackendClusterIdOptions) => { const {baseUrl = "https://global.api.konghq.com", fetch: fetchFn = fetch, personalAccessToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (personalAccessToken !== undefined) headers.set('authorization', `Bearer ${personalAccessToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/event-gateways/${encodeURIComponent(String(args.gatewayId))}/backend-clusters/${encodeURIComponent(String(args.backendClusterId))}${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(backendCluster, await res.json()) };