v0.4.0: Cloudflare Pages deploy tooling, items search in URL, spirit bear patch lookup
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
"""Probe a single Cloudflare Pages custom domain + its zone DNS record."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
|
||||
DOMAIN = "dota2.refining.dev"
|
||||
PROJECT = "climperor-relations"
|
||||
|
||||
|
||||
def cf(method: str, path: str, email: str, key: str) -> dict:
|
||||
url = "https://api.cloudflare.com/client/v4" + path
|
||||
req = urllib.request.Request(url, method=method, headers={
|
||||
"X-Auth-Email": email, "X-Auth-Key": key, "Content-Type": "application/json",
|
||||
})
|
||||
try:
|
||||
with urllib.request.urlopen(req) as r:
|
||||
return json.loads(r.read().decode())
|
||||
except urllib.error.HTTPError as e:
|
||||
return json.loads(e.read().decode())
|
||||
|
||||
|
||||
def main() -> None:
|
||||
email = os.environ.get("CLOUDFLARE_EMAIL") or os.environ.get("KEYZOO_ASSET_META_USERNAME")
|
||||
key = os.environ.get("CLOUDFLARE_API_KEY") or os.environ.get("KEYZOO_ASSET_SECRET_GLOBAL_API_KEY")
|
||||
d = cf("GET", "/accounts", email, key)
|
||||
aid = (d.get("result") or [{}])[0].get("id")
|
||||
|
||||
d = cf("GET", f"/accounts/{aid}/pages/projects/{PROJECT}/domains/{DOMAIN}", email, key)
|
||||
print("domain detail:")
|
||||
for k, v in (d.get("result") or {}).items():
|
||||
if k != "zone_id":
|
||||
print(f" {k}: {v}")
|
||||
|
||||
zd = cf("GET", "/zones?name=refining.dev", email, key)
|
||||
zr = zd.get("result") or []
|
||||
if not zr:
|
||||
print("zone refining.dev: NOT FOUND on this account")
|
||||
return
|
||||
zid = zr[0]["id"]
|
||||
recs = cf("GET", f"/zones/{zid}/dns_records?name={DOMAIN}", email, key)
|
||||
print(f"dns records for {DOMAIN}:")
|
||||
for rec in (recs.get("result") or []):
|
||||
print(f" {rec.get('type')} {rec.get('name')} -> {rec.get('content')} (proxied={rec.get('proxied')})")
|
||||
if not (recs.get("result") or []):
|
||||
print(" (none -- CNAME not added yet)")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user