From: Frank Brehm Date: Thu, 3 Aug 2017 10:49:09 +0000 (+0200) Subject: Extended configuration of PpConfigNamedApp X-Git-Tag: 0.1.2~148 X-Git-Url: https://git.uhu-banane.net/?a=commitdiff_plain;h=a9be4f9a2d63254cb74ffce5ceee6eb82ff3e02d;p=pixelpark%2Fadmin-tools.git Extended configuration of PpConfigNamedApp --- diff --git a/pp_lib/config_named_app.py b/pp_lib/config_named_app.py index adac6f6..cdaf8be 100644 --- a/pp_lib/config_named_app.py +++ b/pp_lib/config_named_app.py @@ -29,7 +29,7 @@ from .common import pp, to_bool from .cfg_app import PpCfgAppError, PpConfigApplication -__version__ = '0.2.0' +__version__ = '0.2.1' LOG = logging.getLogger(__name__) @@ -48,6 +48,7 @@ class PpConfigNamedApp(PpConfigApplication): default_pdns_api_port = 8081 default_pdns_api_root_path = '/api/v1/servers/localhost' default_named_conf = '/etc/named.conf' + default_named_zones_cfg_dir = '/etc/named' default_named_basedir = '/var/named' default_named_datadir = os.path.join(default_named_basedir, 'data') default_named_slavedir = os.path.join(default_named_basedir, 'slaves') @@ -73,6 +74,7 @@ class PpConfigNamedApp(PpConfigApplication): self.is_internal = False self.named_listen_on_v6 = False self.named_conf = self.default_named_conf + self.named_zones_cfg_dir = self.default_named_zones_cfg_dir self.zone_masters = copy.copy(self.default_zone_masters) self.named_user = 'named' @@ -193,16 +195,9 @@ class PpConfigNamedApp(PpConfigApplication): else: self.pdns_api_port = port - if 'root_path' in section: - path = section['root_path'] - if not os.path.isabs(path): - msg = ( - "The root path of the PowerDNS must be an absolute pathname " - "(found [{}]/root_path => {!r} in configuration.").format(section_name, path) - LOG.error(msg) - self.config_has_errors = True - else: - self.pdns_api_root_path = path + self._check_path_config( + section, section_name, 'root_path', + 'pdns_api_root_path', True, 'root path of the PowerDNS') if 'key' in section: key = section['key'].strip() @@ -224,9 +219,63 @@ class PpConfigNamedApp(PpConfigApplication): if 'query_log' in section: self.query_log = to_bool(section['query_log']) + if 'listen_on_v6' in section and section['listen_on_v6'] is not None: + self.named_listen_on_v6 = to_bool(section['listen_on_v6']) + + if 'dnssec' in section and section['dnssec'] is not None: + self.named_dnssec = to_bool(section['dnssec']) + + self._check_path_config(section, section_name, 'named_conf', 'named_conf', True) + self._check_path_config(section, section_name, 'zones_cfg_dir', 'named_zones_cfg_dir', True) + self._check_path_config(section, section_name, 'base_dir', 'named_basedir', True) + self._check_path_config(section, section_name, 'data_dir', 'named_datadir', False) + self._check_path_config(section, section_name, 'slave_dir', 'named_slavedir', False) + self._check_path_config( + section, section_name, 'iscdlv_key_file', 'named_iscdlv_key_file', True) + self._check_path_config(section, section_name, 'run_dir', 'named_rundir', True) + self._check_path_config(section, section_name, 'log_dir', 'named_logdir', True) + + if 'show_bind_version' in section and section['show_bind_version'] is not None: + self.named_show_bind_version = to_bool(section['show_bind_version']) + + if 'version_to_show' in section and section['version_to_show'] is not None: + self.named_version2show = section['version_to_show'].strip() + + if 'named_user' in section and section['named_user'] is not None: + self.named_user = section['named_user'].strip() + if 'named_group' in section and section['named_group'] is not None: + self.named_group = section['named_group'].strip() + if 'masters' in section: self._get_masters_from_cfg(section['masters'], section_name) + # ------------------------------------------------------------------------- + def _check_path_config(self, section, section_name, key, class_prop, absolute=True, desc=None): + + if key not in section: + return + + d = '' + if desc: + d = ' ' + str(desc).strip() + + path = section[key].strip() + if not path: + msg = "No path given for{} [{}]/{} in configuration.".format( + d, section_name, key) + LOG.error(msg) + self.config_has_errors = True + return + + if absolute and not os.path.isabs(path): + msg = "Path {!r} for{} [{}]/{} in configuration must be an absolute path.".format( + path, d, section_name, key) + LOG.error(msg) + self.config_has_errors = True + return + + setattr(self, class_prop, path) + # ------------------------------------------------------------------------- def _get_masters_from_cfg(self, value, section_name):