45 lines
1.1 KiB
Python
45 lines
1.1 KiB
Python
# flake8: noqa
|
|
import os
|
|
import subprocess
|
|
import json
|
|
from pprint import pp
|
|
import httpx
|
|
import dns.zone
|
|
|
|
# todo: dnspython to read builtins.toString vacuconfig.x86_64-linux.vacu.dns."jean-luc.org"
|
|
|
|
SOPS_BIN = "@sops@"
|
|
DNS_SECRETS_FILE = "@dns_secrets_file@"
|
|
data_str = "@data@"
|
|
DATA = json.loads(data_str)
|
|
|
|
secrets_json = subprocess.check_output([SOPS_BIN, "-d", DNS_SECRETS_FILE])
|
|
secrets = json.loads(secrets_json)
|
|
|
|
AUTH_ID = secrets["auth_id"]
|
|
AUTH_PASSWORD = secrets["auth_password"]
|
|
|
|
BASE_URL = "https://api.cloudns.net"
|
|
|
|
def req(path, **kwargs):
|
|
auth_params = {
|
|
"auth-id": AUTH_ID,
|
|
"auth-password": AUTH_PASSWORD,
|
|
}
|
|
|
|
params = { k.replace("_","-"): v for k, v in kwargs.items() }
|
|
|
|
return httpx.get(BASE_URL + path, params={**auth_params, **params}).json()
|
|
|
|
for name, zone_str in DATA.items():
|
|
zone = dns.zone.from_text(zone_str, origin=name)
|
|
pp(zone)
|
|
for name in zone:
|
|
node = zone.find_node(name)
|
|
pp(node)
|
|
for smth in node:
|
|
pp(smth)
|
|
# res = req("/dns/records.json", domain_name = "jean-luc.org", rows_per_page = 100)
|
|
#records = [x for x in res.values()]
|
|
# pp(res.get("status"))
|