dex-connector-cloudflare 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dex_connector_cloudflare-0.1.0.dist-info/METADATA +55 -0
- dex_connector_cloudflare-0.1.0.dist-info/RECORD +18 -0
- dex_connector_cloudflare-0.1.0.dist-info/WHEEL +4 -0
- dex_connectors/cloudflare/__init__.py +52 -0
- dex_connectors/cloudflare/_generated/__init__.py +2 -0
- dex_connectors/cloudflare/_generated/config.py +25 -0
- dex_connectors/cloudflare/_generated/connection.py +131 -0
- dex_connectors/cloudflare/_generated/definitions.py +57 -0
- dex_connectors/cloudflare/_generated/mock.py +113 -0
- dex_connectors/cloudflare/_generated/models.py +90 -0
- dex_connectors/cloudflare/_generated/steps.py +134 -0
- dex_connectors/cloudflare/client.py +385 -0
- dex_connectors/cloudflare/cloudflaremock/__init__.py +59 -0
- dex_connectors/cloudflare/connection.py +49 -0
- dex_connectors/cloudflare/dex-connector.json +82 -0
- dex_connectors/cloudflare/models.py +33 -0
- dex_connectors/cloudflare/py.typed +0 -0
- dex_connectors/cloudflare/steps.py +38 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: dex-connector-cloudflare
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Cloudflare connector for Dex Flows
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Requires-Python: >=3.11
|
|
7
|
+
Requires-Dist: dex-connectors-sdk==0.1.0
|
|
8
|
+
Requires-Dist: dex-python-sdk>=1.28.0
|
|
9
|
+
Requires-Dist: httpx>=0.27
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
|
|
12
|
+
# Cloudflare connector for Python
|
|
13
|
+
|
|
14
|
+
Install with `pip install dex-connector-cloudflare==0.1.0`. The package requires
|
|
15
|
+
`dex-connectors-sdk==0.1.0` and `dex-python-sdk>=1.28.0`, and implements the
|
|
16
|
+
manifest operations `listZones` (Query) and `purgeCacheByURLs` (Mutation) with
|
|
17
|
+
the same branches, defaults, and failure classification as the Go module.
|
|
18
|
+
|
|
19
|
+
## Operations
|
|
20
|
+
|
|
21
|
+
| Operation | Factory | Happy branch | Optional branches |
|
|
22
|
+
| --- | --- | --- | --- |
|
|
23
|
+
| `listZones` | `new_list_zones_step` | `listed` | `providerRejected`, `invalidResponse`, `defect` |
|
|
24
|
+
| `purgeCacheByURLs` | `new_purge_cache_by_urls_step` | `purged` | `notFound`, `providerRejected`, `invalidResponse`, `defect` |
|
|
25
|
+
|
|
26
|
+
`listZones` reads the first page of `/zones` and requires `success: true` with
|
|
27
|
+
a `result` list. `purgeCacheByURLs` posts 1 through 30 absolute HTTP or HTTPS
|
|
28
|
+
URLs without user information to `/zones/<zoneId>/purge_cache`; repeating the
|
|
29
|
+
same purge has the same effect, so retries are safe. Acceptance does not
|
|
30
|
+
guarantee a cache miss.
|
|
31
|
+
|
|
32
|
+
Both operations retry on 408, 409, 429, 5xx, and transport failures. A
|
|
33
|
+
`success: false` envelope selects `providerRejected`; HTTP 404 selects
|
|
34
|
+
`notFound` for purges; other statuses select `providerRejected` with
|
|
35
|
+
authentication (401), authorization (403), not-found (404), or validation
|
|
36
|
+
(400, 422) kinds.
|
|
37
|
+
|
|
38
|
+
## Authorization
|
|
39
|
+
|
|
40
|
+
Create a Dex Web connection named `cloudflare` as described in the
|
|
41
|
+
[connector README](../README.md#authorization). The API token travels only in
|
|
42
|
+
the `Authorization: Bearer` header and is resolved for every attempt.
|
|
43
|
+
|
|
44
|
+
## Example
|
|
45
|
+
|
|
46
|
+
[`examples/cloudflare_lookup`](examples/cloudflare_lookup/flow.py) lists the
|
|
47
|
+
first zone page. Run the Worker with
|
|
48
|
+
`uv run python -m examples.cloudflare_lookup.worker` after `dexcli dev` has
|
|
49
|
+
loaded a project containing the `cloudflare` connection.
|
|
50
|
+
|
|
51
|
+
## Tests
|
|
52
|
+
|
|
53
|
+
`cloudflaremock.Mock` scripts both operations and defaults to the manifest
|
|
54
|
+
answers. Run `uv run pytest tests` for provider parity and manifest contract
|
|
55
|
+
checks.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
dex_connectors/cloudflare/__init__.py,sha256=CzN1z-V7LeHhCb5QRr7qZSAK6EtKVW-3TKJFU_Pepk4,1332
|
|
2
|
+
dex_connectors/cloudflare/client.py,sha256=0yAFGvLnvFMYnFVH38YukeQQRKYSnZMwwaAwL5YK5jg,14348
|
|
3
|
+
dex_connectors/cloudflare/connection.py,sha256=URma9LHtuDD7-v55l2s39lDzFkYzPL5GXtvdx2U-Jd8,2373
|
|
4
|
+
dex_connectors/cloudflare/dex-connector.json,sha256=AerzkmvfzvTGcmdCMfp-oUqzgPHyw26e8WCfnyT-NnY,1893
|
|
5
|
+
dex_connectors/cloudflare/models.py,sha256=iXrb6bjr9y5Fm9-SKHaY_mdk2nUD5FV7UHZZyY3ox1A,1199
|
|
6
|
+
dex_connectors/cloudflare/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
+
dex_connectors/cloudflare/steps.py,sha256=l7P4UfkXEEGdnMVPBZRtp2XHmcGr3V93DtKevNJyl3Y,1505
|
|
8
|
+
dex_connectors/cloudflare/_generated/__init__.py,sha256=ShfMsAGzSt4xuhCaf20ibgtfXl4pXomZb00ovUw6CeI,66
|
|
9
|
+
dex_connectors/cloudflare/_generated/config.py,sha256=qim3Xbb7DSdnypdCuP5UtK0JfQBhf33dY_QpeUu6S-E,566
|
|
10
|
+
dex_connectors/cloudflare/_generated/connection.py,sha256=IV0JAwWTVl_cA1M65Wz2uwNZ20AQvKmyJg8gdx49Dy4,5548
|
|
11
|
+
dex_connectors/cloudflare/_generated/definitions.py,sha256=yV2bTrUoaI8SZDHpNjwZPS15WJbS2iQxi2pIHlJAnqI,2046
|
|
12
|
+
dex_connectors/cloudflare/_generated/mock.py,sha256=BopcWWB2BRgk8FrA8vw6vGg5iX_6JYyE0lZbSzMKk3g,5257
|
|
13
|
+
dex_connectors/cloudflare/_generated/models.py,sha256=6DCSI6xTUsj7igtIIPsT3bO2t5vTvUNM78TmBZ_i3kg,2856
|
|
14
|
+
dex_connectors/cloudflare/_generated/steps.py,sha256=TwFnxDXhGGwRUnZDY-q-YmkHWwCbLMkiD3sXF5LixHs,5810
|
|
15
|
+
dex_connectors/cloudflare/cloudflaremock/__init__.py,sha256=LgedFGomCu8B_diVZZU0aL7-ICki_YCcBi9otELjIQE,2620
|
|
16
|
+
dex_connector_cloudflare-0.1.0.dist-info/METADATA,sha256=-OPCKnKHRZ8u1x19-6pQjiw6SLHkmASfFcbVojNA7_U,2286
|
|
17
|
+
dex_connector_cloudflare-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
18
|
+
dex_connector_cloudflare-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Cloudflare zone listing and URL cache purge operations for Dex connector Steps."""
|
|
4
|
+
|
|
5
|
+
from .client import (
|
|
6
|
+
CONNECTOR_ID,
|
|
7
|
+
DEFECT,
|
|
8
|
+
INVALID_RESPONSE,
|
|
9
|
+
LIST_ZONES_DEFINITION,
|
|
10
|
+
LISTED,
|
|
11
|
+
NOT_FOUND,
|
|
12
|
+
PROVIDER_REJECTED,
|
|
13
|
+
PURGE_CACHE_BY_URLS_DEFINITION,
|
|
14
|
+
PURGED,
|
|
15
|
+
Client,
|
|
16
|
+
Config,
|
|
17
|
+
Credentials,
|
|
18
|
+
ListZonesOperation,
|
|
19
|
+
PurgeCacheByURLsOperation,
|
|
20
|
+
)
|
|
21
|
+
from .connection import Connection, new_connection, new_connection_with_operations, new_project_connection
|
|
22
|
+
from .models import CachePurge, ListZonesInput, PurgeCacheByURLsInput, PurgeRequest, Zone, ZonesPage
|
|
23
|
+
from .steps import new_list_zones_step, new_purge_cache_by_urls_step
|
|
24
|
+
|
|
25
|
+
__all__ = [
|
|
26
|
+
"CachePurge",
|
|
27
|
+
"Client",
|
|
28
|
+
"Config",
|
|
29
|
+
"Connection",
|
|
30
|
+
"Credentials",
|
|
31
|
+
"ListZonesInput",
|
|
32
|
+
"ListZonesOperation",
|
|
33
|
+
"PurgeCacheByURLsInput",
|
|
34
|
+
"PurgeCacheByURLsOperation",
|
|
35
|
+
"PurgeRequest",
|
|
36
|
+
"Zone",
|
|
37
|
+
"ZonesPage",
|
|
38
|
+
"new_connection",
|
|
39
|
+
"new_connection_with_operations",
|
|
40
|
+
"new_list_zones_step",
|
|
41
|
+
"new_project_connection",
|
|
42
|
+
"new_purge_cache_by_urls_step",
|
|
43
|
+
"CONNECTOR_ID",
|
|
44
|
+
"DEFECT",
|
|
45
|
+
"INVALID_RESPONSE",
|
|
46
|
+
"LIST_ZONES_DEFINITION",
|
|
47
|
+
"LISTED",
|
|
48
|
+
"NOT_FOUND",
|
|
49
|
+
"PROVIDER_REJECTED",
|
|
50
|
+
"PURGE_CACHE_BY_URLS_DEFINITION",
|
|
51
|
+
"PURGED",
|
|
52
|
+
]
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
# ruff: noqa
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
|
|
7
|
+
from dex_connectors.sdk import SecretString
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@dataclass(frozen=True, slots=True)
|
|
11
|
+
class Config:
|
|
12
|
+
|
|
13
|
+
base_url: str = "https://api.cloudflare.com/client/v4"
|
|
14
|
+
timeout_seconds: float = 15
|
|
15
|
+
max_response_bytes: int = 2097152
|
|
16
|
+
|
|
17
|
+
setattr(Config, '__module__', 'dex_connectors.cloudflare.client')
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass(frozen=True, slots=True)
|
|
21
|
+
class Credentials:
|
|
22
|
+
|
|
23
|
+
api_token: SecretString
|
|
24
|
+
|
|
25
|
+
setattr(Credentials, '__module__', 'dex_connectors.cloudflare.client')
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
# ruff: noqa
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
import httpx
|
|
8
|
+
from dex_connectors.sdk import ConnectionRef, Mutation, Query, Call, SecretString
|
|
9
|
+
from dex_connectors.sdk.projectconfig import ConnectionKey, LoadedProject
|
|
10
|
+
|
|
11
|
+
from ..client import Client, Config, Credentials
|
|
12
|
+
from .definitions import CONNECTOR_ID, LIST_ZONES_DEFINITION, PURGE_CACHE_BY_URLS_DEFINITION
|
|
13
|
+
from ..models import CachePurge, ListZonesInput, PurgeCacheByURLsInput, ZonesPage
|
|
14
|
+
|
|
15
|
+
class Connection:
|
|
16
|
+
|
|
17
|
+
__slots__ = ('_purge_cache_by_urls', '_list_zones', '_client', 'reference')
|
|
18
|
+
|
|
19
|
+
def __init__(self,
|
|
20
|
+
reference: ConnectionRef,
|
|
21
|
+
purge_cache_by_urls: Mutation[PurgeCacheByURLsInput, CachePurge],
|
|
22
|
+
list_zones: Query[ListZonesInput, ZonesPage],
|
|
23
|
+
client: Client | None = None,
|
|
24
|
+
) -> None:
|
|
25
|
+
reference.validate()
|
|
26
|
+
if reference.provider != CONNECTOR_ID or purge_cache_by_urls is None or list_zones is None:
|
|
27
|
+
raise ValueError("Cloudflare connection provider and operations are required")
|
|
28
|
+
if purge_cache_by_urls.definition().operation != PURGE_CACHE_BY_URLS_DEFINITION.operation:
|
|
29
|
+
raise ValueError("Cloudflare connection operation identity differs")
|
|
30
|
+
if list_zones.definition().operation != LIST_ZONES_DEFINITION.operation:
|
|
31
|
+
raise ValueError("Cloudflare connection operation identity differs")
|
|
32
|
+
self.reference = reference
|
|
33
|
+
self._purge_cache_by_urls = purge_cache_by_urls
|
|
34
|
+
self._list_zones = list_zones
|
|
35
|
+
self._client = client
|
|
36
|
+
|
|
37
|
+
def purge_cache_by_urls(self) -> Mutation[PurgeCacheByURLsInput, CachePurge]:
|
|
38
|
+
return self._purge_cache_by_urls
|
|
39
|
+
|
|
40
|
+
def list_zones(self) -> Query[ListZonesInput, ZonesPage]:
|
|
41
|
+
return self._list_zones
|
|
42
|
+
|
|
43
|
+
async def aclose(self) -> None:
|
|
44
|
+
if self._client is not None:
|
|
45
|
+
await self._client.aclose()
|
|
46
|
+
|
|
47
|
+
def __repr__(self) -> str:
|
|
48
|
+
return "cloudflare.Connection([REDACTED])"
|
|
49
|
+
|
|
50
|
+
def __reduce__(self) -> tuple[object, ...]:
|
|
51
|
+
raise TypeError("Cloudflare connections cannot be serialized")
|
|
52
|
+
|
|
53
|
+
setattr(Connection, '__module__', 'dex_connectors.cloudflare.connection')
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def new_connection(client: Client, reference: ConnectionRef) -> Connection:
|
|
57
|
+
if client is None:
|
|
58
|
+
raise ValueError("Cloudflare client is required")
|
|
59
|
+
return Connection(reference, client.purge_cache_by_urls(), client.list_zones(), client)
|
|
60
|
+
|
|
61
|
+
setattr(new_connection, '__module__', 'dex_connectors.cloudflare.connection')
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def new_connection_with_operations(
|
|
65
|
+
purge_cache_by_urls: Mutation[PurgeCacheByURLsInput, CachePurge],
|
|
66
|
+
list_zones: Query[ListZonesInput, ZonesPage],
|
|
67
|
+
reference: ConnectionRef,
|
|
68
|
+
) -> Connection:
|
|
69
|
+
return Connection(reference, purge_cache_by_urls, list_zones)
|
|
70
|
+
|
|
71
|
+
setattr(new_connection_with_operations, '__module__', 'dex_connectors.cloudflare.connection')
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class _ProjectCredentialSource:
|
|
75
|
+
|
|
76
|
+
def __init__(self, project: LoadedProject, key: ConnectionKey) -> None:
|
|
77
|
+
self.project = project
|
|
78
|
+
self.key = key
|
|
79
|
+
|
|
80
|
+
async def resolve(self, call: Call) -> Credentials:
|
|
81
|
+
material = await self.project.resolve_credential(self.key, str(call.id))
|
|
82
|
+
api_token = material.get("api_token")
|
|
83
|
+
if not isinstance(api_token, str) or not api_token:
|
|
84
|
+
raise ValueError("Cloudflare credential api_token is required")
|
|
85
|
+
return Credentials(SecretString(api_token))
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def new_project_connection(
|
|
89
|
+
project: LoadedProject, connection_name: str, http_client: httpx.AsyncClient | None = None
|
|
90
|
+
) -> Connection:
|
|
91
|
+
if project is None:
|
|
92
|
+
raise ValueError("Cloudflare connection requires loaded project configuration")
|
|
93
|
+
reference = ConnectionRef(CONNECTOR_ID, connection_name)
|
|
94
|
+
reference.validate()
|
|
95
|
+
key = ConnectionKey(CONNECTOR_ID, connection_name)
|
|
96
|
+
matching = [
|
|
97
|
+
entry
|
|
98
|
+
for entry in project.configuration.connections
|
|
99
|
+
if entry.connector_id == CONNECTOR_ID and entry.connection_name == connection_name
|
|
100
|
+
]
|
|
101
|
+
if len(matching) != 1:
|
|
102
|
+
raise ValueError("Cloudflare project connection is missing or duplicated")
|
|
103
|
+
if matching[0].provider != CONNECTOR_ID:
|
|
104
|
+
raise ValueError("Cloudflare project connection provider differs")
|
|
105
|
+
config = _decode_config(matching[0].configuration)
|
|
106
|
+
client = Client(config, _ProjectCredentialSource(project, key), http_client)
|
|
107
|
+
return new_connection(client, reference)
|
|
108
|
+
|
|
109
|
+
setattr(new_project_connection, '__module__', 'dex_connectors.cloudflare.connection')
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def _decode_config(value: dict[str, Any]) -> Config:
|
|
113
|
+
if set(value) - {"baseUrl", "timeout", "maxResponseBytes"}:
|
|
114
|
+
raise ValueError("Cloudflare configuration has unknown fields")
|
|
115
|
+
config_arguments: dict[str, Any] = {}
|
|
116
|
+
if "baseUrl" in value:
|
|
117
|
+
base_url = value["baseUrl"]
|
|
118
|
+
if not (isinstance(base_url, str)):
|
|
119
|
+
raise ValueError("Cloudflare configuration baseUrl has an invalid type")
|
|
120
|
+
config_arguments['base_url'] = base_url
|
|
121
|
+
if "timeout" in value:
|
|
122
|
+
timeout = value["timeout"]
|
|
123
|
+
if not (type(timeout) is int):
|
|
124
|
+
raise ValueError("Cloudflare configuration timeout has an invalid type")
|
|
125
|
+
config_arguments['timeout_seconds'] = timeout / 1_000_000_000
|
|
126
|
+
if "maxResponseBytes" in value:
|
|
127
|
+
max_response_bytes = value["maxResponseBytes"]
|
|
128
|
+
if not (type(max_response_bytes) is int):
|
|
129
|
+
raise ValueError("Cloudflare configuration maxResponseBytes has an invalid type")
|
|
130
|
+
config_arguments['max_response_bytes'] = max_response_bytes
|
|
131
|
+
return Config(**config_arguments)
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
# ruff: noqa
|
|
4
|
+
|
|
5
|
+
from datetime import timedelta
|
|
6
|
+
|
|
7
|
+
from dex_connectors.sdk import (
|
|
8
|
+
BranchDefinition,
|
|
9
|
+
MutationDefinition,
|
|
10
|
+
OperationRef,
|
|
11
|
+
QueryDefinition,
|
|
12
|
+
RetryPolicy,
|
|
13
|
+
StepDefaults,
|
|
14
|
+
default_connector_step_execute_retry_policy,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
CONNECTOR_ID = "cloudflare"
|
|
18
|
+
PROVIDER = "cloudflare"
|
|
19
|
+
PURGE_CACHE_BY_URLS_OPERATION_ID = "purgeCacheByURLs"
|
|
20
|
+
LIST_ZONES_OPERATION_ID = "listZones"
|
|
21
|
+
DEFECT = "defect"
|
|
22
|
+
INVALID_RESPONSE = "invalidResponse"
|
|
23
|
+
LISTED = "listed"
|
|
24
|
+
NOT_FOUND = "notFound"
|
|
25
|
+
PROVIDER_REJECTED = "providerRejected"
|
|
26
|
+
PURGED = "purged"
|
|
27
|
+
|
|
28
|
+
PURGE_CACHE_BY_URLS_DEFINITION = MutationDefinition(
|
|
29
|
+
OperationRef(CONNECTOR_ID, PURGE_CACHE_BY_URLS_OPERATION_ID),
|
|
30
|
+
(
|
|
31
|
+
BranchDefinition(PURGED, "Purge specific URLs from a Cloudflare zone; repeating the same purge has the same cache-removal effect.", False),
|
|
32
|
+
BranchDefinition(NOT_FOUND, "The requested resource does not exist or is inaccessible.", True),
|
|
33
|
+
BranchDefinition(PROVIDER_REJECTED, "The provider rejected the request.", True),
|
|
34
|
+
BranchDefinition(INVALID_RESPONSE, "The provider returned malformed or oversized JSON.", True),
|
|
35
|
+
BranchDefinition(DEFECT, "Local input or connection credentials are invalid.", True),
|
|
36
|
+
),
|
|
37
|
+
StepDefaults(
|
|
38
|
+
timedelta(seconds=30),
|
|
39
|
+
2,
|
|
40
|
+
execute_retry=default_connector_step_execute_retry_policy(),
|
|
41
|
+
),
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
LIST_ZONES_DEFINITION = QueryDefinition(
|
|
45
|
+
OperationRef(CONNECTOR_ID, LIST_ZONES_OPERATION_ID),
|
|
46
|
+
(
|
|
47
|
+
BranchDefinition(LISTED, "List the first page of Cloudflare zones.", False),
|
|
48
|
+
BranchDefinition(PROVIDER_REJECTED, "The provider rejected the request.", True),
|
|
49
|
+
BranchDefinition(INVALID_RESPONSE, "The provider returned malformed or oversized JSON.", True),
|
|
50
|
+
BranchDefinition(DEFECT, "Local input or connection credentials are invalid.", True),
|
|
51
|
+
),
|
|
52
|
+
StepDefaults(
|
|
53
|
+
timedelta(seconds=30),
|
|
54
|
+
2,
|
|
55
|
+
execute_retry=default_connector_step_execute_retry_policy(),
|
|
56
|
+
),
|
|
57
|
+
)
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
# ruff: noqa
|
|
4
|
+
|
|
5
|
+
from datetime import datetime
|
|
6
|
+
|
|
7
|
+
from dex_connectors.sdk import ConnectionRef, Failure, FailureKind
|
|
8
|
+
from dex_connectors.sdk.connectormock import Case, Mutation, Query
|
|
9
|
+
|
|
10
|
+
from ..connection import Connection, new_connection_with_operations
|
|
11
|
+
from ..models import CachePurge, ListZonesInput, PurgeCacheByURLsInput, PurgeRequest, Zone, ZonesPage
|
|
12
|
+
from .definitions import CONNECTOR_ID, DEFECT, INVALID_RESPONSE, LISTED, LIST_ZONES_DEFINITION, NOT_FOUND, PROVIDER_REJECTED, PURGED, PURGE_CACHE_BY_URLS_DEFINITION
|
|
13
|
+
|
|
14
|
+
def purge_cache_by_urls_purged(value: CachePurge, failure: Failure | None = None) -> Case[CachePurge]:
|
|
15
|
+
return Case.branch_result(PURGED, value, failure)
|
|
16
|
+
|
|
17
|
+
setattr(purge_cache_by_urls_purged, '__module__', "dex_connectors.cloudflare.cloudflaremock")
|
|
18
|
+
|
|
19
|
+
def purge_cache_by_urls_not_found(value: CachePurge, failure: Failure | None = None) -> Case[CachePurge]:
|
|
20
|
+
return Case.branch_result(NOT_FOUND, value, failure)
|
|
21
|
+
|
|
22
|
+
setattr(purge_cache_by_urls_not_found, '__module__', "dex_connectors.cloudflare.cloudflaremock")
|
|
23
|
+
|
|
24
|
+
def purge_cache_by_urls_provider_rejected(value: CachePurge, failure: Failure | None = None) -> Case[CachePurge]:
|
|
25
|
+
return Case.branch_result(PROVIDER_REJECTED, value, failure)
|
|
26
|
+
|
|
27
|
+
setattr(purge_cache_by_urls_provider_rejected, '__module__', "dex_connectors.cloudflare.cloudflaremock")
|
|
28
|
+
|
|
29
|
+
def purge_cache_by_urls_invalid_response(value: CachePurge, failure: Failure | None = None) -> Case[CachePurge]:
|
|
30
|
+
return Case.branch_result(INVALID_RESPONSE, value, failure)
|
|
31
|
+
|
|
32
|
+
setattr(purge_cache_by_urls_invalid_response, '__module__', "dex_connectors.cloudflare.cloudflaremock")
|
|
33
|
+
|
|
34
|
+
def purge_cache_by_urls_defect(value: CachePurge, failure: Failure | None = None) -> Case[CachePurge]:
|
|
35
|
+
return Case.branch_result(DEFECT, value, failure)
|
|
36
|
+
|
|
37
|
+
setattr(purge_cache_by_urls_defect, '__module__', "dex_connectors.cloudflare.cloudflaremock")
|
|
38
|
+
|
|
39
|
+
def purge_cache_by_urls_retry(failure: Failure, after_seconds: float = 0) -> Case[CachePurge]:
|
|
40
|
+
return Case.retry(failure, after_seconds)
|
|
41
|
+
|
|
42
|
+
setattr(purge_cache_by_urls_retry, '__module__', "dex_connectors.cloudflare.cloudflaremock")
|
|
43
|
+
|
|
44
|
+
def purge_cache_by_urls_purged_default() -> Case[CachePurge]:
|
|
45
|
+
return Case.branch_result(PURGED, CachePurge(success=True, result=PurgeRequest(id='purge-meridian')))
|
|
46
|
+
|
|
47
|
+
setattr(purge_cache_by_urls_purged_default, '__module__', "dex_connectors.cloudflare.cloudflaremock")
|
|
48
|
+
|
|
49
|
+
def list_zones_listed(value: ZonesPage, failure: Failure | None = None) -> Case[ZonesPage]:
|
|
50
|
+
return Case.branch_result(LISTED, value, failure)
|
|
51
|
+
|
|
52
|
+
setattr(list_zones_listed, '__module__', "dex_connectors.cloudflare.cloudflaremock")
|
|
53
|
+
|
|
54
|
+
def list_zones_provider_rejected(value: ZonesPage, failure: Failure | None = None) -> Case[ZonesPage]:
|
|
55
|
+
return Case.branch_result(PROVIDER_REJECTED, value, failure)
|
|
56
|
+
|
|
57
|
+
setattr(list_zones_provider_rejected, '__module__', "dex_connectors.cloudflare.cloudflaremock")
|
|
58
|
+
|
|
59
|
+
def list_zones_invalid_response(value: ZonesPage, failure: Failure | None = None) -> Case[ZonesPage]:
|
|
60
|
+
return Case.branch_result(INVALID_RESPONSE, value, failure)
|
|
61
|
+
|
|
62
|
+
setattr(list_zones_invalid_response, '__module__', "dex_connectors.cloudflare.cloudflaremock")
|
|
63
|
+
|
|
64
|
+
def list_zones_defect(value: ZonesPage, failure: Failure | None = None) -> Case[ZonesPage]:
|
|
65
|
+
return Case.branch_result(DEFECT, value, failure)
|
|
66
|
+
|
|
67
|
+
setattr(list_zones_defect, '__module__', "dex_connectors.cloudflare.cloudflaremock")
|
|
68
|
+
|
|
69
|
+
def list_zones_retry(failure: Failure, after_seconds: float = 0) -> Case[ZonesPage]:
|
|
70
|
+
return Case.retry(failure, after_seconds)
|
|
71
|
+
|
|
72
|
+
setattr(list_zones_retry, '__module__', "dex_connectors.cloudflare.cloudflaremock")
|
|
73
|
+
|
|
74
|
+
def list_zones_listed_default() -> Case[ZonesPage]:
|
|
75
|
+
return Case.branch_result(LISTED, ZonesPage(success=True, result=(Zone(id='zone-meridian', name='meridian.example', status='active'),)))
|
|
76
|
+
|
|
77
|
+
setattr(list_zones_listed_default, '__module__', "dex_connectors.cloudflare.cloudflaremock")
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
class Mock:
|
|
81
|
+
|
|
82
|
+
def __init__(self, connection_name: str = "cloudflare") -> None:
|
|
83
|
+
self.purge_cache_by_urls_script: Mutation[PurgeCacheByURLsInput, CachePurge] = Mutation(PURGE_CACHE_BY_URLS_DEFINITION)
|
|
84
|
+
self.purge_cache_by_urls_script.default(purge_cache_by_urls_purged_default())
|
|
85
|
+
self.list_zones_script: Query[ListZonesInput, ZonesPage] = Query(LIST_ZONES_DEFINITION)
|
|
86
|
+
self.list_zones_script.default(list_zones_listed_default())
|
|
87
|
+
self._connection = new_connection_with_operations(
|
|
88
|
+
purge_cache_by_urls=self.purge_cache_by_urls_script,
|
|
89
|
+
list_zones=self.list_zones_script,
|
|
90
|
+
reference=ConnectionRef(CONNECTOR_ID, connection_name),
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
def connection(self) -> Connection:
|
|
94
|
+
return self._connection
|
|
95
|
+
|
|
96
|
+
setattr(Mock, '__module__', "dex_connectors.cloudflare.cloudflaremock")
|
|
97
|
+
|
|
98
|
+
__all__ = [
|
|
99
|
+
"Mock",
|
|
100
|
+
"purge_cache_by_urls_purged",
|
|
101
|
+
"purge_cache_by_urls_not_found",
|
|
102
|
+
"purge_cache_by_urls_provider_rejected",
|
|
103
|
+
"purge_cache_by_urls_invalid_response",
|
|
104
|
+
"purge_cache_by_urls_defect",
|
|
105
|
+
"purge_cache_by_urls_retry",
|
|
106
|
+
"purge_cache_by_urls_purged_default",
|
|
107
|
+
"list_zones_listed",
|
|
108
|
+
"list_zones_provider_rejected",
|
|
109
|
+
"list_zones_invalid_response",
|
|
110
|
+
"list_zones_defect",
|
|
111
|
+
"list_zones_retry",
|
|
112
|
+
"list_zones_listed_default",
|
|
113
|
+
]
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
# ruff: noqa
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass, field as _dataclass_field
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
def _replace_nil_slices(value: Any, depth: int) -> Any:
|
|
9
|
+
if value is None:
|
|
10
|
+
return ()
|
|
11
|
+
if depth == 1:
|
|
12
|
+
return tuple(value)
|
|
13
|
+
return tuple(_replace_nil_slices(item, depth - 1) for item in value)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
# PurgeCacheByURLsInput names one zone and up to 30 absolute URLs.
|
|
17
|
+
@dataclass(frozen=True, slots=True)
|
|
18
|
+
class PurgeCacheByURLsInput:
|
|
19
|
+
# ZoneID identifies the zone whose cache is purged.
|
|
20
|
+
zone_id: str = _dataclass_field(default='', metadata={'dex_json_name': 'zoneId'})
|
|
21
|
+
# URLs lists absolute HTTP or HTTPS URLs to purge.
|
|
22
|
+
urls: tuple[str, ...] = ()
|
|
23
|
+
|
|
24
|
+
def __post_init__(self) -> None:
|
|
25
|
+
object.__setattr__(self, 'urls', _replace_nil_slices(self.urls, 1))
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
PurgeCacheByURLsInput.__annotations__['urls'] = tuple[str, ...] | None
|
|
29
|
+
PurgeCacheByURLsInput.__dataclass_fields__['urls'].type = tuple[str, ...] | None
|
|
30
|
+
setattr(PurgeCacheByURLsInput, '__module__', 'dex_connectors.cloudflare.models')
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@dataclass(frozen=True, slots=True)
|
|
34
|
+
class CachePurgeResult:
|
|
35
|
+
id: str = ''
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
setattr(CachePurgeResult, '__module__', 'dex_connectors.cloudflare.models')
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
# CachePurge records Cloudflare's acceptance, not a cache miss guarantee.
|
|
42
|
+
@dataclass(frozen=True, slots=True)
|
|
43
|
+
class CachePurge:
|
|
44
|
+
# Success reports that Cloudflare accepted the purge request.
|
|
45
|
+
success: bool = False
|
|
46
|
+
# Result contains Cloudflare's purge request ID.
|
|
47
|
+
result: CachePurgeResult = _dataclass_field(default_factory=CachePurgeResult)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
setattr(CachePurge, '__module__', 'dex_connectors.cloudflare.models')
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
# ListZonesInput requests the default Cloudflare zone page.
|
|
54
|
+
@dataclass(frozen=True, slots=True)
|
|
55
|
+
class ListZonesInput:
|
|
56
|
+
pass
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
setattr(ListZonesInput, '__module__', 'dex_connectors.cloudflare.models')
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
# Zone identifies a Cloudflare zone.
|
|
63
|
+
@dataclass(frozen=True, slots=True)
|
|
64
|
+
class Zone:
|
|
65
|
+
# ID is the zone identifier used by cache operations.
|
|
66
|
+
id: str = ''
|
|
67
|
+
# Name is the zone's DNS name.
|
|
68
|
+
name: str = ''
|
|
69
|
+
# Status is the provider-reported zone status.
|
|
70
|
+
status: str = ''
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
setattr(Zone, '__module__', 'dex_connectors.cloudflare.models')
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
# ZonesPage contains Cloudflare zones and success metadata.
|
|
77
|
+
@dataclass(frozen=True, slots=True)
|
|
78
|
+
class ZonesPage:
|
|
79
|
+
# Success reports whether Cloudflare accepted the list request.
|
|
80
|
+
success: bool = False
|
|
81
|
+
# Result contains one zone page, possibly empty.
|
|
82
|
+
result: tuple[Zone, ...] = ()
|
|
83
|
+
|
|
84
|
+
def __post_init__(self) -> None:
|
|
85
|
+
object.__setattr__(self, 'result', _replace_nil_slices(self.result, 1))
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
ZonesPage.__annotations__['result'] = tuple[Zone, ...] | None
|
|
89
|
+
ZonesPage.__dataclass_fields__['result'].type = tuple[Zone, ...] | None
|
|
90
|
+
setattr(ZonesPage, '__module__', 'dex_connectors.cloudflare.models')
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
# ruff: noqa
|
|
4
|
+
|
|
5
|
+
from collections.abc import Callable, Mapping
|
|
6
|
+
from typing import Any, TypeVar
|
|
7
|
+
|
|
8
|
+
import dex
|
|
9
|
+
from dex_connectors.sdk import (
|
|
10
|
+
MutationResult,
|
|
11
|
+
MutationStep,
|
|
12
|
+
MutationStepConfig,
|
|
13
|
+
QueryResult,
|
|
14
|
+
QueryStep,
|
|
15
|
+
QueryStepConfig,
|
|
16
|
+
StepAnnotations,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
from ..connection import Connection
|
|
20
|
+
from ..models import CachePurge, ListZonesInput, PurgeCacheByURLsInput, ZonesPage
|
|
21
|
+
|
|
22
|
+
StepInput = TypeVar("StepInput")
|
|
23
|
+
|
|
24
|
+
def new_purge_cache_by_urls_step(
|
|
25
|
+
*,
|
|
26
|
+
step_type: str,
|
|
27
|
+
step_input_type: type[StepInput],
|
|
28
|
+
annotations: StepAnnotations | Mapping[str, str],
|
|
29
|
+
connection: Connection,
|
|
30
|
+
connection_name: str,
|
|
31
|
+
map_to_operation_input: Callable[[StepInput], PurgeCacheByURLsInput],
|
|
32
|
+
purged: dex.StepTarget[MutationResult[CachePurge]],
|
|
33
|
+
not_found: dex.StepTarget[MutationResult[CachePurge]] | None = None,
|
|
34
|
+
provider_rejected: dex.StepTarget[MutationResult[CachePurge]] | None = None,
|
|
35
|
+
invalid_response: dex.StepTarget[MutationResult[CachePurge]] | None = None,
|
|
36
|
+
defect: dex.StepTarget[MutationResult[CachePurge]] | None = None,
|
|
37
|
+
result_attribute: dex.Attribute[MutationResult[CachePurge]] | None = None,
|
|
38
|
+
step_options_override: dex.StepOptions | None = None,
|
|
39
|
+
) -> MutationStep[StepInput, PurgeCacheByURLsInput, CachePurge]:
|
|
40
|
+
if connection is None or connection.reference.name != connection_name:
|
|
41
|
+
raise ValueError("Cloudflare Step connection name must match its connection reference")
|
|
42
|
+
if isinstance(annotations, StepAnnotations):
|
|
43
|
+
step_annotations = annotations
|
|
44
|
+
else:
|
|
45
|
+
if not isinstance(annotations, Mapping) or set(annotations) != {"groupId", "groupLabel", "explanation"}:
|
|
46
|
+
raise ValueError("Cloudflare Step annotations require groupId, groupLabel, and explanation")
|
|
47
|
+
if any(not isinstance(value, str) for value in annotations.values()):
|
|
48
|
+
raise ValueError("Cloudflare Step annotations must be strings")
|
|
49
|
+
step_annotations = StepAnnotations(annotations["groupId"], annotations["groupLabel"], annotations["explanation"])
|
|
50
|
+
branches = {
|
|
51
|
+
"purged": purged,
|
|
52
|
+
}
|
|
53
|
+
if not_found is not None:
|
|
54
|
+
branches["notFound"] = not_found
|
|
55
|
+
if provider_rejected is not None:
|
|
56
|
+
branches["providerRejected"] = provider_rejected
|
|
57
|
+
if invalid_response is not None:
|
|
58
|
+
branches["invalidResponse"] = invalid_response
|
|
59
|
+
if defect is not None:
|
|
60
|
+
branches["defect"] = defect
|
|
61
|
+
return MutationStep(
|
|
62
|
+
MutationStepConfig(
|
|
63
|
+
step_type=step_type,
|
|
64
|
+
step_input_type=step_input_type,
|
|
65
|
+
annotations=step_annotations,
|
|
66
|
+
operation=_bound_operation(connection, "purge_cache_by_urls"),
|
|
67
|
+
connection=connection.reference,
|
|
68
|
+
map_to_operation_input=map_to_operation_input,
|
|
69
|
+
branches=branches,
|
|
70
|
+
result_attribute=result_attribute,
|
|
71
|
+
step_options_override=step_options_override,
|
|
72
|
+
)
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
setattr(new_purge_cache_by_urls_step, '__module__', 'dex_connectors.cloudflare.steps')
|
|
76
|
+
|
|
77
|
+
def new_list_zones_step(
|
|
78
|
+
*,
|
|
79
|
+
step_type: str,
|
|
80
|
+
step_input_type: type[StepInput],
|
|
81
|
+
annotations: StepAnnotations | Mapping[str, str],
|
|
82
|
+
connection: Connection,
|
|
83
|
+
connection_name: str,
|
|
84
|
+
map_to_operation_input: Callable[[StepInput], ListZonesInput],
|
|
85
|
+
listed: dex.StepTarget[QueryResult[ZonesPage]],
|
|
86
|
+
provider_rejected: dex.StepTarget[QueryResult[ZonesPage]] | None = None,
|
|
87
|
+
invalid_response: dex.StepTarget[QueryResult[ZonesPage]] | None = None,
|
|
88
|
+
defect: dex.StepTarget[QueryResult[ZonesPage]] | None = None,
|
|
89
|
+
result_attribute: dex.Attribute[QueryResult[ZonesPage]] | None = None,
|
|
90
|
+
step_options_override: dex.StepOptions | None = None,
|
|
91
|
+
) -> QueryStep[StepInput, ListZonesInput, ZonesPage]:
|
|
92
|
+
if connection is None or connection.reference.name != connection_name:
|
|
93
|
+
raise ValueError("Cloudflare Step connection name must match its connection reference")
|
|
94
|
+
if isinstance(annotations, StepAnnotations):
|
|
95
|
+
step_annotations = annotations
|
|
96
|
+
else:
|
|
97
|
+
if not isinstance(annotations, Mapping) or set(annotations) != {"groupId", "groupLabel", "explanation"}:
|
|
98
|
+
raise ValueError("Cloudflare Step annotations require groupId, groupLabel, and explanation")
|
|
99
|
+
if any(not isinstance(value, str) for value in annotations.values()):
|
|
100
|
+
raise ValueError("Cloudflare Step annotations must be strings")
|
|
101
|
+
step_annotations = StepAnnotations(annotations["groupId"], annotations["groupLabel"], annotations["explanation"])
|
|
102
|
+
branches = {
|
|
103
|
+
"listed": listed,
|
|
104
|
+
}
|
|
105
|
+
if provider_rejected is not None:
|
|
106
|
+
branches["providerRejected"] = provider_rejected
|
|
107
|
+
if invalid_response is not None:
|
|
108
|
+
branches["invalidResponse"] = invalid_response
|
|
109
|
+
if defect is not None:
|
|
110
|
+
branches["defect"] = defect
|
|
111
|
+
return QueryStep(
|
|
112
|
+
QueryStepConfig(
|
|
113
|
+
step_type=step_type,
|
|
114
|
+
step_input_type=step_input_type,
|
|
115
|
+
annotations=step_annotations,
|
|
116
|
+
operation=_bound_operation(connection, "list_zones"),
|
|
117
|
+
connection=connection.reference,
|
|
118
|
+
map_to_operation_input=map_to_operation_input,
|
|
119
|
+
branches=branches,
|
|
120
|
+
result_attribute=result_attribute,
|
|
121
|
+
step_options_override=step_options_override,
|
|
122
|
+
)
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
setattr(new_list_zones_step, '__module__', 'dex_connectors.cloudflare.steps')
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def _bound_operation(connection: Connection, operation_name: str) -> Any:
|
|
129
|
+
source = getattr(connection, operation_name, None)
|
|
130
|
+
if source is None:
|
|
131
|
+
source = getattr(getattr(connection, "operations", None), operation_name, None)
|
|
132
|
+
if source is None:
|
|
133
|
+
raise ValueError(f"connection operation {operation_name} is missing")
|
|
134
|
+
return source() if callable(source) else source
|
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Cloudflare zone listing and URL cache purges with Go-compatible branch classification."""
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from collections.abc import Callable
|
|
7
|
+
from dataclasses import dataclass
|
|
8
|
+
from datetime import UTC, datetime
|
|
9
|
+
from datetime import timedelta as timedelta
|
|
10
|
+
from typing import Any, TypeVar
|
|
11
|
+
from urllib.parse import quote, urlsplit
|
|
12
|
+
|
|
13
|
+
import httpx
|
|
14
|
+
from dex_connectors.sdk import BranchDefinition as BranchDefinition
|
|
15
|
+
from dex_connectors.sdk import (
|
|
16
|
+
Call,
|
|
17
|
+
CallID,
|
|
18
|
+
CredentialProvider,
|
|
19
|
+
Failure,
|
|
20
|
+
FailureKind,
|
|
21
|
+
IdempotencyKey,
|
|
22
|
+
MutationAttempt,
|
|
23
|
+
MutationDefinition,
|
|
24
|
+
QueryAttempt,
|
|
25
|
+
QueryDefinition,
|
|
26
|
+
ReauthorizationRequiredError,
|
|
27
|
+
Receipt,
|
|
28
|
+
)
|
|
29
|
+
from dex_connectors.sdk import OperationRef as OperationRef
|
|
30
|
+
from dex_connectors.sdk import SecretString as SecretString
|
|
31
|
+
from dex_connectors.sdk import StepDefaults as StepDefaults
|
|
32
|
+
from dex_connectors.sdk.providerhttp import (
|
|
33
|
+
BodyTooLargeError,
|
|
34
|
+
ProviderTransportError,
|
|
35
|
+
is_header_safe_credential,
|
|
36
|
+
new_provider_http_client,
|
|
37
|
+
parse_retry_after,
|
|
38
|
+
read_bounded_body,
|
|
39
|
+
send_traced,
|
|
40
|
+
validate_base_url,
|
|
41
|
+
)
|
|
42
|
+
from dex_connectors.sdk.retry_policy import (
|
|
43
|
+
default_connector_step_execute_retry_policy as default_connector_step_execute_retry_policy,
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
from ._generated.config import (
|
|
47
|
+
Config as Config,
|
|
48
|
+
)
|
|
49
|
+
from ._generated.config import (
|
|
50
|
+
Credentials as Credentials,
|
|
51
|
+
)
|
|
52
|
+
from ._generated.definitions import (
|
|
53
|
+
CONNECTOR_ID as CONNECTOR_ID,
|
|
54
|
+
)
|
|
55
|
+
from ._generated.definitions import (
|
|
56
|
+
DEFECT as DEFECT,
|
|
57
|
+
)
|
|
58
|
+
from ._generated.definitions import (
|
|
59
|
+
INVALID_RESPONSE as INVALID_RESPONSE,
|
|
60
|
+
)
|
|
61
|
+
from ._generated.definitions import (
|
|
62
|
+
LIST_ZONES_DEFINITION as LIST_ZONES_DEFINITION,
|
|
63
|
+
)
|
|
64
|
+
from ._generated.definitions import (
|
|
65
|
+
LIST_ZONES_OPERATION_ID as LIST_ZONES_OPERATION_ID,
|
|
66
|
+
)
|
|
67
|
+
from ._generated.definitions import (
|
|
68
|
+
LISTED as LISTED,
|
|
69
|
+
)
|
|
70
|
+
from ._generated.definitions import (
|
|
71
|
+
NOT_FOUND as NOT_FOUND,
|
|
72
|
+
)
|
|
73
|
+
from ._generated.definitions import (
|
|
74
|
+
PROVIDER_REJECTED as PROVIDER_REJECTED,
|
|
75
|
+
)
|
|
76
|
+
from ._generated.definitions import (
|
|
77
|
+
PURGE_CACHE_BY_URLS_DEFINITION as PURGE_CACHE_BY_URLS_DEFINITION,
|
|
78
|
+
)
|
|
79
|
+
from ._generated.definitions import (
|
|
80
|
+
PURGE_CACHE_BY_URLS_OPERATION_ID as PURGE_CACHE_BY_URLS_OPERATION_ID,
|
|
81
|
+
)
|
|
82
|
+
from ._generated.definitions import (
|
|
83
|
+
PURGED as PURGED,
|
|
84
|
+
)
|
|
85
|
+
from .models import CachePurge, ListZonesInput, PurgeCacheByURLsInput, PurgeRequest, Zone, ZonesPage
|
|
86
|
+
|
|
87
|
+
_DEFAULT_BASE_URL = "https://api.cloudflare.com/client/v4"
|
|
88
|
+
_DEFAULT_TIMEOUT_SECONDS = 15
|
|
89
|
+
_DEFAULT_MAX_RESPONSE_BYTES = 2_097_152
|
|
90
|
+
_MAX_PURGE_URLS = 30
|
|
91
|
+
_PATH_SEGMENT_SAFE = "$&+:=@"
|
|
92
|
+
_STATUS_KINDS = {
|
|
93
|
+
401: FailureKind.AUTHENTICATION,
|
|
94
|
+
403: FailureKind.AUTHORIZATION,
|
|
95
|
+
404: FailureKind.NOT_FOUND,
|
|
96
|
+
400: FailureKind.VALIDATION,
|
|
97
|
+
422: FailureKind.VALIDATION,
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
Output = TypeVar("Output")
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
@dataclass(frozen=True, slots=True)
|
|
104
|
+
class _Outcome:
|
|
105
|
+
"""A terminal or retry attempt whose empty value the calling operation supplies."""
|
|
106
|
+
|
|
107
|
+
branch: str
|
|
108
|
+
failure: Failure
|
|
109
|
+
is_retry: bool = False
|
|
110
|
+
retry_after_seconds: float = 0
|
|
111
|
+
|
|
112
|
+
def as_query(self, empty: Output) -> QueryAttempt[Output]:
|
|
113
|
+
if self.is_retry:
|
|
114
|
+
return QueryAttempt.retry(self.failure, self.retry_after_seconds)
|
|
115
|
+
return QueryAttempt.branch_result(self.branch, empty, Receipt(), self.failure)
|
|
116
|
+
|
|
117
|
+
def as_mutation(self, empty: Output) -> MutationAttempt[Output]:
|
|
118
|
+
if self.is_retry:
|
|
119
|
+
return MutationAttempt.retry(self.failure, self.retry_after_seconds)
|
|
120
|
+
return MutationAttempt.branch_result(self.branch, empty, Receipt(), self.failure)
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
@dataclass(frozen=True, slots=True)
|
|
124
|
+
class _Success:
|
|
125
|
+
"""A decoded happy-branch value."""
|
|
126
|
+
|
|
127
|
+
value: Any
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
class Client:
|
|
131
|
+
"""One redirect-safe HTTP client and call-time credential source."""
|
|
132
|
+
|
|
133
|
+
def __init__(
|
|
134
|
+
self,
|
|
135
|
+
config: Config,
|
|
136
|
+
credentials: CredentialProvider[Credentials],
|
|
137
|
+
http_client: httpx.AsyncClient | None = None,
|
|
138
|
+
) -> None:
|
|
139
|
+
if config is None:
|
|
140
|
+
raise ValueError("Cloudflare configuration is required")
|
|
141
|
+
if credentials is None:
|
|
142
|
+
raise ValueError("Cloudflare credential source is required")
|
|
143
|
+
if config.timeout_seconds < 0 or config.max_response_bytes < 0:
|
|
144
|
+
raise ValueError("Cloudflare timeout and maxResponseBytes must be positive")
|
|
145
|
+
self.base_url = validate_base_url(config.base_url or _DEFAULT_BASE_URL)
|
|
146
|
+
self.max_response_bytes = config.max_response_bytes or _DEFAULT_MAX_RESPONSE_BYTES
|
|
147
|
+
self.credentials = credentials
|
|
148
|
+
self.http_client = http_client or new_provider_http_client(
|
|
149
|
+
config.timeout_seconds or _DEFAULT_TIMEOUT_SECONDS
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
def list_zones(self) -> "ListZonesOperation":
|
|
153
|
+
"""Bind the listZones Query to this client."""
|
|
154
|
+
return ListZonesOperation(self)
|
|
155
|
+
|
|
156
|
+
def purge_cache_by_urls(self) -> "PurgeCacheByURLsOperation":
|
|
157
|
+
"""Bind the purgeCacheByURLs Mutation to this client."""
|
|
158
|
+
return PurgeCacheByURLsOperation(self)
|
|
159
|
+
|
|
160
|
+
async def aclose(self) -> None:
|
|
161
|
+
"""Close the owned provider HTTP client after application shutdown."""
|
|
162
|
+
await self.http_client.aclose()
|
|
163
|
+
|
|
164
|
+
async def execute(
|
|
165
|
+
self,
|
|
166
|
+
call: Call,
|
|
167
|
+
operation: str,
|
|
168
|
+
method: str,
|
|
169
|
+
path: str,
|
|
170
|
+
body: bytes | None,
|
|
171
|
+
has_not_found: bool,
|
|
172
|
+
decode: Callable[[Any], Any],
|
|
173
|
+
) -> _Success | _Outcome:
|
|
174
|
+
"""Send one request and classify it exactly like the Go executeQuery and executeMutation helpers."""
|
|
175
|
+
try:
|
|
176
|
+
credentials = await self.credentials.resolve(call)
|
|
177
|
+
except (ValueError, LookupError, OSError, ReauthorizationRequiredError):
|
|
178
|
+
return _outcome(
|
|
179
|
+
DEFECT, operation, FailureKind.AUTHENTICATION, "connection credentials are unavailable"
|
|
180
|
+
)
|
|
181
|
+
token = credentials.api_token.reveal()
|
|
182
|
+
if not token or not is_header_safe_credential(token):
|
|
183
|
+
return _outcome(
|
|
184
|
+
DEFECT, operation, FailureKind.AUTHENTICATION, "connection credentials are invalid"
|
|
185
|
+
)
|
|
186
|
+
headers = {"Authorization": "Bearer " + token, "Accept": "application/json"}
|
|
187
|
+
if body is not None:
|
|
188
|
+
headers["Content-Type"] = "application/json"
|
|
189
|
+
try:
|
|
190
|
+
request = self.http_client.build_request(
|
|
191
|
+
method, self.base_url + path, content=body, headers=headers
|
|
192
|
+
)
|
|
193
|
+
except (httpx.HTTPError, ValueError):
|
|
194
|
+
return _outcome(DEFECT, operation, FailureKind.LOCAL_DEFECT, "request could not be built")
|
|
195
|
+
try:
|
|
196
|
+
response, _ = await send_traced(self.http_client, request)
|
|
197
|
+
except ProviderTransportError:
|
|
198
|
+
return _outcome(
|
|
199
|
+
"", operation, FailureKind.AVAILABILITY, "Cloudflare request failed", is_retry=True
|
|
200
|
+
)
|
|
201
|
+
try:
|
|
202
|
+
status = response.status_code
|
|
203
|
+
if status in (408, 409, 429) or status >= 500:
|
|
204
|
+
kind = FailureKind.RATE_LIMIT if status == 429 else FailureKind.AVAILABILITY
|
|
205
|
+
retry_after = parse_retry_after(response.headers.get("Retry-After", ""), datetime.now(UTC))
|
|
206
|
+
return _outcome("", operation, kind, f"Cloudflare returned HTTP {status}", True, retry_after)
|
|
207
|
+
if status != 200:
|
|
208
|
+
branch = NOT_FOUND if status == 404 and has_not_found else PROVIDER_REJECTED
|
|
209
|
+
kind = _STATUS_KINDS.get(status, FailureKind.PROVIDER_REJECTION)
|
|
210
|
+
return _outcome(branch, operation, kind, f"Cloudflare returned HTTP {status}")
|
|
211
|
+
try:
|
|
212
|
+
response_body = await read_bounded_body(response, self.max_response_bytes)
|
|
213
|
+
except BodyTooLargeError:
|
|
214
|
+
return _outcome(
|
|
215
|
+
INVALID_RESPONSE,
|
|
216
|
+
operation,
|
|
217
|
+
FailureKind.RESPONSE_TOO_LARGE,
|
|
218
|
+
"response exceeded the configured limit",
|
|
219
|
+
)
|
|
220
|
+
except ProviderTransportError:
|
|
221
|
+
return _outcome(
|
|
222
|
+
"", operation, FailureKind.AVAILABILITY, "response was interrupted", is_retry=True
|
|
223
|
+
)
|
|
224
|
+
try:
|
|
225
|
+
document = json.loads(response_body)
|
|
226
|
+
except (ValueError, UnicodeDecodeError):
|
|
227
|
+
document = None
|
|
228
|
+
is_valid_json = False
|
|
229
|
+
else:
|
|
230
|
+
is_valid_json = True
|
|
231
|
+
if is_valid_json and isinstance(document, dict) and document.get("success") is False:
|
|
232
|
+
return _outcome(
|
|
233
|
+
PROVIDER_REJECTED,
|
|
234
|
+
operation,
|
|
235
|
+
FailureKind.PROVIDER_REJECTION,
|
|
236
|
+
"Cloudflare rejected the request",
|
|
237
|
+
)
|
|
238
|
+
try:
|
|
239
|
+
if not is_valid_json:
|
|
240
|
+
raise ValueError
|
|
241
|
+
return _Success(decode(document))
|
|
242
|
+
except (ValueError, TypeError):
|
|
243
|
+
return _outcome(INVALID_RESPONSE, operation, FailureKind.PROTOCOL, "response was malformed")
|
|
244
|
+
finally:
|
|
245
|
+
await response.aclose()
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
class ListZonesOperation:
|
|
249
|
+
"""List the first page of Cloudflare zones."""
|
|
250
|
+
|
|
251
|
+
def __init__(self, client: Client) -> None:
|
|
252
|
+
if client is None:
|
|
253
|
+
raise ValueError("Cloudflare client is required")
|
|
254
|
+
self.client = client
|
|
255
|
+
|
|
256
|
+
def definition(self) -> QueryDefinition:
|
|
257
|
+
"""Return manifest identity, branches, and retry defaults."""
|
|
258
|
+
return LIST_ZONES_DEFINITION
|
|
259
|
+
|
|
260
|
+
async def invoke(self, call: Call, input: ListZonesInput) -> QueryAttempt[ZonesPage]:
|
|
261
|
+
"""Read the first zone page once, then select a branch or safe retry."""
|
|
262
|
+
result = await self.client.execute(
|
|
263
|
+
call, LIST_ZONES_OPERATION_ID, "GET", "/zones", None, False, _decode_zones
|
|
264
|
+
)
|
|
265
|
+
if isinstance(result, _Outcome):
|
|
266
|
+
return result.as_query(ZonesPage())
|
|
267
|
+
return QueryAttempt.branch_result(LISTED, result.value, Receipt())
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
class PurgeCacheByURLsOperation:
|
|
271
|
+
"""Purge specific URLs from one zone; repeating the same purge has the same effect."""
|
|
272
|
+
|
|
273
|
+
def __init__(self, client: Client) -> None:
|
|
274
|
+
if client is None:
|
|
275
|
+
raise ValueError("Cloudflare client is required")
|
|
276
|
+
self.client = client
|
|
277
|
+
|
|
278
|
+
def definition(self) -> MutationDefinition:
|
|
279
|
+
"""Return manifest identity, branches, and retry defaults."""
|
|
280
|
+
return PURGE_CACHE_BY_URLS_DEFINITION
|
|
281
|
+
|
|
282
|
+
def idempotency_key(self, call_id: CallID, input: PurgeCacheByURLsInput) -> IdempotencyKey:
|
|
283
|
+
"""Identify the Dex call; purging the same URLs is repeat safe."""
|
|
284
|
+
return IdempotencyKey(str(call_id))
|
|
285
|
+
|
|
286
|
+
async def invoke(self, call: Call, input: PurgeCacheByURLsInput) -> MutationAttempt[CachePurge]:
|
|
287
|
+
"""Validate, purge once, then select a branch or safe retry."""
|
|
288
|
+
operation = PURGE_CACHE_BY_URLS_OPERATION_ID
|
|
289
|
+
message = _purge_validation_message(input)
|
|
290
|
+
if message:
|
|
291
|
+
return MutationAttempt.branch_result(
|
|
292
|
+
DEFECT,
|
|
293
|
+
CachePurge(),
|
|
294
|
+
Receipt(),
|
|
295
|
+
Failure(FailureKind.VALIDATION, CONNECTOR_ID, operation, message),
|
|
296
|
+
)
|
|
297
|
+
body = json.dumps({"files": list(input.urls)}, separators=(",", ":")).encode()
|
|
298
|
+
path = "/zones/" + quote(input.zone_id, safe=_PATH_SEGMENT_SAFE) + "/purge_cache"
|
|
299
|
+
result = await self.client.execute(call, operation, "POST", path, body, True, _decode_cache_purge)
|
|
300
|
+
if isinstance(result, _Outcome):
|
|
301
|
+
return result.as_mutation(CachePurge())
|
|
302
|
+
return MutationAttempt.branch_result(PURGED, result.value, Receipt())
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
def _purge_validation_message(input: PurgeCacheByURLsInput) -> str:
|
|
306
|
+
if (
|
|
307
|
+
not isinstance(input, PurgeCacheByURLsInput)
|
|
308
|
+
or not isinstance(input.zone_id, str)
|
|
309
|
+
or not input.zone_id.strip()
|
|
310
|
+
or not 1 <= len(input.urls) <= _MAX_PURGE_URLS
|
|
311
|
+
):
|
|
312
|
+
return "zoneId and 1 to 30 URLs are required"
|
|
313
|
+
if not all(_is_absolute_http_url(raw_url) for raw_url in input.urls):
|
|
314
|
+
return "each URL must be an absolute HTTP or HTTPS URL"
|
|
315
|
+
return ""
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
def _is_absolute_http_url(raw_url: object) -> bool:
|
|
319
|
+
if not isinstance(raw_url, str) or any(
|
|
320
|
+
ord(character) < 0x20 or character == "\x7f" for character in raw_url
|
|
321
|
+
):
|
|
322
|
+
return False
|
|
323
|
+
try:
|
|
324
|
+
parsed = urlsplit(raw_url)
|
|
325
|
+
except ValueError:
|
|
326
|
+
return False
|
|
327
|
+
return (
|
|
328
|
+
parsed.scheme in ("http", "https")
|
|
329
|
+
and bool(parsed.netloc)
|
|
330
|
+
and "@" not in parsed.netloc
|
|
331
|
+
and " " not in parsed.netloc
|
|
332
|
+
)
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
def _decode_zones(document: Any) -> ZonesPage:
|
|
336
|
+
if not isinstance(document, dict):
|
|
337
|
+
raise ValueError
|
|
338
|
+
result = document.get("result")
|
|
339
|
+
if _optional(document, "success", False) is not True or not isinstance(result, list):
|
|
340
|
+
raise ValueError
|
|
341
|
+
return ZonesPage(True, tuple(_decode_zone(zone) for zone in result))
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
def _decode_zone(document: Any) -> Zone:
|
|
345
|
+
if document is None:
|
|
346
|
+
return Zone()
|
|
347
|
+
if not isinstance(document, dict):
|
|
348
|
+
raise ValueError
|
|
349
|
+
fields = tuple(_optional(document, name, "") for name in ("id", "name", "status"))
|
|
350
|
+
if not all(isinstance(value, str) for value in fields):
|
|
351
|
+
raise ValueError
|
|
352
|
+
return Zone(*fields)
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
def _decode_cache_purge(document: Any) -> CachePurge:
|
|
356
|
+
if not isinstance(document, dict) or _optional(document, "success", False) is not True:
|
|
357
|
+
raise ValueError
|
|
358
|
+
result = _optional(document, "result", {})
|
|
359
|
+
if not isinstance(result, dict):
|
|
360
|
+
raise ValueError
|
|
361
|
+
purge_id = _optional(result, "id", "")
|
|
362
|
+
if not isinstance(purge_id, str):
|
|
363
|
+
raise ValueError
|
|
364
|
+
return CachePurge(True, PurgeRequest(purge_id))
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
def _optional(document: dict[str, Any], name: str, default: Any) -> Any:
|
|
368
|
+
"""Return a JSON field, treating absent or null like Go's zero value."""
|
|
369
|
+
value = document.get(name)
|
|
370
|
+
return default if value is None else value
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
def _outcome(
|
|
374
|
+
branch: str,
|
|
375
|
+
operation: str,
|
|
376
|
+
kind: FailureKind,
|
|
377
|
+
message: str,
|
|
378
|
+
is_retry: bool = False,
|
|
379
|
+
retry_after_seconds: float = 0,
|
|
380
|
+
) -> _Outcome:
|
|
381
|
+
return _Outcome(branch, Failure(kind, CONNECTOR_ID, operation, message), is_retry, retry_after_seconds)
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
Config.__doc__ = "Cloudflare HTTP settings; zero or blank values use manifest defaults."
|
|
385
|
+
Credentials.__doc__ = "Cloudflare API token, resolved anew for every provider attempt."
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Public manifest-backed mock helpers."""
|
|
4
|
+
|
|
5
|
+
from dex_connectors.sdk import ConnectionRef as ConnectionRef
|
|
6
|
+
from dex_connectors.sdk import Failure as Failure
|
|
7
|
+
from dex_connectors.sdk.connectormock import Case as Case
|
|
8
|
+
from dex_connectors.sdk.connectormock import Case as _Case
|
|
9
|
+
from dex_connectors.sdk.connectormock import Mutation as Mutation
|
|
10
|
+
from dex_connectors.sdk.connectormock import Query as Query
|
|
11
|
+
|
|
12
|
+
from .._generated.mock import Mock as Mock
|
|
13
|
+
from .._generated.mock import list_zones_listed as list_zones_listed
|
|
14
|
+
from .._generated.mock import list_zones_listed_default as _list_zones_listed_default
|
|
15
|
+
from .._generated.mock import purge_cache_by_urls_not_found as purge_cache_by_urls_not_found
|
|
16
|
+
from .._generated.mock import purge_cache_by_urls_purged as purge_cache_by_urls_purged
|
|
17
|
+
from .._generated.mock import purge_cache_by_urls_purged_default as _purge_cache_by_urls_purged_default
|
|
18
|
+
from ..client import CONNECTOR_ID as CONNECTOR_ID
|
|
19
|
+
from ..client import LIST_ZONES_DEFINITION as LIST_ZONES_DEFINITION
|
|
20
|
+
from ..client import LISTED as LISTED
|
|
21
|
+
from ..client import NOT_FOUND as NOT_FOUND
|
|
22
|
+
from ..client import PURGE_CACHE_BY_URLS_DEFINITION as PURGE_CACHE_BY_URLS_DEFINITION
|
|
23
|
+
from ..client import PURGED as PURGED
|
|
24
|
+
from ..connection import Connection as Connection
|
|
25
|
+
from ..connection import new_connection_with_operations as new_connection_with_operations
|
|
26
|
+
from ..models import CachePurge as CachePurge
|
|
27
|
+
from ..models import CachePurge as _CachePurge
|
|
28
|
+
from ..models import ListZonesInput as ListZonesInput
|
|
29
|
+
from ..models import PurgeCacheByURLsInput as PurgeCacheByURLsInput
|
|
30
|
+
from ..models import PurgeRequest as PurgeRequest
|
|
31
|
+
from ..models import Zone as Zone
|
|
32
|
+
from ..models import ZonesPage as ZonesPage
|
|
33
|
+
from ..models import ZonesPage as _ZonesPage
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def list_zones_default_answer() -> _Case[_ZonesPage]:
|
|
37
|
+
"""Return the manifest's listZones default answer."""
|
|
38
|
+
return _list_zones_listed_default()
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def purge_cache_by_urls_default_answer() -> _Case[_CachePurge]:
|
|
42
|
+
"""Return the manifest's purgeCacheByURLs default answer."""
|
|
43
|
+
return _purge_cache_by_urls_purged_default()
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
__all__ = [
|
|
47
|
+
"Mock",
|
|
48
|
+
"list_zones_listed",
|
|
49
|
+
"list_zones_default_answer",
|
|
50
|
+
"purge_cache_by_urls_purged",
|
|
51
|
+
"purge_cache_by_urls_not_found",
|
|
52
|
+
"purge_cache_by_urls_default_answer",
|
|
53
|
+
]
|
|
54
|
+
|
|
55
|
+
Mock.__doc__ = "Script Cloudflare operations, defaulting to their manifest answers."
|
|
56
|
+
|
|
57
|
+
list_zones_listed.__doc__ = "Script the listed route."
|
|
58
|
+
purge_cache_by_urls_purged.__doc__ = "Script the purged route."
|
|
59
|
+
purge_cache_by_urls_not_found.__doc__ = "Script a missing or inaccessible zone."
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Cloudflare connection bindings from the manifest contract."""
|
|
4
|
+
|
|
5
|
+
from typing import Any as Any
|
|
6
|
+
|
|
7
|
+
import httpx as httpx
|
|
8
|
+
from dex_connectors.sdk import Call as Call
|
|
9
|
+
from dex_connectors.sdk import ConnectionRef as ConnectionRef
|
|
10
|
+
from dex_connectors.sdk import Mutation as Mutation
|
|
11
|
+
from dex_connectors.sdk import Query as Query
|
|
12
|
+
from dex_connectors.sdk import SecretString as SecretString
|
|
13
|
+
from dex_connectors.sdk.projectconfig import ConnectionKey as ConnectionKey
|
|
14
|
+
from dex_connectors.sdk.projectconfig import LoadedProject as LoadedProject
|
|
15
|
+
|
|
16
|
+
from ._generated.connection import (
|
|
17
|
+
Connection as Connection,
|
|
18
|
+
)
|
|
19
|
+
from ._generated.connection import (
|
|
20
|
+
new_connection as new_connection,
|
|
21
|
+
)
|
|
22
|
+
from ._generated.connection import (
|
|
23
|
+
new_connection_with_operations as new_connection_with_operations,
|
|
24
|
+
)
|
|
25
|
+
from ._generated.connection import (
|
|
26
|
+
new_project_connection as new_project_connection,
|
|
27
|
+
)
|
|
28
|
+
from .client import CONNECTOR_ID as CONNECTOR_ID
|
|
29
|
+
from .client import LIST_ZONES_DEFINITION as LIST_ZONES_DEFINITION
|
|
30
|
+
from .client import PURGE_CACHE_BY_URLS_DEFINITION as PURGE_CACHE_BY_URLS_DEFINITION
|
|
31
|
+
from .client import Client as Client
|
|
32
|
+
from .client import Config as Config
|
|
33
|
+
from .client import Credentials as Credentials
|
|
34
|
+
from .models import CachePurge as CachePurge
|
|
35
|
+
from .models import ListZonesInput as ListZonesInput
|
|
36
|
+
from .models import PurgeCacheByURLsInput as PurgeCacheByURLsInput
|
|
37
|
+
from .models import ZonesPage as ZonesPage
|
|
38
|
+
|
|
39
|
+
Connection.__doc__ = "Nonserializable Cloudflare operation bindings for a named project connection."
|
|
40
|
+
Connection.purge_cache_by_urls.__doc__ = "Return the URL cache purge Mutation used by an application Step."
|
|
41
|
+
Connection.list_zones.__doc__ = "Return the zone listing Query used by an application Step."
|
|
42
|
+
Connection.aclose.__doc__ = "Close the owned provider transport after Worker shutdown."
|
|
43
|
+
new_connection.__doc__ = "Bind a client to an explicit logical connection reference."
|
|
44
|
+
new_connection_with_operations.__doc__ = (
|
|
45
|
+
"Bind mock operations to the same connection identity as the real provider."
|
|
46
|
+
)
|
|
47
|
+
new_project_connection.__doc__ = "Open declared ordinary settings and resolve the current API token per call."
|
|
48
|
+
Connection.__repr__.__doc__ = "Keep provider transport and credentials out of logs."
|
|
49
|
+
Connection.__reduce__.__doc__ = "Prevent a live connection from entering durable Flow state."
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
{
|
|
2
|
+
"connectorId": "cloudflare",
|
|
3
|
+
"releaseTag": "connectors/cloudflare/go/v0.2.0",
|
|
4
|
+
"package": {
|
|
5
|
+
"ecosystem": "pypi",
|
|
6
|
+
"name": "dex-connector-cloudflare",
|
|
7
|
+
"version": "0.1.0"
|
|
8
|
+
},
|
|
9
|
+
"factories": [
|
|
10
|
+
{
|
|
11
|
+
"name": "new_list_zones_step",
|
|
12
|
+
"kind": "query",
|
|
13
|
+
"operationId": "listZones",
|
|
14
|
+
"fields": {
|
|
15
|
+
"stepType": "step_type",
|
|
16
|
+
"annotations": "annotations",
|
|
17
|
+
"connectionName": "connection_name",
|
|
18
|
+
"resultAttribute": "result_attribute"
|
|
19
|
+
},
|
|
20
|
+
"branches": [
|
|
21
|
+
{
|
|
22
|
+
"id": "listed",
|
|
23
|
+
"field": "listed",
|
|
24
|
+
"optional": false
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"id": "providerRejected",
|
|
28
|
+
"field": "provider_rejected",
|
|
29
|
+
"optional": true
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"id": "invalidResponse",
|
|
33
|
+
"field": "invalid_response",
|
|
34
|
+
"optional": true
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"id": "defect",
|
|
38
|
+
"field": "defect",
|
|
39
|
+
"optional": true
|
|
40
|
+
}
|
|
41
|
+
]
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"name": "new_purge_cache_by_urls_step",
|
|
45
|
+
"kind": "mutation",
|
|
46
|
+
"operationId": "purgeCacheByURLs",
|
|
47
|
+
"fields": {
|
|
48
|
+
"stepType": "step_type",
|
|
49
|
+
"annotations": "annotations",
|
|
50
|
+
"connectionName": "connection_name",
|
|
51
|
+
"resultAttribute": "result_attribute"
|
|
52
|
+
},
|
|
53
|
+
"branches": [
|
|
54
|
+
{
|
|
55
|
+
"id": "purged",
|
|
56
|
+
"field": "purged",
|
|
57
|
+
"optional": false
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"id": "notFound",
|
|
61
|
+
"field": "not_found",
|
|
62
|
+
"optional": true
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"id": "providerRejected",
|
|
66
|
+
"field": "provider_rejected",
|
|
67
|
+
"optional": true
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
"id": "invalidResponse",
|
|
71
|
+
"field": "invalid_response",
|
|
72
|
+
"optional": true
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
"id": "defect",
|
|
76
|
+
"field": "defect",
|
|
77
|
+
"optional": true
|
|
78
|
+
}
|
|
79
|
+
]
|
|
80
|
+
}
|
|
81
|
+
]
|
|
82
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Typed Cloudflare zone pages and URL cache purges."""
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
|
|
7
|
+
from ._generated.models import ListZonesInput as ListZonesInput
|
|
8
|
+
from ._generated.models import PurgeCacheByURLsInput as PurgeCacheByURLsInput
|
|
9
|
+
from ._generated.models import Zone as Zone
|
|
10
|
+
from ._generated.models import ZonesPage as ZonesPage
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@dataclass(frozen=True, slots=True)
|
|
14
|
+
class PurgeRequest:
|
|
15
|
+
"""Cloudflare's purge request ID."""
|
|
16
|
+
|
|
17
|
+
id: str = ""
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass(frozen=True, slots=True)
|
|
21
|
+
class CachePurge:
|
|
22
|
+
"""Cloudflare's acceptance of the purge request, not a cache-miss guarantee."""
|
|
23
|
+
|
|
24
|
+
success: bool = False
|
|
25
|
+
result: PurgeRequest = PurgeRequest()
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
# connectorctl: model-alias CachePurgeResult=PurgeRequest
|
|
29
|
+
|
|
30
|
+
ListZonesInput.__doc__ = "Request for the default first page of Cloudflare zones; it carries no parameters."
|
|
31
|
+
Zone.__doc__ = "A zone's identifier used by cache operations, its DNS name, and its provider-reported status."
|
|
32
|
+
ZonesPage.__doc__ = "Cloudflare's success flag and one zone page, possibly empty."
|
|
33
|
+
PurgeCacheByURLsInput.__doc__ = "The zone whose cache is purged and 1 through 30 absolute HTTP or HTTPS URLs."
|
|
File without changes
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Public operation-specific Step factories from connector.yaml."""
|
|
4
|
+
|
|
5
|
+
from collections.abc import Callable as Callable
|
|
6
|
+
from collections.abc import Mapping as Mapping
|
|
7
|
+
from typing import TypeVar as TypeVar
|
|
8
|
+
|
|
9
|
+
import dex as dex
|
|
10
|
+
from dex_connectors.sdk import MutationResult as MutationResult
|
|
11
|
+
from dex_connectors.sdk import MutationStep as MutationStep
|
|
12
|
+
from dex_connectors.sdk import MutationStepConfig as MutationStepConfig
|
|
13
|
+
from dex_connectors.sdk import QueryResult as QueryResult
|
|
14
|
+
from dex_connectors.sdk import QueryStep as QueryStep
|
|
15
|
+
from dex_connectors.sdk import QueryStepConfig as QueryStepConfig
|
|
16
|
+
from dex_connectors.sdk import StepAnnotations as StepAnnotations
|
|
17
|
+
|
|
18
|
+
from ._generated.steps import (
|
|
19
|
+
StepInput as StepInput,
|
|
20
|
+
)
|
|
21
|
+
from ._generated.steps import (
|
|
22
|
+
new_list_zones_step as new_list_zones_step,
|
|
23
|
+
)
|
|
24
|
+
from ._generated.steps import (
|
|
25
|
+
new_purge_cache_by_urls_step as new_purge_cache_by_urls_step,
|
|
26
|
+
)
|
|
27
|
+
from .connection import Connection as Connection
|
|
28
|
+
from .models import CachePurge as CachePurge
|
|
29
|
+
from .models import ListZonesInput as ListZonesInput
|
|
30
|
+
from .models import PurgeCacheByURLsInput as PurgeCacheByURLsInput
|
|
31
|
+
from .models import ZonesPage as ZonesPage
|
|
32
|
+
|
|
33
|
+
BranchTarget = TypeVar("BranchTarget")
|
|
34
|
+
|
|
35
|
+
new_purge_cache_by_urls_step.__doc__ = (
|
|
36
|
+
"Create the typed cache purge Step; unwired optional outcomes fail the Flow."
|
|
37
|
+
)
|
|
38
|
+
new_list_zones_step.__doc__ = "Create the typed zone listing Step; unwired optional outcomes fail the Flow."
|