ascension

Migrate DNS zones to the GNU Name System
Log | Files | Refs | README | LICENSE

commit 7e8b3fe81e448734f7cccc96cbeb6163f74bae89
parent 4ab581df8f99d1fe65ce15fe5c60984ad358dba2
Author: rexxnor <rexxnor+gnunet@brief.li>
Date:   Thu,  9 May 2019 21:38:01 +0200

fixed too long lines, added newest way to get PKEY of zone

Diffstat:
Mascension/ascension.py | 39+++++++++++++++++++++++++--------------
1 file changed, 25 insertions(+), 14 deletions(-)

diff --git a/ascension/ascension.py b/ascension/ascension.py @@ -284,13 +284,14 @@ class Ascender(): # => bar PKEY GNS $NEWKEY + mapping: bar => $NEWKEY # => foo[.bar] A GNS 1.2.3.4 #gnspkey = list(filter(lambda record: for rec in record[2]: if str(rec).startswith('gns--pkey--'): return true; return false, nsrecords)) + illegalchars = ["I", "L", "O", "U", "i", "l", "o", "u"] for nsrecord in nsrecords: name = str(nsrecord[0]) values = nsrecord[1] ttl = values.ttl - #if values.startswith('gns--pkey--'): - # gnspkeys.add() - gnspkeys = list(filter(lambda record: str(record).startswith('gns--pkey--'), values)) + + gnspkeys = list(filter(lambda record: str(record).startswith('gns--pkey--') + and illegalchars not in str(record[11:]), values)) num_gnspkeys = len(gnspkeys) if not num_gnspkeys: @@ -302,9 +303,10 @@ class Ascender(): continue gnspkey = str(gnspkeys[0]) - # FIXME: check that this is actucally a well-formed PKEY string! (Crockford base32, sufficient length) - self.add_pkey_record_to_zone(gnspkey[11:], self.domain, name, ttl) - # FIXME: drop all NS records under this name later! => new map, if entry present during NS processing, skip! + # FIXME: drop all NS records under this name later! + # => new map, if entry present during NS processing, skip! + if not any(illegal in gnspkey for illegal in illegalchars): + self.add_pkey_record_to_zone(gnspkey[11:], self.domain, name, ttl) # Unify all records under same label into a record set customrdataset = dict() @@ -331,7 +333,7 @@ class Ascender(): if value.ttl <= self.minimum: ttl = self.minimum else: - ttl = rdataset.ttl + ttl = value.ttl except AttributeError: ttl = self.minimum @@ -462,15 +464,20 @@ class Ascender(): if label.startswith("@"): value = '%s@%s' % (zonename, nameserver) else: - value = '%s.%s@%s' % (str(label), zonename, nameserver) + value = '%s.%s@%s' % (str(label), + zonename, + nameserver) else: # Name is relative to zone, must be in bailiwick value = self.resolve_glue(record.target) if not value: if label.startswith("@"): - value = '%s@%s.%s' % (self.domain, record.target, self.domain) + value = '%s@%s.%s' % (self.domain, + record.target, + self.domain) else: - value = '%s.%s@%s.%s' % (str(label), self.domain, record.target, self.domain) + value = '%s.%s@%s.%s' % (str(label), self.domain, + record.target, self.domain) logging.info("transformed %s record to GNS2DNS format", rdtype) rdtype = 'GNS2DNS' @@ -591,13 +598,17 @@ class Ascender(): '-C', zonestring, '-V'], stdout=sp.PIPE, - stderr=sp.DEVNULL) + stderr=sp.DEVNULL, + check=True) logging.info("executed command: %s", " ".join(ret.args)) pkey_zone = ret.stdout.decode().strip() except sp.CalledProcessError: - output = ret.stdout.decode().strip() - pkey_zone = re.findall("^[\w\d]{52}$", output, re.M)[0] - logging.info("Zone %s already exists!", zonestring) + ret = sp.run([GNUNET_ZONE_CREATION_COMMAND, + '-dq', + '-e', zonestring], + stdout=sp.PIPE) + logging.info("executed command: %s", " ".join(ret.args)) + pkey_zone = ret.stdout.decode().strip() return pkey_zone @staticmethod