hc-cert-dns/updater/adapter.py

25 lines
764 B
Python
Raw Normal View History

2024-04-10 18:13:16 -04:00
import requests
import time
import logging
class HatecomputersDNSAdapter:
def __init__(self, endpoint, api_key, logger=None):
self.endpoint = endpoint
self.session = requests.Session()
self.headers = {"Authorization": "Bearer " + api_key}
self.logger = logger or logging.getLogger(__name__)
def post_record(self, record):
endpoint = self.endpoint + "/dns"
self.logger.info(f"adding {record} to {endpoint}")
self.session.post(endpoint, headers=self.headers, data=record)
def post_records(self, dns_entries, eepy_time=0.25):
for record in dns_entries:
self.post_record(record)
2024-04-10 18:17:08 -04:00
self.logger.info(f"eeping out for {eepy_time}s")
2024-04-10 18:13:16 -04:00
time.sleep(eepy_time)