import {z} from 'zod' export type GetApiDbaasExternalEndpointRsyslogEndpointIdArgs = {'endpoint-id': string}; export type GetApiDbaasExternalEndpointRsyslogEndpointIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const enumExternalEndpointTypes = z.enum(["prometheus", "opensearch", "rsyslog", "datadog", "elasticsearch"]); export const enumRsyslogFormat = z.enum(["custom", "rfc3164", "rfc5424"]); export const dbaasEndpointRsyslogOptionalFields = z.object({server: z.string().min(4).max(255).optional(), port: z.number().int().gte(1).lte(65535).optional(), tls: z.boolean().optional(), format: enumRsyslogFormat.optional(), logline: z.string().min(1).max(512).optional(), sd: z.string().max(1024).optional(), "max-message-size": z.number().int().gte(2048).lte(2147483647).optional()}); export const dbaasExternalEndpointRsyslogOutput = z.object({name: z.string().optional(), type: enumExternalEndpointTypes.optional(), id: z.string().optional(), settings: dbaasEndpointRsyslogOptionalFields.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 }; /** * GET /dbaas-external-endpoint-rsyslog/{endpoint-id} */ export const getApiDbaasExternalEndpointRsyslogEndpointId = async (args: GetApiDbaasExternalEndpointRsyslogEndpointIdArgs, options?: GetApiDbaasExternalEndpointRsyslogEndpointIdOptions) => { const {baseUrl = "https://api-ch-gva-2.exoscale.com/v2", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/dbaas-external-endpoint-rsyslog/${encodeURIComponent(String(args['endpoint-id']))}${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(dbaasExternalEndpointRsyslogOutput, await res.json()) };