2024-04-11 13:17:58 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import os
|
2024-04-10 18:13:16 -04:00
|
|
|
import json
|
|
|
|
import logging
|
2024-04-11 13:17:58 -04:00
|
|
|
import time
|
2024-04-10 18:13:16 -04:00
|
|
|
|
|
|
|
from updater.adapter import HatecomputersDNSAdapter
|
2024-04-11 13:17:58 -04:00
|
|
|
from updater.utils import record_transformer
|
2024-04-10 18:13:16 -04:00
|
|
|
from args import get_args
|
|
|
|
|
|
|
|
|
2024-04-11 13:17:58 -04:00
|
|
|
def certbot_mode(args, dns_api_adapter, record_transformer):
|
|
|
|
domain = args.certbot_domain
|
|
|
|
if domain.startswith("*."):
|
|
|
|
domain = domain[2:]
|
|
|
|
logging.info(f"processing domain {domain}")
|
|
|
|
|
|
|
|
record = {
|
|
|
|
"ttl": 60,
|
|
|
|
"name": "_acme-challenge." + domain,
|
|
|
|
"type": "TXT",
|
|
|
|
"content": args.certbot_validation,
|
|
|
|
}
|
|
|
|
record = record_transformer(record)
|
|
|
|
logging.info(f"creating record {record}")
|
|
|
|
dns_api_adapter.post_record(record)
|
|
|
|
|
|
|
|
logging.info(
|
|
|
|
f"eeping out for {args.dns_propogate_time}s, to allow DNS propogation. look at this cute little guy 🐢 until then!!"
|
|
|
|
)
|
|
|
|
time.sleep(args.dns_propogate_time)
|
|
|
|
|
|
|
|
logging.info(f"updating record for {domain} with {args.certbot_validation}")
|
2024-04-10 18:13:16 -04:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
args = get_args()
|
|
|
|
logging.basicConfig()
|
|
|
|
logging.root.setLevel(args.log_level)
|
|
|
|
|
|
|
|
api_key = open(args.api_key_file, "r").read().strip()
|
2024-04-11 13:17:58 -04:00
|
|
|
dns_api_adapter = HatecomputersDNSAdapter(args.endpoint, api_key)
|
2024-04-10 18:13:16 -04:00
|
|
|
|
2024-04-11 13:17:58 -04:00
|
|
|
if args.create:
|
|
|
|
records_file = open(args.records_file, "r")
|
|
|
|
dns_records = json.load(records_file)
|
|
|
|
dns_api_adapter.post_records(dns_records)
|
2024-04-10 18:13:16 -04:00
|
|
|
|
|
|
|
if args.certbot:
|
2024-04-11 13:17:58 -04:00
|
|
|
certbot_mode(
|
|
|
|
args,
|
|
|
|
dns_api_adapter,
|
|
|
|
record_transformer(args.public_suffixes),
|
|
|
|
)
|
|
|
|
|
|
|
|
logging.info("done")
|