Added conditional deletion of dumped file after we are done

master
Ruakij 3 years ago
parent 002e2e4613
commit 43ed39f5d4

@ -121,6 +121,7 @@ def readYamlFile(file: str):
return yaml.load(f, Loader=yaml.FullLoader) return yaml.load(f, Loader=yaml.FullLoader)
def updateNsData(zone): def updateNsData(zone):
hasToDelete = False
try: try:
zone = str(zone)[:-1] zone = str(zone)[:-1]
adaptedZone = adaptZoneName(zone) adaptedZone = adaptZoneName(zone)
@ -132,6 +133,8 @@ def updateNsData(zone):
raise Exception("Dumping data failed!") raise Exception("Dumping data failed!")
zone = adaptedZone zone = adaptedZone
hasToDelete = True
adaptFileForRequire(zone, dumpFile) adaptFileForRequire(zone, dumpFile)
if dnscontrolPush(zone) != 0: if dnscontrolPush(zone) != 0:
raise Exception("Pushing data failed!") raise Exception("Pushing data failed!")
@ -141,8 +144,9 @@ def updateNsData(zone):
log.error(f'{adaptedZone} |\t{sys.exc_info()}') log.error(f'{adaptedZone} |\t{sys.exc_info()}')
log.error(f'{adaptedZone} |\tUpdating NS-Data failed!') log.error(f'{adaptedZone} |\tUpdating NS-Data failed!')
if(hasToDelete):
deleteFile(dumpFile)
def adaptZoneName(zone): def adaptZoneName(zone):
if config['zone']['public-suffix'] != "" and zone.endswith(config['zone']['public-suffix']): if config['zone']['public-suffix'] != "" and zone.endswith(config['zone']['public-suffix']):
adaptedZone = zone[:-len(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}'..") log.debug(f"{zone} |\tDumping to '{dumpFile}'..")
return os.system(f"dnscontrol get-zones --format=js --out={dumpFile} powerdns POWERDNS {zone}") 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\()" ignoreLinesRexp = r"^\s*(var|D\(|DnsProvider\(|DefaultTTL\()"
def adaptFileForRequire(zone, dumpFile): def adaptFileForRequire(zone, dumpFile):
log.debug(f"{zone} |\tRewriting file '{dumpFile}'..") log.debug(f"{zone} |\tRewriting file '{dumpFile}'..")

Loading…
Cancel
Save