catch exceptions of dns.tsigkeyring.from_text(), fixes #338, fixes #319

This commit is contained in:
Thomas Waldmann 2018-09-28 23:43:04 +02:00
parent 917dacfceb
commit 837103fdd7

View File

@ -16,6 +16,7 @@ UPDATE_TIMEOUT = float(os.environ.get('DNS_UPDATE_TIMEOUT', '20.0'))
UNAVAILABLE_RETRY = 120.0 UNAVAILABLE_RETRY = 120.0
import binascii
import time import time
from datetime import timedelta from datetime import timedelta
from collections import namedtuple from collections import namedtuple
@ -332,9 +333,13 @@ def update_ns(fqdn, rdtype='A', ipaddr=None, action='upd', ttl=60):
assert isinstance(fqdn, FQDN) assert isinstance(fqdn, FQDN)
assert action in ['add', 'del', 'upd', ] assert action in ['add', 'del', 'upd', ]
nameserver, nameserver2, origin, domain, name, keyname, key, algo = get_ns_info(fqdn) nameserver, nameserver2, origin, domain, name, keyname, key, algo = get_ns_info(fqdn)
upd = dns.update.Update(origin, try:
keyring=dns.tsigkeyring.from_text({keyname: key}), keyring = dns.tsigkeyring.from_text({keyname: key})
keyalgorithm=algo) except (UnicodeError, binascii.Error) as e:
msg = "Exception when building keyring for %s: [%s]" % (keyname, str(e))
logger.error(msg)
raise DnsUpdateError(msg)
upd = dns.update.Update(origin, keyring=keyring, keyalgorithm=algo)
if action == 'add': if action == 'add':
assert ipaddr is not None assert ipaddr is not None
upd.add(name, ttl, rdtype, ipaddr) upd.add(name, ttl, rdtype, ipaddr)