aboutsummaryrefslogtreecommitdiff
path: root/ascension
diff options
context:
space:
mode:
authorrexxnor <rexxnor+gnunet@brief.li>2019-05-01 17:38:45 +0200
committerrexxnor <rexxnor+gnunet@brief.li>2019-05-01 17:38:45 +0200
commitc1ee00c35074ef188ecd9a416dd98fe55aa37b7a (patch)
treea22e7435f6193cdf88cf8555e8141ee883f7c2ca /ascension
parentd63e299e150ad557300a404e604fc922bf1ebb7f (diff)
downloadascension-c1ee00c35074ef188ecd9a416dd98fe55aa37b7a.tar.gz
ascension-c1ee00c35074ef188ecd9a416dd98fe55aa37b7a.zip
further refactoring, type defintions and version bump, updated manpage
Diffstat (limited to 'ascension')
-rw-r--r--ascension/ascension.py57
1 files changed, 32 insertions, 25 deletions
diff --git a/ascension/ascension.py b/ascension/ascension.py
index 3f035db..8815d5f 100644
--- a/ascension/ascension.py
+++ b/ascension/ascension.py
@@ -82,7 +82,12 @@ class Ascender():
82 """ 82 """
83 Class that provides migration for any given domain 83 Class that provides migration for any given domain
84 """ 84 """
85 def __init__(self, domain, transferns, port, flags, minimum): 85 def __init__(self,
86 domain: str,
87 transferns: str,
88 port: str,
89 flags: str,
90 minimum: str) -> None:
86 self.domain = domain 91 self.domain = domain
87 if domain[-1] == '.': 92 if domain[-1] == '.':
88 self.domain = self.domain[:-1] 93 self.domain = self.domain[:-1]
@@ -97,7 +102,7 @@ class Ascender():
97 self.minimum = int(minimum) 102 self.minimum = int(minimum)
98 self.subzonedict = dict() 103 self.subzonedict = dict()
99 104
100 def bootstrap_zone(self): 105 def bootstrap_zone(self) -> None:
101 """ 106 """
102 Creates the zone in gnunet 107 Creates the zone in gnunet
103 """ 108 """
@@ -108,7 +113,9 @@ class Ascender():
108 except sp.CalledProcessError: 113 except sp.CalledProcessError:
109 logging.info("Zone %s already exists!", self.domain) 114 logging.info("Zone %s already exists!", self.domain)
110 115
111 def get_dns_zone_serial(self, domain, resolver=None): 116 def get_dns_zone_serial(self,
117 domain: str,
118 resolver=None) -> dns.rdatatype.SOA:
112 """ 119 """
113 Gets the current serial for a given zone 120 Gets the current serial for a given zone
114 :param domain: Domain to query for in DNS 121 :param domain: Domain to query for in DNS
@@ -154,7 +161,7 @@ class Ascender():
154 self.transferns = str(soa_record[2].mname) 161 self.transferns = str(soa_record[2].mname)
155 return soa_record[2].serial 162 return soa_record[2].serial
156 163
157 def add_records_to_gns(self): 164 def add_records_to_gns(self) -> None:
158 """ 165 """
159 Extracts records from zone and adds them to GNS 166 Extracts records from zone and adds them to GNS
160 :raises AttributeError: When getting incomplete data 167 :raises AttributeError: When getting incomplete data
@@ -347,7 +354,9 @@ class Ascender():
347 logging.info("All records have been added!") 354 logging.info("All records have been added!")
348 355
349 @staticmethod 356 @staticmethod
350 def add_recordline_to_gns(recordline, zonename, label): 357 def add_recordline_to_gns(recordline: list,
358 zonename: str,
359 label: str) -> None:
351 """ 360 """
352 Replaces records in zone or adds them if not 361 Replaces records in zone or adds them if not
353 :param recordline: records to replace as list in form 362 :param recordline: records to replace as list in form
@@ -370,7 +379,11 @@ class Ascender():
370 logging.info("successfully added record with command %s", 379 logging.info("successfully added record with command %s",
371 ' '.join(ret.args)) 380 ' '.join(ret.args))
372 381
373 def transform_to_gns_format(self, record, rdtype, zonename, label): 382 def transform_to_gns_format(self,
383 record: dns.rdata.Rdata,
384 rdtype: dns.rdata.Rdata,
385 zonename: str,
386 label: str) -> tuple:
374 """ 387 """
375 Transforms value of record to GNS compatible format 388 Transforms value of record to GNS compatible format
376 :param record: record to transform 389 :param record: record to transform
@@ -469,7 +482,7 @@ class Ascender():
469 logging.info("Did not transform record of type: %s", rdtype) 482 logging.info("Did not transform record of type: %s", rdtype)
470 return (rdtype, value, label) 483 return (rdtype, value, label)
471 484
472 def get_gns_zone_serial(self): 485 def get_gns_zone_serial(self) -> int:
473 """ 486 """
474 Fetches the zones serial from GNS 487 Fetches the zones serial from GNS
475 :returns: serial of the SOA record in GNS 488 :returns: serial of the SOA record in GNS
@@ -481,24 +494,16 @@ class Ascender():
481 serial = serial.decode() 494 serial = serial.decode()
482 except sp.CalledProcessError: 495 except sp.CalledProcessError:
483 serial = "" 496 serial = ""
484 soa_serial = None 497 soa_serial = 0
485 soapattern = re.compile(r'.+\s(\d+),\d+,\d+,\d+,\d+', re.M) 498 soapattern = re.compile(r'.+\s(\d+),\d+,\d+,\d+,\d+', re.M)
486 if re.findall(soapattern, serial): 499 if re.findall(soapattern, serial):
487 soa_serial = re.findall(soapattern, serial)[0] 500 soa_serial = re.findall(soapattern, serial)[0]
488 else: 501 else:
489 soa_serial = None 502 soa_serial = 0
490 return soa_serial 503 return soa_serial
491 504
492 def get_zone_soa_expiry(self):
493 """
494 Extracts the current serial from the class SOA
495 :returns: refresh time of the current SOA record
496 """
497 ttlpattern = re.compile(r'.+\s\d+\s(\d+)\s\d+\s\d+\s\d+', re.M)
498 return re.findall(ttlpattern, str(self.soa[2]))
499
500 @staticmethod 505 @staticmethod
501 def get_zone_soa(zone): 506 def get_zone_soa(zone) -> dns.rdatatype.SOA:
502 """ 507 """
503 Fetches soa record from zone a given zone 508 Fetches soa record from zone a given zone
504 :param zone: A dnspython zone 509 :param zone: A dnspython zone
@@ -510,7 +515,7 @@ class Ascender():
510 soa = soarecord 515 soa = soarecord
511 return soa 516 return soa
512 517
513 def add_soa_record_to_gns(self, record): 518 def add_soa_record_to_gns(self, record) -> None:
514 """ 519 """
515 Adds a SOA record to GNS 520 Adds a SOA record to GNS
516 :param record: The record to add 521 :param record: The record to add
@@ -539,7 +544,7 @@ class Ascender():
539 self.add_recordline_to_gns(recordline, self.domain, str(label)) 544 self.add_recordline_to_gns(recordline, self.domain, str(label))
540 545
541 @staticmethod 546 @staticmethod
542 def create_zone_and_get_pkey(zonestring): 547 def create_zone_and_get_pkey(zonestring: str) -> str:
543 """ 548 """
544 Creates the zone in zonestring and returns pkey 549 Creates the zone in zonestring and returns pkey
545 :param zonestring: The label name of the zone 550 :param zonestring: The label name of the zone
@@ -569,7 +574,10 @@ class Ascender():
569 return pkey_zone 574 return pkey_zone
570 575
571 @staticmethod 576 @staticmethod
572 def add_pkey_record_to_zone(pkey, domain, label, ttl): 577 def add_pkey_record_to_zone(pkey: str,
578 domain: str,
579 label: str,
580 ttl: str) -> None:
573 """ 581 """
574 Adds the pkey of the subzone to the parent zone 582 Adds the pkey of the subzone to the parent zone
575 :param pkey: the public key of the child zone 583 :param pkey: the public key of the child zone
@@ -600,10 +608,9 @@ class Ascender():
600 label, domain) 608 label, domain)
601 #logging.warning("PKEY record %s already exists in %s", label, domain) 609 #logging.warning("PKEY record %s already exists in %s", label, domain)
602 610
603 def create_zone_hierarchy(self): 611 def create_zone_hierarchy(self) -> None:
604 """ 612 """
605 Creates the zone hierarchy in GNS for label 613 Creates the zone hierarchy in GNS for label
606 :param label: the split record to create zones for
607 """ 614 """
608 domain = self.domain 615 domain = self.domain
609 616
@@ -624,13 +631,13 @@ def main():
624 Initializes object and handles arguments 631 Initializes object and handles arguments
625 """ 632 """
626 # argument parsing from docstring definition 633 # argument parsing from docstring definition
627 args = docopt.docopt(__doc__, version='Ascension 0.5.0') 634 args = docopt.docopt(__doc__, version='Ascension 0.6.0')
628 635
629 # argument parsing 636 # argument parsing
630 debug = args['--debug'] 637 debug = args['--debug']
631 domain = args.get('<domain>', None) 638 domain = args.get('<domain>', None)
632 transferns = args['<transferns>'] if args['<transferns>'] else None 639 transferns = args['<transferns>'] if args['<transferns>'] else None
633 port = args['<port>'] if args['<port>'] else 53 640 port = args['<port>'] if args['<port>'] else "53"
634 flags = "p" if args.get('--public') else "n" 641 flags = "p" if args.get('--public') else "n"
635 standalone = bool(args.get('--standalone')) 642 standalone = bool(args.get('--standalone'))
636 minimum = args['--minimum-ttl'] 643 minimum = args['--minimum-ttl']