Expand description
The cloud-provider range lifecycle: the fetch payload parsers, the
Azure ServiceTags URL extraction, the refresh cadence with the
single-flight gate, and the store-backed cache layers.
This is the pure half of the reference cloud handler
(guard_core/handlers/cloud_handler.py,
_cloud_provider_fetchers.py, _cloud_azure_fetch.py,
_cloud_provider_registry.py, cloud_ip_stores.py); the wire half -
the HTTP client driving the reference endpoints - lives in the facade’s
cloud_fetch and feeds these parsers.
§Payload parsers (one per provider, the reference fetcher bodies)
AWS json prefixes[]: entries with service == "AMAZON" only; the
ip_prefix network carries its region annotation; a malformed
prefix aborts the whole parse (the reference raise)
GCP json prefixes[]: ipv4Prefix or ipv6Prefix, scope annotation;
a malformed prefix aborts the whole parse (the reference raise)
CSV `DigitalOcean` / Linode: the first field per non-comment line;
invalid CIDRs are skipped, not fatal
Vultr json subnets[]: ip_prefix; invalid CIDRs are skipped
Azure json values[]: the "AzureCloud" entry's
properties.addressPrefixes; a malformed prefix fails the whole
parse (the reference raises into the fetcher's catch)§Azure ServiceTags URL extraction (the reference order)
- the
id="failoverLink"anchor’s href; - the newest URL matching the
ServiceTagspattern (newest = theServiceTags_Public_(\d{8})date, then the URL text); - any
https://download.microsoft.com/...jsonhref.
Every candidate must be https on download.microsoft.com, or it is
rejected.
§Refresh lifecycle
CloudRefreshCoordinator carries the reference stamp semantics: the
check asks CloudRefreshCoordinator::should_refresh
(now - last > interval, the reference CloudIpRefreshCheck), stamps
optimistically, schedules, and rolls the stamp back when scheduling
reports failure. CloudRefreshCoordinator::schedule_refresh is
single-flight: while one refresh is in flight, further calls are no-ops
returning false, so at most one refresh runs at a time.
refresh_provider_from_store walks the reference cache layers,
newest-to-oldest: the store (the section 08 cloud_ip_v2 /
cloud_ranges_v2 shapes) first - a hit decodes and installs in memory
with no network fetch; a miss fetches, and only a non-empty result is
cached and installed (an empty fetch is never cached and never touches
the provider’s previous ranges).
§Example
use guard_core_engine::cloud_fetch::{parse_aws_ranges, extract_azure_download_url};
// The AWS shape: only the AMAZON service entries, regions attached.
let payload = r#"{"prefixes": [
{"ip_prefix": "203.0.113.0/24", "region": "us-east-1", "service": "AMAZON"},
{"ip_prefix": "198.51.100.0/24", "region": "eu-west-1", "service": "EC2"}
]}"#;
let ranges = parse_aws_ranges(payload).expect("valid payload");
assert_eq!(ranges, vec![(String::from("203.0.113.0/24"), Some(String::from("us-east-1")))]);
// The Azure page scrape: the newest `ServiceTags` URL wins, on-host only.
let page = r#"<a id="failoverLink" href="https://download.microsoft.com/?x">x</a>"#;
assert_eq!(
extract_azure_download_url(page).as_deref(),
Some("https://download.microsoft.com/7/1/ServiceTags_Public_20260101.json")
);Structs§
- Azure
Download Candidate - A selected
ServiceTagsURL and how fresh the reference considers it. - Cloud
Refresh Coordinator - The refresh stamp plus the single-flight gate (the reference
CloudIpRefreshCheckstamp andCloudManager.schedule_refresh). - Payload
Error - A malformed provider payload: the JSON body did not carry the shape the parser reads.
Enums§
- Cloud
Refresh Outcome - What one
refresh_provider_from_storepass decided.
Constants§
- AZURE_
TRUSTED_ DOWNLOAD_ HOST - The trusted Azure download host (
_AZURE_TRUSTED_DOWNLOAD_HOST): every candidate URL must be https on this exact host.
Traits§
- Cloud
Range Store - The store seam behind the cache layers (the reference
CloudIpStoreProtocol; the Redis shape is the section 08cloud_ip_v2/cloud_ranges_v2payload, the in-memory shape is a map).
Functions§
- extract_
azure_ download_ url - The full extraction (
_extract_azure_download_url): failover link, then the newestServiceTagsURL, then any trusted JSON href. - extract_
failover_ link_ url - The failover-link arm (
_extract_failover_link_url): the first<a ... id="failoverLink" ...>anchor’s href, trusted URLs only. - extract_
generic_ json_ url - The generic-json arm (
_extract_generic_json_url): the firsthttps://download.microsoft.com/...jsonhref. - extract_
newest_ service_ tags_ url - The newest-
ServiceTagsarm (_extract_newest_service_tags_url): every URL matching theServiceTagsshape on the trusted host, the winner by(has date, date, url). - is_
trusted_ azure_ download_ url - Whether
urlis a trusted Azure download URL (_is_trusted_azure_ download_url): https scheme on the exact trusted host. - parse_
aws_ ranges - The AWS parser (
fetch_aws_ip_ranges): theprefixes[]entries withservice == "AMAZON"only, eachip_prefixcarrying itsregionas the annotation. - parse_
azure_ service_ tags - The
AzureServiceTagsparser (_select_azure_cloud_prefixes): thevalues[]entry namedAzureCloud, itsproperties.addressPrefixes. - parse_
csv_ ranges - The CSV parser (
_fetch_csv_prefix_networks, theDigitalOceanand Linode shape): the first field of every non-comment line; blank lines are skipped and an invalid prefix is skipped, not fatal. - parse_
gcp_ ranges - The GCP parser (
fetch_gcp_ip_ranges): theprefixes[]entries’ipv4Prefix/ipv6Prefixwith thescopeannotation. - parse_
service_ tags_ date - The
ServiceTags_Public_(\d{8})date ofurl(_parse_service_tags_date):Nonewhen the pattern is absent, the digits do not form a real calendar date, or the date lies in the future. - parse_
vultr_ ranges - The Vultr parser (
fetch_vultr_ip_ranges): thesubnets[]entries’ip_prefix; an invalid prefix is skipped, not fatal. - refresh_
provider_ from_ store - One provider’s refresh pass over the reference cache layers: the store first (a hit installs, no fetch), then the fetcher (only a non-empty result is cached and installed).
Type Aliases§
- Parsed
Ranges - The parsed provider ranges:
(network, region)pairs in thecrate::cloud_provider::CloudIpTableentry shape.