/** * Best-effort geolocation of a host to the cloud provider and region it * runs in. Resolves the host to its IP address(es) via DNS, then matches * those addresses against the public IP-range feeds each hyperscaler * publishes (AWS, Azure, GCP). Handy for placing a Databricks workspace * URL, but works for any host. * * The range feeds are large and change slowly, so each provider's feed * is cached for {@link RANGE_CACHE_TTL_MS} (24 hours) at two layers: an * on-disk copy under the OS temp dir (survives process restarts, shared * across processes) plus an in-process memoized parse. A provider whose * feed fails to load is skipped rather than failing the whole lookup - * the other providers still answer. * * Server-only: DNS resolution needs `node:dns` (via `./net.ts`), the * disk cache needs `node:fs` / `node:os` / `node:path`, and the feeds * are fetched with the global `fetch`. * * @module */ import { net } from "@dbx-tools/shared-core"; /** How long a fetched provider IP-range feed is reused before refetch. */ export declare const RANGE_CACHE_TTL_MS: number; /** Cloud hyperscaler a host resolves into. */ export declare enum CloudProvider { Aws = "aws", Azure = "azure", Gcp = "gcp" } /** * Where a host lives: the {@link CloudProvider}, the provider-native * `region` string (whatever the provider's feed calls it, e.g. * `"us-east-1"` on AWS, `"eastus2"` on Azure, `"us-east1"` on GCP), the * resolved `ip` that matched, and the `cidr` block it fell in. */ export interface CloudLocation { provider: CloudProvider; region: string; ip: string; cidr: string; } /** A parsed CIDR block tagged with the region it belongs to. */ interface RegionCidr extends net.Cidr { region: string; } /** One provider's parsed, region-tagged range table. */ interface ProviderRanges { provider: CloudProvider; ranges: RegionCidr[]; } /** * Resolve `input`'s host to a {@link CloudLocation}, or `null` when the * host can't be resolved or none of its IPs match a known cloud range. * `input` is any {@link net.UrlLike} - a URL, a bare host, or a `{ url }` * wrapper. * * The provider range feeds are cached for {@link RANGE_CACHE_TTL_MS}, so * only the first call in a 24-hour window pays the fetch cost; the DNS * lookup happens on every call. * * @example * await resolveCloudLocation("https://adb-1234567890.7.azuredatabricks.net"); * // { provider: CloudProvider.Azure, * // region: "eastus2", ip: "...", cidr: "..." } * * await resolveCloudLocation("dbc-abc123.cloud.databricks.com"); * // { provider: CloudProvider.Aws, * // region: "us-west-2", ip: "...", cidr: "..." } */ export declare function resolveCloudLocation(input: net.UrlLike): Promise; /** * Load every provider's region-tagged range table, each cached for * {@link RANGE_CACHE_TTL_MS}. Providers are loaded in parallel and a * feed that fails to fetch or parse is dropped (logged, not thrown) so * a single flaky feed never sinks the whole lookup. Exposed for callers * that want to match many IPs against one cached snapshot without a DNS * step per address. */ export declare function loadProviderRanges(): Promise; export {};