From 43ed39f5d4a354e2dde0a0be6ff56be80308e682 Mon Sep 17 00:00:00 2001 From: Ruakij Date: Mon, 2 Aug 2021 14:25:26 +0200 Subject: [PATCH] Added conditional deletion of dumped file after we are done --- daemon.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/daemon.py b/daemon.py index 3528eab..d525be7 100755 --- a/daemon.py +++ b/daemon.py @@ -121,6 +121,7 @@ def readYamlFile(file: str): return yaml.load(f, Loader=yaml.FullLoader) def updateNsData(zone): + hasToDelete = False try: zone = str(zone)[:-1] adaptedZone = adaptZoneName(zone) @@ -132,6 +133,8 @@ def updateNsData(zone): raise Exception("Dumping data failed!") zone = adaptedZone + hasToDelete = True + adaptFileForRequire(zone, dumpFile) if dnscontrolPush(zone) != 0: raise Exception("Pushing data failed!") @@ -141,8 +144,9 @@ def updateNsData(zone): log.error(f'{adaptedZone} |\t{sys.exc_info()}') log.error(f'{adaptedZone} |\tUpdating NS-Data failed!') + if(hasToDelete): + deleteFile(dumpFile) - def adaptZoneName(zone): if config['zone']['public-suffix'] != "" and zone.endswith(config['zone']['public-suffix']): adaptedZone = zone[:-len(config['zone']['public-suffix'])] @@ -153,6 +157,10 @@ def dumpZoneData(zone, dumpFile): log.debug(f"{zone} |\tDumping to '{dumpFile}'..") return os.system(f"dnscontrol get-zones --format=js --out={dumpFile} powerdns POWERDNS {zone}") +def deleteFile(file): + log.debug(f"Deleting file '{file}'") + os.remove(file) + ignoreLinesRexp = r"^\s*(var|D\(|DnsProvider\(|DefaultTTL\()" def adaptFileForRequire(zone, dumpFile): log.debug(f"{zone} |\tRewriting file '{dumpFile}'..")