Initial Pantheon infrastructure
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import os
|
||||
import yaml
|
||||
import requests
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
|
||||
TOKEN = os.getenv("CF_API_TOKEN")
|
||||
ZONE = os.getenv("CF_ZONE_ID")
|
||||
|
||||
headers = {
|
||||
"Authorization": f"Bearer {TOKEN}",
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
|
||||
url = f"https://api.cloudflare.com/client/v4/zones/{ZONE}/dns_records"
|
||||
|
||||
records = requests.get(url, headers=headers).json()["result"]
|
||||
|
||||
data = {
|
||||
"zone": "mrredportal.com",
|
||||
"defaults": {
|
||||
"ttl": 1,
|
||||
"proxied": False,
|
||||
},
|
||||
"records": {},
|
||||
}
|
||||
|
||||
for r in records:
|
||||
name = r["name"].replace(".mrredportal.com", "")
|
||||
|
||||
data["records"][name] = {
|
||||
"type": r["type"],
|
||||
"content": r["content"],
|
||||
"proxied": r["proxied"],
|
||||
"ttl": r["ttl"],
|
||||
}
|
||||
|
||||
with open("dns.yaml", "w") as f:
|
||||
yaml.dump(data, f, sort_keys=True)
|
||||
|
||||
print("dns.yaml written.")
|
||||
|
||||
Reference in New Issue
Block a user