Skip to main content

Module cloudflare

Module cloudflare 

Source
Expand description

Cloudflare API client — publishes the QDP front-door DNS record (the easy-install path).

The front door is anchored by a single DNS TXT record at _qdp.<domain> (QDP §3.6): a domain owner adds one record and needs no server. For the many domains already on Cloudflare, doing that by hand is friction; this module drives Cloudflare’s v4 API to publish the same record turnkey.

This is a convenience path, not infrastructure: it holds only the user’s own Cloudflare API token (supplied by the principal), talks only to api.cloudflare.com, and carries only the public front-door record produced by crate::front_door::FrontDoorRecord::to_dns_txt — never a private key (QDP §5).

The network calls are host-only (#[cfg(not(target_arch = "wasm32"))]) and use reqwest::blocking (already a dependency — no new crates). The pure helpers (payload shaping, response parsing) carry the logic and are unit-tested without a network.

Structs§

CfConfig
Credentials for the user’s own Cloudflare account. Supplied by the principal; never persisted here.

Functions§

dns_record_payload
Shape the Cloudflare POST /zones/{zone}/dns_records body for a front-door record.
list_zones
List the zones (domains) the token can manage (GET /zones) → (zone_id, zone_name) pairs.
parse_verify_token
Validate a Cloudflare GET /user/tokens/verify response.
parse_zone_list
Parse a Cloudflare GET /zones response into (zone_id, zone_name) pairs.
provision_pages_project
Provision a Cloudflare Pages Project linked to a GitHub repository (POST /accounts/{account_id}/pages/projects).
provision_r2_bucket
Provision a Cloudflare R2 bucket (POST /accounts/{account_id}/r2/buckets).
provision_tunnel
Provision a Cloudflare Tunnel (POST /accounts/{account_id}/cfd_tunnel). Returns the generated Tunnel ID.
provision_worker
Provision a Cloudflare Worker script (PUT /accounts/{account_id}/workers/scripts/{script_name}).
publish_front_door
Publish the front-door TXT record (POST /zones/{zone}/dns_records) → the created record’s id.
route_tunnel_dns
Route DNS to a Cloudflare Tunnel (POST /zones/{zone_id}/dns_records).
verify_token
Verify a Cloudflare API token is valid and active (GET /user/tokens/verify).