Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(proxy): tolerate every Cloudflare custom hostname status (#80800)

Yasend03b7d228674
diff --git a/posthog/temporal/proxy_service/cloudflare.py b/posthog/temporal/proxy_service/cloudflare.py
index c7050be4dac6..47918f1b4ced 100644
--- a/posthog/temporal/proxy_service/cloudflare.py
+++ b/posthog/temporal/proxy_service/cloudflare.py
@@ -29,25 +29,66 @@ class CloudflareAPIError(Exception):
return any(err.get("code") == 10000 for err in self.errors) or "rate limit" in str(self).lower()
-class CustomHostnameSSLStatus(str, Enum):
- """SSL certificate status for a Custom Hostname."""
+class CloudflareStatus(str, Enum):
+ """Base for Cloudflare status enums.
+
+ Cloudflare extends these sets without notice, and a status we do not model is still
+ worth reporting, so an unmodeled value becomes a member carrying the raw string
+ rather than raising and taking down the caller.
+ """
+
+ @classmethod
+ def _missing_(cls, value: object) -> t.Optional["CloudflareStatus"]:
+ if not isinstance(value, str):
+ return None
+ unmodeled = str.__new__(cls, value)
+ unmodeled._name_ = value.upper()
+ unmodeled._value_ = value
+ return unmodeled
+
+
+class CustomHostnameSSLStatus(CloudflareStatus):
+ """SSL certificate status for a Custom Hostname.
+
+ Names the states a proxy of ours reaches. Cloudflare's staging and backup certificate
+ states are absent on purpose, since our flow never asks for them, and the base class
+ keeps them parseable if one ever arrives.
+ """
INITIALIZING = "initializing"
PENDING_VALIDATION = "pending_validation"
+ DELETED = "deleted"
PENDING_ISSUANCE = "pending_issuance"
PENDING_DEPLOYMENT = "pending_deployment"
- ACTIVE = "active"
PENDING_DELETION = "pending_deletion"
- DELETED = "deleted"
+ PENDING_EXPIRATION = "pending_expiration"
+ EXPIRED = "expired"
+ ACTIVE = "active"
+ INITIALIZING_TIMED_OUT = "initializing_timed_out"
+ VALIDATION_TIMED_OUT = "validation_timed_out"
+ ISSUANCE_TIMED_OUT = "issuance_timed_out"
+ DEPLOYMENT_TIMED_OUT = "deployment_timed_out"
+ DELETION_TIMED_OUT = "deletion_timed_out"
+ DEACTIVATING = "deactivating"
+ INACTIVE = "inactive"
-class CustomHostnameStatus(str, Enum):
- """Status for a Custom Hostname."""
+class CustomHostnameStatus(CloudflareStatus):
+ """Status for a Custom Hostname.
+
+ Cloudflare's `test_*` states are absent on purpose, since we never create test hostnames.
+ """
ACTIVE = "active"
PENDING = "pending"
+ ACTIVE_REDEPLOYING = "active_redeploying"
MOVED = "moved"
+ PENDING_DELETION = "pending_deletion"
DELETED = "deleted"
+ PENDING_BLOCKED = "pending_blocked"
+ PENDING_MIGRATION = "pending_migration"
+ PENDING_PROVISIONED = "pending_provisioned"
+ PROVISIONED = "provisioned"
BLOCKED = "blocked"
diff --git a/posthog/temporal/proxy_service/test/test_cloudflare.py b/posthog/temporal/proxy_service/test/test_cloudflare.py
index b47eb11df5ed..460b0b6c8a51 100644
--- a/posthog/temporal/proxy_service/test/test_cloudflare.py
+++ b/posthog/temporal/proxy_service/test/test_cloudflare.py
@@ -1,8 +1,61 @@
-from django.test import TestCase
+from django.test import SimpleTestCase, TestCase
from parameterized import parameterized
-from posthog.temporal.proxy_service.cloudflare import CloudflareAPIError
+from posthog.temporal.proxy_service.cloudflare import (
+ CloudflareAPIError,
+ CustomHostnameSSLStatus,
+ CustomHostnameStatus,
+ _parse_hostname,
+)
+
+# Every status Cloudflare can send, which is a superset of what the enums name. Re-derive with:
+# curl -sL https://raw.githubusercontent.com/cloudflare/api-schemas/main/openapi.json | jq -r \
+# '.components.schemas."tls-certificates-and-hostnames_ssl".oneOf[0].properties.status.enum[]'
+# curl -sL https://raw.githubusercontent.com/cloudflare/api-schemas/main/openapi.json | jq -r \
+# '.components.schemas."tls-certificates-and-hostnames_status-3".enum[]'
+CLOUDFLARE_SSL_STATUSES = [
+ "initializing",
+ "pending_validation",
+ "deleted",
+ "pending_issuance",
+ "pending_deployment",
+ "pending_deletion",
+ "pending_expiration",
+ "expired",
+ "active",
+ "initializing_timed_out",
+ "validation_timed_out",
+ "issuance_timed_out",
+ "deployment_timed_out",
+ "deletion_timed_out",
+ "pending_cleanup",
+ "staging_deployment",
+ "staging_active",
+ "deactivating",
+ "inactive",
+ "backup_issued",
+ "holding_deployment",
+]
+
+CLOUDFLARE_HOSTNAME_STATUSES = [
+ "active",
+ "pending",
+ "active_redeploying",
+ "moved",
+ "pending_deletion",
+ "deleted",
+ "pending_blocked",
+ "pending_migration",
+ "pending_provisioned",
+ "test_pending",
+ "test_active",
+ "test_active_apex",
+ "test_blocked",
+ "test_failed",
+ "provisioned",
+ "blocked",
+]
class TestCloudflareAPIErrorIsRateLimited(TestCase):
@@ -18,3 +71,43 @@ class TestCloudflareAPIErrorIsRateLimited(TestCase):
def test_is_rate_limited(self, _name, message, errors, expected):
error = CloudflareAPIError(message, errors=errors)
self.assertEqual(error.is_rate_limited(), expected)
+
+
+def _hostname_payload(status="active", ssl_status="active"):
+ return {
+ "id": "abc123",
+ "hostname": "p.example.com",
+ "status": status,
+ "ssl": {"status": ssl_status, "validation_errors": []},
+ }
+
+
+class TestParseHostnameStatuses(SimpleTestCase):
+ @parameterized.expand([(status,) for status in CLOUDFLARE_SSL_STATUSES])
+ def test_parses_every_ssl_status_cloudflare_can_send(self, ssl_status):
+ info = _parse_hostname(_hostname_payload(ssl_status=ssl_status))
+ self.assertEqual(info.ssl.status.value, ssl_status)
+
+ @parameterized.expand([(status,) for status in CLOUDFLARE_HOSTNAME_STATUSES])
+ def test_parses_every_hostname_status_cloudflare_can_send(self, status):
+ info = _parse_hostname(_hostname_payload(status=status))
+ self.assertEqual(info.status.value, status)
+
+ @parameterized.expand(
+ [
+ ("ssl", {"ssl_status": "some_future_status"}, "some_future_status"),
+ ("hostname", {"status": "some_future_status"}, "some_future_status"),
+ ]
+ )
+ def test_keeps_the_raw_value_of_an_unmodeled_status(self, field, payload_kwargs, expected):
+ info = _parse_hostname(_hostname_payload(**payload_kwargs))
+ parsed = info.ssl.status if field == "ssl" else info.status
+ self.assertEqual(parsed.value, expected)
+
+ def test_an_unmodeled_ssl_status_is_not_active(self):
+ info = _parse_hostname(_hostname_payload(ssl_status="some_future_status"))
+ self.assertNotEqual(info.ssl.status, CustomHostnameSSLStatus.ACTIVE)
+
+ def test_an_unmodeled_hostname_status_is_not_active(self):
+ info = _parse_hostname(_hostname_payload(status="some_future_status"))
+ self.assertNotEqual(info.status, CustomHostnameStatus.ACTIVE)