Initial test
This commit is contained in:
parent
2d9a070514
commit
312d872adc
5 changed files with 171 additions and 13 deletions
|
|
@ -1,3 +1,4 @@
|
|||
import json
|
||||
import logging
|
||||
import subprocess
|
||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||
|
|
@ -16,6 +17,8 @@ def _get_ip(resolvers):
|
|||
except subprocess.CalledProcessError as e:
|
||||
raise OSError("Unable to retrieve current IP") from e
|
||||
|
||||
return output.decode("utf-8").strip()
|
||||
|
||||
|
||||
def _get_domain(domain, token, api_url):
|
||||
headers = {"Authorization": f"Bearer {token}"}
|
||||
|
|
@ -43,7 +46,7 @@ def _get_domain_data(domains, token, api_url):
|
|||
yield {"domain": domain, **response.json()}
|
||||
|
||||
|
||||
def _update_domain(domain, payload, token, api_url):
|
||||
def _update_domain(domain, payload, api_url, token):
|
||||
headers = {"Authorization": f"Bearer {token}"}
|
||||
|
||||
return requests.put(
|
||||
|
|
@ -51,13 +54,13 @@ def _update_domain(domain, payload, token, api_url):
|
|||
)
|
||||
|
||||
|
||||
def _update_domains(updated_domains, token, read_only):
|
||||
def _update_domains(updated_domains, api_url, token, read_only):
|
||||
if read_only:
|
||||
return
|
||||
|
||||
with ThreadPoolExecutor(max_workers=10) as executor:
|
||||
futures = {
|
||||
executor.submit(_update_domain, domain, entries, token): domain
|
||||
executor.submit(_update_domain, domain, entries, api_url, token): domain
|
||||
for domain, entries in updated_domains.items()
|
||||
}
|
||||
|
||||
|
|
@ -74,7 +77,7 @@ def _update_domains(updated_domains, token, read_only):
|
|||
logger.info(f"Updated domain {domain}")
|
||||
|
||||
|
||||
def detect(domains, resolvers, token, api_url, read_only):
|
||||
def detect(domains, resolvers, api_url, token, read_only):
|
||||
ip = _get_ip(resolvers)
|
||||
domain_data = _get_domain_data(domains, token, api_url)
|
||||
updated_domains = {}
|
||||
|
|
@ -97,4 +100,4 @@ def detect(domains, resolvers, token, api_url, read_only):
|
|||
|
||||
updated_domains[domain] = {"dnsEntries": updated_entries}
|
||||
|
||||
_update_domains(updated_domains, token, api_url, read_only)
|
||||
_update_domains(updated_domains, api_url, token, read_only)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue