import {z} from 'zod' export type AzureMetricsIntegrationAzurePrincipal = {client_id?: string | undefined, tenant_id?: string | undefined}; export type AzureMetricsIntegrationAzureResourceType = {metric_names?: Array | undefined, name?: string | undefined}; export type AzureMetricsIntegrationAzureScrapeConfig = {locations?: Array | undefined, resource_types?: Array | undefined, subscription_ids?: Array | undefined}; export type Configv1AzureMetricsIntegration = {count_metrics_enabled?: boolean | undefined, created_at?: string | undefined, name: string, principal?: AzureMetricsIntegrationAzurePrincipal | undefined, propagate_tags?: boolean | undefined, scrape_config?: AzureMetricsIntegrationAzureScrapeConfig | undefined, slug?: string | undefined, updated_at?: string | undefined, usage_metrics_enabled?: boolean | undefined}; export type ConfigV1UpdateAzureMetricsIntegrationBody = {azure_metrics_integration?: Configv1AzureMetricsIntegration | undefined, create_if_missing?: boolean | undefined, dry_run?: boolean | undefined}; export type UpdateApiApiV1ConfigAzureMetricsIntegrationsSlugArgs = {slug: string, body: ConfigV1UpdateAzureMetricsIntegrationBody}; export type UpdateApiApiV1ConfigAzureMetricsIntegrationsSlugOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const azureMetricsIntegrationAzurePrincipal = z.object({client_id: z.string().optional(), tenant_id: z.string().optional()}); export const azureMetricsIntegrationAzureResourceType = z.object({metric_names: z.array(z.string()).optional(), name: z.string().optional()}); export const azureMetricsIntegrationAzureScrapeConfig = z.object({locations: z.array(z.string()).optional(), resource_types: z.array(azureMetricsIntegrationAzureResourceType).optional(), subscription_ids: z.array(z.string()).optional()}); export const configv1AzureMetricsIntegration = z.object({count_metrics_enabled: z.boolean().optional(), created_at: z.string().optional(), name: z.string(), principal: azureMetricsIntegrationAzurePrincipal.optional(), propagate_tags: z.boolean().optional(), scrape_config: azureMetricsIntegrationAzureScrapeConfig.optional(), slug: z.string().optional(), updated_at: z.string().optional(), usage_metrics_enabled: z.boolean().optional()}); export const configv1UpdateAzureMetricsIntegrationResponse = z.object({azure_metrics_integration: configv1AzureMetricsIntegration.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 }; /** * PUT /api/v1/config/azure-metrics-integrations/{slug} */ export const updateApiApiV1ConfigAzureMetricsIntegrationsSlug = async (args: UpdateApiApiV1ConfigAzureMetricsIntegrationsSlugArgs, options?: UpdateApiApiV1ConfigAzureMetricsIntegrationsSlugOptions) => { const {baseUrl = "https://tenant.chronosphere.io", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("API-Token", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/config/azure-metrics-integrations/${encodeURIComponent(String(args.slug))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(configv1UpdateAzureMetricsIntegrationResponse, await res.json()) };