Enhancements: Upgraded Actions, Improved Logging, Restructured Project (#1)
* update python project use setup tools, and upgrade github action version * add manual run trigger * add check not found check * remove TODO as not possible * Update doc and add default value of non required config --------- Co-authored-by: Snigdhajyoti Ghosh <snigdhasjg@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
f601634857
commit
2c9b686062
44
docker_nsupdate_ddns/lib/nsupdate.py
Normal file
44
docker_nsupdate_ddns/lib/nsupdate.py
Normal file
@@ -0,0 +1,44 @@
|
||||
import logging
|
||||
|
||||
import dns.update
|
||||
import dns.query
|
||||
import dns.tsigkeyring
|
||||
import ipaddress
|
||||
|
||||
config = {}
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def add_records(records):
|
||||
keyring = dns.tsigkeyring.from_text({config['TSIG_NAME']: config['TSIG_KEY']})
|
||||
|
||||
for hostname, ip in records.items():
|
||||
LOG.info(f"Adding record for {hostname}({ip})")
|
||||
|
||||
rrtype = "A"
|
||||
address = ipaddress.ip_address(ip)
|
||||
if isinstance(address, ipaddress.IPv4Address):
|
||||
rrtype = "A"
|
||||
if isinstance(address, ipaddress.IPv6Address):
|
||||
rrtype = "AAAA"
|
||||
|
||||
update = dns.update.Update(config['DOMAIN'], keyring=keyring)
|
||||
update.add(hostname, int(config['DNS_RECORD_TTL']), rrtype, ip)
|
||||
dns.query.tcp(update, config['NAMESERVER'], timeout=2)
|
||||
|
||||
|
||||
def delete_records(records):
|
||||
keyring = dns.tsigkeyring.from_text({config['TSIG_NAME']: config['TSIG_KEY']})
|
||||
|
||||
for hostname, ip in records.items():
|
||||
LOG.info(f"Deleting record for {hostname}({ip})")
|
||||
|
||||
update = dns.update.Update(config['DOMAIN'], keyring=keyring)
|
||||
update.delete(hostname)
|
||||
dns.query.tcp(update, config['NAMESERVER'], timeout=2)
|
||||
|
||||
|
||||
def init(_config):
|
||||
global config
|
||||
config = _config
|
||||
Reference in New Issue
Block a user