import {z} from 'zod' export type GetApiAccountsAccountIdentifierInfraprovidersInfraproviderIdentifierResourcesArgs = {accountIdentifier: string, infraprovider_identifier: string, acl_filter?: string | undefined, current_resource_identifier?: string | undefined}; export type GetApiAccountsAccountIdentifierInfraprovidersInfraproviderIdentifierResourcesOptions = {baseUrl: string, bearerAuth?: string | undefined, xApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const enumInfraProviderType = z.enum(["docker", "harness_gcp", "harness_cloud", "hybrid_vm_gcp", "hybrid_vm_aws"]); export const typesInfraProviderResource = z.object({config_identifier: z.string().optional(), config_name: z.string().optional(), cpu: z.string().nullable().optional(), created: z.number().int().optional(), deleted: z.number().int().nullable().optional(), disk: z.string().nullable().optional(), identifier: z.string().optional(), infra_provider_type: enumInfraProviderType.optional(), is_deleted: z.boolean().optional(), memory: z.string().nullable().optional(), metadata: z.record(z.string(), z.string()).nullable().optional(), name: z.string().optional(), network: z.string().nullable().optional(), region: z.string().optional(), space_path: z.string().optional(), updated: z.number().int().optional()}); export const getApiAccountsAccountIdentifierInfraprovidersInfraproviderIdentifierResourcesResponse = z.array(typesInfraProviderResource); 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 }; /** * List infraprovider resources * * GET /accounts/{accountIdentifier}/infraproviders/{infraprovider_identifier}/resources */ export const getApiAccountsAccountIdentifierInfraprovidersInfraproviderIdentifierResources = async (args: GetApiAccountsAccountIdentifierInfraprovidersInfraproviderIdentifierResourcesArgs, options: GetApiAccountsAccountIdentifierInfraprovidersInfraproviderIdentifierResourcesOptions) => { const {baseUrl, fetch: fetchFn = fetch, bearerAuth, xApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.acl_filter != null) query.append("acl_filter", String(args.acl_filter)) if (args.current_resource_identifier != null) query.append("current_resource_identifier", String(args.current_resource_identifier)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) if (xApiKey !== undefined) headers.set("x-api-key", xApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/accounts/${encodeURIComponent(String(args.accountIdentifier))}/infraproviders/${encodeURIComponent(String(args.infraprovider_identifier))}/resources${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(getApiAccountsAccountIdentifierInfraprovidersInfraproviderIdentifierResourcesResponse, await res.json()) };