From: Frank Brehm Date: Tue, 7 Dec 2021 15:24:33 +0000 (+0100) Subject: Finishing get all named keys X-Git-Tag: 0.4.1~5^2~5 X-Git-Url: https://git.uhu-banane.net/?a=commitdiff_plain;h=4e9db1dbe71ca620eb676b439ddcd1bfe79dd456;p=pixelpark%2Fpp-admin-tools.git Finishing get all named keys --- diff --git a/lib/pp_admintools/deploy_zones_from_pdns.py b/lib/pp_admintools/deploy_zones_from_pdns.py index 1495f4e..e6f5470 100644 --- a/lib/pp_admintools/deploy_zones_from_pdns.py +++ b/lib/pp_admintools/deploy_zones_from_pdns.py @@ -472,7 +472,7 @@ class PpDeployZonesApp(PpPDNSApplication): result = super(BaseApplication, self).run( cmd, stdout=PIPE, stderr=PIPE, timeout=10, check=True, may_simulate=False) - if self.verbose > 2: + if self.verbose > 3: LOG.debug(_("Result:") + '\n' + str(result)) config = result.stdout @@ -480,6 +480,8 @@ class PpDeployZonesApp(PpPDNSApplication): key_pattern = r'^\s*key\s+("[^"]+"|\S+)\s+\{([^\}]+)\}\s*;' re_quotes = re.compile(r'^\s*"([^"]+)"\s*$') re_key = re.compile(key_pattern, re.IGNORECASE | re.MULTILINE | re.DOTALL) + re_algo = re.compile(r'^\s*algorithm\s+"([^"]+)"\s*;', re.IGNORECASE) + re_secret = re.compile(r'^\s*secret\s+"([^"]+)"\s*;', re.IGNORECASE) for match in re_key.finditer(config): match_quotes = re_quotes.match(match[1]) @@ -488,9 +490,34 @@ class PpDeployZonesApp(PpPDNSApplication): else: key_name = match[1] key_data = match[2].strip() - if self.verbose > 1: + if self.verbose > 2: LOG.debug("Found key {!r}:".format(key_name) + '\n' + key_data) + algorithm = None + secret = None + + for line in key_data.splitlines(): + # Searching for algorithm + match_algo = re_algo.search(line) + if match_algo: + algorithm = match_algo[1] + # Searching for secret + match_secret = re_secret.search(line) + if match_secret: + secret = match_secret[1] + + if algorithm and secret: + self.named_keys[key_name] = { + 'algorithm': algorithm, + 'secret': secret, + } + + if self.verbose > 1: + if self.named_keys: + LOG.debug(_("Found named keys:") + '\n' + pp(self.named_keys)) + else: + LOG.debug(_("Found named keys:") + ' ' + _('None')) + # ------------------------------------------------------------------------- def generate_slave_cfg_file(self): @@ -754,29 +781,6 @@ class PpDeployZonesApp(PpPDNSApplication): return False return True -# std_out = None -# std_err = None -# ret_val = None - -# with Popen(cmd, stdout=PIPE, stderr=PIPE) as proc: -# try: -# std_out, std_err = proc.communicate(timeout=10) -# except TimeoutExpired: -# proc.kill() -# std_out, std_err = proc.communicate() -# ret_val = proc.wait() - -# LOG.debug(_("Return value: {!r}").format(ret_val)) -# if std_out and std_out.strip(): -# LOG.warn(_("Output on {}").format('STDOUT') + ' ' + to_str(std_out.strip())) -# if std_err and std_err.strip(): -# LOG.warn(_("Output on {}").format('STDERR') + ' ' + to_str(std_err.strip())) - -# if ret_val: -# return False - -# return True - # ------------------------------------------------------------------------- def apply_config(self):