# from .config import ConfigError, BaseConfiguration
from fb_tools.multi_config import DEFAULT_ENCODING
+from . import __version__ as GLOBAL_VERSION
+from . import MAX_TIMEOUT, MAX_PORT_NUMBER
+
from .mail_config import MailConfigError, MailConfiguration
-from .mail_config import DEFAULT_CONFIG_DIR, MAX_PORT_NUMBER
+from .mail_config import DEFAULT_CONFIG_DIR
from .xlate import XLATOR
-MAX_PDNS_API_TIMEOUT = 3600
+LIBRARY_NAME = "pp-pdns-api-client"
-__version__ = '0.1.2'
+__version__ = '0.1.3'
LOG = logging.getLogger(__name__)
_ = XLATOR.gettext
and methods to read it from configuration files.
"""
+ valid_pdns_api_instances = ('global', 'public', 'local')
+
default_pdns_api_instances = {
'global': {
'host': "dnsmaster.pp-dns.com",
additional_config_file=None, additional_cfgdirs=None, encoding=DEFAULT_ENCODING,
ensure_privacy=True, use_chardet=True, initialized=False):
+ self.api_user_agent = '{}/{}'.format(LIBRARY_NAME, GLOBAL_VERSION)
+
self.pdns_api_instances = {}
for inst_name in self.default_pdns_api_instances.keys():
res['default_pdns_api_servername'] = self.default_pdns_api_servername
res['default_pdns_timeout'] = self.default_pdns_timeout
res['default_pdns_instance'] = self.default_pdns_instance
+ res{'valid_pdns_api_instances'] = self.valid_pdns_api_instances
res['pdns_api_instances'] = {}
for iname in self.pdns_api_instances.keys():
msg = _("Evaluating config section {!r}:").format(section_name)
LOG.debug(msg + '\n' + pp(section))
+ self._eval_api_user_agent(section_name, section)
self._eval_pdns_timeout(section_name, section)
self._eval_pdns_instances(section_name, section)
+ # -------------------------------------------------------------------------
+ def _eval_api_user_agent(self, section_name, section):
+
+ re_agent = re.compile(r'^\s*(?:api[_-]?)?user[_-]?agent\s*$', re.IGNORECASE)
+
+ for key in section.keys():
+ if not re_agent.search(key):
+ continue
+
+ val = section[key].strip()
+ if val:
+ self.api_user_agent = val
+
# -------------------------------------------------------------------------
def _eval_pdns_timeout(self, section_name, section):
val = section[key]
try:
timeout = int(val)
- if timeout <= 0 or timeout > MAX_PDNS_API_TIMEOUT:
+ if timeout <= 0 or timeout > MAX_TIMEOUT:
msg = _("A timeout has to be between 1 and {} seconds.")
- msg = msg.format(MAX_PDNS_API_TIMEOUT)
+ msg = msg.format(MAX_TIMEOUT)
raise ValueError(msg)
except (ValueError, TypeError) as e:
msg = _("Value {!r} for PowerDNS API timeout is invalid:").format(val)