import {z} from 'zod' export type GetApiApiV2SecretRotationsClickhouseCredentialsRotationNameRotationNameArgs = {projectId: string, secretPath: string, environment: string, rotationName: string}; export type GetApiApiV2SecretRotationsClickhouseCredentialsRotationNameRotationNameOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiV2SecretRotationsClickhouseCredentialsRotationNameRotationNameResponse = z.object({secretRotation: z.object({id: z.string(), name: z.string(), description: z.string().nullable().optional(), isAutoRotationEnabled: z.boolean().optional(), activeIndex: z.number().optional(), folderId: z.string(), connectionId: z.string(), createdAt: z.string(), updatedAt: z.string(), rotationInterval: z.number(), rotationStatus: z.string(), lastRotationAttemptedAt: z.string(), lastRotatedAt: z.string(), lastRotationJobId: z.string().nullable().optional(), nextRotationAt: z.string().nullable().optional(), isLastRotationManual: z.boolean().optional(), connection: z.object({app: z.literal("clickhouse"), name: z.string(), id: z.string()}), environment: z.object({slug: z.string(), name: z.string(), id: z.string()}), projectId: z.string(), folder: z.object({id: z.string(), path: z.string()}), rotateAtUtc: z.object({hours: z.number().gte(0).lte(23), minutes: z.number().gte(0).lte(59)}), lastRotationMessage: z.string().nullable().optional(), type: z.literal("clickhouse-credentials"), parameters: z.object({username1: z.string().min(1).max(256), username2: z.string().min(1).max(256)}), secretsMapping: z.object({username: z.string().min(1), password: z.string().min(1)})})}); 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 the specified ClickHouse Credentials Rotation by name, secret path, environment and project ID. * * GET /api/v2/secret-rotations/clickhouse-credentials/rotation-name/{rotationName} */ export const getApiApiV2SecretRotationsClickhouseCredentialsRotationNameRotationName = async (args: GetApiApiV2SecretRotationsClickhouseCredentialsRotationNameRotationNameArgs, options?: GetApiApiV2SecretRotationsClickhouseCredentialsRotationNameRotationNameOptions) => { const {baseUrl = "https://us.infisical.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.projectId != null) query.append("projectId", String(args.projectId)) if (args.secretPath != null) query.append("secretPath", String(args.secretPath)) if (args.environment != null) query.append("environment", String(args.environment)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/secret-rotations/clickhouse-credentials/rotation-name/${encodeURIComponent(String(args.rotationName))}${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(getApiApiV2SecretRotationsClickhouseCredentialsRotationNameRotationNameResponse, await res.json()) };