Overview

Date: 2026-05-11

Time: 15:52

Overview

This module provides Cloudflare DNS management for FTL2 automation, specifically creating and updating A records via the Cloudflare v4 API. It's used in the ftl2-servercraft application to automatically point hostnames at provisioned game server IPs. It uses only stdlib (urllib.request) with no external HTTP dependencies.

Usage Patterns

The single public entry point is updatednsrecord:


from ftl2_servercraft.cloudflare import update_dns_record

update_dns_record(
    hostname="world1.servercraft2.com",
    ip="203.0.113.42",
    log=print,  # or any Callable[[str], None]
)

The log callback receives progress strings — callers typically pass a TUI logger or print. The function is idempotent: it creates the record if missing, updates it if the IP changed, and skips the API call entirely if the record already matches.

API and Configuration

| Parameter / Config | Description |

|---|---|

| CLOUDFLAREAPITOKEN | Required env var. Bearer token with DNS edit permissions for the target zone. Raises RuntimeError if missing. |

| hostname | FQDN for the A record (e.g. "world1.servercraft2.com") |

| ip | IPv4 address to point to |

| log | Callable[[str], None] — progress/status callback |

Records are created with TTL 300 seconds and proxied: False (DNS-only, no Cloudflare proxy).

Key Behaviors

Relationships