import {z} from 'zod' export type SerialNumbergw = string; export type Next = string; export type GetApiNetworkMonitoringV1GatewaysSerialNumberDhcpPoolsArgs = {'serial-number': SerialNumbergw, sort?: string | undefined, limit?: number | undefined, next?: Next | undefined}; export type GetApiNetworkMonitoringV1GatewaysSerialNumberDhcpPoolsOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const countgw = z.number().int(); export const totalgw = z.number().int(); export const gatewayDhcpPoolListResponse = z.object({items: z.array(z.object({poolName: z.string().max(256), vlanId: z.number().int().gte(1).lte(4095), vlanName: z.string(), subnet: z.string(), leaseDuration: z.number().int().gte(0).lte(3155760000), poolSize: z.number().int(), currentLeases: z.number().int(), utilization: z.number().int(), availableAddresses: z.number().int()})), count: countgw, total: totalgw.optional(), next: z.string()}); 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 DHCP pools configured on the gateway * * GET /network-monitoring/v1/gateways/{serial-number}/dhcp-pools */ export const getApiNetworkMonitoringV1GatewaysSerialNumberDhcpPools = async (args: GetApiNetworkMonitoringV1GatewaysSerialNumberDhcpPoolsArgs, options?: GetApiNetworkMonitoringV1GatewaysSerialNumberDhcpPoolsOptions) => { const {baseUrl = "https://sso.common.cloud.hpe.com", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.sort != null) query.append("sort", String(args.sort)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.next != null) query.append("next", String(args.next)) if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/network-monitoring/v1/gateways/${encodeURIComponent(String(args['serial-number']))}/dhcp-pools${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(gatewayDhcpPoolListResponse, await res.json()) };