MAX_PDNS_API_TIMEOUT = 3600
-__version__ = '0.1.0'
+__version__ = '0.1.1'
LOG = logging.getLogger(__name__)
_ = XLATOR.gettext
res['default_pdns_timeout'] = self.default_pdns_timeout
res['default_pdns_instance'] = self.default_pdns_instance
+ res['pdns_api_instances'] = {}
+ for iname in self.pdns_api_instances.keys():
+ inst = self.pdns_api_instances[iname]
+ res['pdns_api_instances'][iname] = copy.copy(inst)
+ if 'key' in inst:
+ if self.verbose <= 4:
+ res['pdns_api_instances'][iname]['key'] = '******'
+
return res
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------
def _eval_pdns_inst_host(self, iname, section):
- pass
+ if self.verbose > 2
+ msg = _("Searching for host for PDNS instance {!r} ..")
+ LOG.debug(msg.format(iname)
+
+ for key in section.keys():
+ if key.lower() == 'host':
+ host = section[key].lower().strip()
+ if host:
+ if self.verbose > 2:
+ msg = _("Found host for PDNS instance {inst!r}: {host!r}.")
+ LOG.debug(msg.format(inst=iname, host=host))
+ self.pdns_api_instances[iname]['host'] = host
# -------------------------------------------------------------------------
def _eval_pdns_inst_port(self, iname, section):
- pass
+ if self.verbose > 2
+ msg = _("Searching for post number for PDNS instance {!r} ..")
+ LOG.debug(msg.format(iname)
+
+ for key in section.keys():
+ if key.lower() == 'port':
+ port = None
+ val = section[key]
+ try:
+ port = int(val)
+ if port <= 0 or port > MAX_PORT_NUMBER:
+ msg = _("A port must be greater than 0 and less than {}.")
+ raise ValueError(msg.format(MAX_PORT_NUMBER)
+ except (TypeError, ValueError) as e:
+ msg = _("Wrong port number {p!r} for PDNS instance {inst!r} found: {e}")
+ msg = msg.format(p=val, inst=iname, e=e)
+ if self.raise_on_error:
+ raise PdnsConfigError(msg)
+ else:
+ LOG.error(msg)
+ port = None
+ if port:
+ if self.verbose > 2:
+ msg = _("Found port number for PDNS instance {inst!r}: {p}.")
+ LOG.debug(msg.format(inst=iname, p=port))
+ self.pdns_api_instances[iname]['port'] = port
# -------------------------------------------------------------------------
def _eval_pdns_inst_servername(self, iname, section):
- pass
+ if self.verbose > 2
+ msg = _("Searching for internal server name of PDNS instance {!r} ..")
+ LOG.debug(msg.format(iname)
+
+ re_servername = re.compile(r'^\s*server[_-]?(name|id)\s*$', re.IGNORECASE)
+
+ for key in section.keys():
+ if re_servername.search(key):
+ servername = section[key].lower().strip()
+ if servername:
+ if self.verbose > 2:
+ msg = _("Found internal server name PDNS instance {inst!r}: {sn!r}.")
+ LOG.debug(msg.format(inst=iname, sn=servername))
+ self.pdns_api_instances[iname]['servername'] = servername
# -------------------------------------------------------------------------
def _eval_pdns_inst_key(self, iname, section):
- pass
-
-# re_cc = re.compile(r'^\s*(mail[_-]?)?cc\s*$', re.IGNORECASE)
-#
-# for key in section.keys():
-#
-# self._mail_cc_configured = True
-# if not re_cc.search(key):
-# continue
-#
-# val = section[key]
-# if not val:
-# continue
-# if is_sequence(val):
-# for v in val:
-# result = self._split_mailaddress_tokens(v, _("cc mail address"))
-# if result:
-# self.mail_cc.expand(result)
-# else:
-# result = self._split_mailaddress_tokens(val, _("cc mail address"))
-# if result:
-# self.mail_cc.expand(result)
-#
-# # -------------------------------------------------------------------------
-# def _eval_mail_reply_to(self, section_name, section):
-#
-# re_reply = re.compile(r'^\s*(mail[_-]?)?reply([-_]?to)?\s*$', re.IGNORECASE)
-#
-# for key in section.keys():
-# if not re_reply.search(key):
-# continue
-#
-# val = section[key]
-#
-# if is_sequence(val):
-# if not len(val):
-# continue
-# val = val[0]
-#
-# if MailAddress.valid_address(val):
-# self.reply_to = val
-# else:
-# msg = _("Found invalid {what} {addr!r} in configuration.")
-# LOG.error(msg.format(what=_("reply to address"), addr=val))
-#
-# # -------------------------------------------------------------------------
-# def _eval_mail_method(self, section_name, section):
-#
-# re_method = re.compile(r'^\s*(mail[_-]?)?method\s*$', re.IGNORECASE)
-#
-# for key in section.keys():
-# if not re_reply.search(key):
-# continue
-#
-# val = section[key].strip().lower()
-# if not val:
-# continue
-#
-# if val not in self.valid_mail_methods:
-# msg = _("Found invalid mail method {!r} in configuration.")
-# LOG.error(msg.format(section[key]))
-# continue
-#
-# self.mail_method = val
-#
-# # -------------------------------------------------------------------------
-# def _eval_mail_server(self, section_name, section):
-#
-# re_server = re.compile(r'^\s*(mail[_-]?)?server\s*$', re.IGNORECASE)
-#
-# for key in section.keys():
-# if not re_server.search(key):
-# continue
-#
-# val = section[key].strip().lower()
-# if not val:
-# continue
-#
-# self.mail_server = val
-#
-# # -------------------------------------------------------------------------
-# def _eval_smtp_port(self, section_name, section):
-#
-# re_server = re.compile(r'^\s*(smtp[_-]?)?port\s*$', re.IGNORECASE)
-#
-# for key in section.keys():
-# if not re_server.search(key):
-# continue
-#
-# val = section[key]
-# try:
-# port = int(val)
-# except (ValueError, TypeError) as e:
-# msg = _("Value {!r} for SMTP port is invalid:").format(val)
-# LOG.error(msg)
-# continue
-# if port <= 0 or port > MAX_PORT_NUMBER:
-# msg = _("Found invalid SMTP port number {} in configuration.").format(port)
-# LOG.error(msg)
-# continue
-#
-# self.smtp_port = port
+ if self.verbose > 2
+ msg = _("Searching for API key of PDNS instance {!r} ..")
+ LOG.debug(msg.format(iname)
+
+ re_key = re.compile(r'^\s*(api[_-]?)?key\s*$', re.IGNORECASE)
+
+ for key in section.keys():
+ if re_key.search(key):
+ api_key = section[key].lower().strip()
+ if api_key:
+ if self.verbose > 2:
+ key_show = '******'
+ if self.verbose > 4:
+ key_show = api_key
+ msg = _("Found API key of PDNS instance {inst!r}: {key!r}.")
+ LOG.debug(msg.format(inst=iname, key=key_show))
+ self.pdns_api_instances[iname]['key'] = api_key
+
# =============================================================================
if __name__ == "__main__":