58 lines
1.5 KiB
Python
Executable File
58 lines
1.5 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import os
|
|
import json
|
|
import logging
|
|
import time
|
|
|
|
from updater.adapter import HatecomputersDNSAdapter
|
|
from updater.utils import record_transformer
|
|
from args import get_args
|
|
|
|
|
|
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}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
args = get_args()
|
|
logging.basicConfig()
|
|
logging.root.setLevel(args.log_level)
|
|
|
|
api_key = open(args.api_key_file, "r").read().strip()
|
|
dns_api_adapter = HatecomputersDNSAdapter(args.endpoint, api_key)
|
|
|
|
if args.create:
|
|
records_file = open(args.records_file, "r")
|
|
dns_records = json.load(records_file)
|
|
dns_api_adapter.post_records(dns_records)
|
|
|
|
if args.certbot:
|
|
certbot_mode(
|
|
args,
|
|
dns_api_adapter,
|
|
record_transformer(args.public_suffixes),
|
|
)
|
|
|
|
logging.info("done")
|