From e781ec160c8d1f51fad3f1baaa2e5b5a32fb358b Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Tue, 7 Nov 2017 17:28:25 +0100 Subject: [PATCH] Fixing pp_lib/pdns_app.py --- pp_lib/pdns_app.py | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/pp_lib/pdns_app.py b/pp_lib/pdns_app.py index 2b5b63f..a6a9a8e 100644 --- a/pp_lib/pdns_app.py +++ b/pp_lib/pdns_app.py @@ -24,8 +24,9 @@ from .common import pp, to_bool from .cfg_app import PpCfgAppError, PpConfigApplication -__version__ = '0.1.0' +__version__ = '0.1.1' LOG = logging.getLogger(__name__) +_LIBRARY_NAME = "pp-pdns-api-client" # ============================================================================= @@ -68,9 +69,29 @@ class PpPDNSApplication(PpConfigApplication): self._api_host = self.api_hosts['global'] self._api_port = self.default_api_port self._api_servername = self.default_api_servername - self._user_agent = '{}/{}'.format(_LIBRARY_NAME, __version__) + self._user_agent = '{}/{}'.format(_LIBRARY_NAME,self.version) self._environment = 'global' + stems = [] + if cfg_stems: + if isinstance(cfg_stems, list): + for stem in cfg_stems: + s = str(stem).strip() + if not s: + msg = "Invalid configuration stem {!r} given.".format(stem) + raise PpLdapAppError(msg) + stems.append(s) + else: + s = str(cfg_stems).strip() + if not s: + msg = "Invalid configuration stem {!r} given.".format(cfg_stems) + raise PpLdapAppError(msg) + stems.append(s) + else: + stems = [self.appname] + if 'pdns-api' not in stems: + stems.insert(0, 'pdns-api') + super(PpPDNSApplication, self).__init__( appname=appname, verbose=verbose, version=version, base_dir=base_dir, initialized=False, usage=usage, description=description, @@ -123,7 +144,7 @@ class PpPDNSApplication(PpConfigApplication): return self._api_servername @api_servername.setter - def api_servername(self.value): + def api_servername(self, value): if value is None or str(value).strip() == '': raise PpPDNSAppError("Invalid API server name {!r} given.".format(value)) self._api_servername = str(value).strip() @@ -135,7 +156,7 @@ class PpPDNSApplication(PpConfigApplication): return self._user_agent @user_agent.setter - def user_agent(self.value): + def user_agent(self, value): if value is None or str(value).strip() == '': raise PpPDNSAppError("Invalid user agent {!r} given.".format(value)) self._user_agent = str(value).strip() @@ -197,13 +218,18 @@ class PpPDNSApplication(PpConfigApplication): pdns_group = self.arg_parser.add_argument_group('PowerDNS API options') env_group = pdns_group.add_mutually_exclusive_group() + envs = [] + for env in self.api_keys.keys(): + envs.append(str(env)) + envs.sort() + env_group.add_argument( '-E', '--env', '--environment', - metavar="ENVIRONMENT", choices=self.api_keys.keys().sort(), dest="env", + metavar="ENVIRONMENT", choices=envs, dest="env", help=( "Select, which PowerDNS environment to use. " "Valid values: {v}, default: {d!r}.".format( - v=', '.join(map(lambda x: repr(x), self.api_keys.keys().sort())), + v=', '.join(map(lambda x: repr(x), envs)), d='global')) ) -- 2.39.5