]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Finishing get all named keys
authorFrank Brehm <frank@brehm-online.com>
Tue, 7 Dec 2021 15:24:33 +0000 (16:24 +0100)
committerFrank Brehm <frank@brehm-online.com>
Tue, 7 Dec 2021 15:24:33 +0000 (16:24 +0100)
lib/pp_admintools/deploy_zones_from_pdns.py

index 1495f4e964d6888433f74bb4089a88ac3904652a..e6f54700e4bf11ca95ba9b9c078256adbe7806d0 100644 (file)
@@ -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):