aboutsummaryrefslogtreecommitdiffstats
path: root/arthur/apis/cloudflare/zones.py
diff options
context:
space:
mode:
authorGravatar ChrisJL <[email protected]>2022-08-21 23:04:15 +0100
committerGravatar GitHub <[email protected]>2022-08-21 23:04:15 +0100
commitdde3773ecb76775edc50e2d13937e07f0970c1d9 (patch)
treef0f3426ff0cbc3f00a47f0761f1173512a51312e /arthur/apis/cloudflare/zones.py
parentAdd missing space to prefix list (diff)
parentCreate dependabot.yml (diff)
Merge pull request #15 from python-discord/bot-core-integration
Diffstat (limited to 'arthur/apis/cloudflare/zones.py')
-rw-r--r--arthur/apis/cloudflare/zones.py20
1 files changed, 12 insertions, 8 deletions
diff --git a/arthur/apis/cloudflare/zones.py b/arthur/apis/cloudflare/zones.py
index 81a54f1..7d407a0 100644
--- a/arthur/apis/cloudflare/zones.py
+++ b/arthur/apis/cloudflare/zones.py
@@ -8,30 +8,34 @@ from arthur.config import CONFIG
AUTH_HEADER = {"Authorization": f"Bearer {CONFIG.cloudflare_token}"}
-async def list_zones(zone_name: Optional[str] = None) -> dict[str, str]:
+async def list_zones(
+ session: aiohttp.ClientSession,
+ zone_name: Optional[str] = None,
+) -> dict[str, str]:
"""List all Cloudflare zones."""
endpoint = "https://api.cloudflare.com/client/v4/zones"
if zone_name is not None:
endpoint += f"?name={zone_name}"
- async with aiohttp.ClientSession() as session:
- async with session.get(endpoint, headers=AUTH_HEADER) as response:
- info = await response.json()
+ async with session.get(endpoint, headers=AUTH_HEADER) as response:
+ info = await response.json()
zones = info["result"]
return {zone["name"]: zone["id"] for zone in zones}
-async def purge_zone(zone_identifier: str) -> dict:
+async def purge_zone(
+ session: aiohttp.ClientSession,
+ zone_identifier: str,
+) -> dict:
"""Purge the cache for a Cloudflare zone."""
endpoint = f"https://api.cloudflare.com/client/v4/zones/{zone_identifier}/purge_cache"
request_body = {"purge_everything": True}
- async with aiohttp.ClientSession() as session:
- async with session.post(endpoint, headers=AUTH_HEADER, json=request_body) as response:
- info = await response.json()
+ async with session.post(endpoint, headers=AUTH_HEADER, json=request_body) as response:
+ info = await response.json()
return {"success": info["success"], "errors": info["errors"]}