def _create_client(self, zone_name): config = LexiconConfigResolver() dynamic_config = OnTheFlyLexiconConfigSource(zone_name) config.with_config_source(dynamic_config) \ .with_env().with_dict(self.lexicon_config) try: return LexiconClient(config), dynamic_config except AttributeError as e: self.log.error('Unable to parse config {!s}'.format(config)) raise e
def authenticate(self): """ Launch the authentication process: for 'auto' provider, it means first to find the relevant provider, then call its authenticate() method. Almost every subsequent operation will then be delegated to that provider. """ mapping_override = self.config.resolve('lexicon:auto:mapping_override') print(mapping_override) mapping_override_processed = {} if mapping_override: for one_mapping in mapping_override.split(','): one_mapping_processed = one_mapping.split(':') mapping_override_processed[ one_mapping_processed[0]] = one_mapping_processed[1] override_provider = mapping_override_processed.get(self.domain) if override_provider: provider = [ element for element in AVAILABLE_PROVIDERS.items() if element[0] == override_provider ][0] LOGGER.info('Provider authoritatively mapped for domain %s: %s.', self.domain, provider.__name__) (provider_name, provider_module) = provider else: (provider_name, provider_module) = _relevant_provider_for_domain(self.domain) LOGGER.info('Provider discovered for domain %s: %s.', self.domain, provider_name) new_config = ConfigResolver() new_config.with_dict({'lexicon:provider_name': provider_name}) target_prefix = 'auto_{0}_'.format(provider_name) for configSource in self.config._config_sources: if not isinstance(configSource, ArgsConfigSource): new_config.with_config_source(configSource) else: # ArgsConfigSource needs to be reprocessed to rescope the provided # args to the delegate provider new_dict = {} for key, value in configSource._parameters.items(): if key.startswith(target_prefix): new_param_name = re.sub('^{0}'.format(target_prefix), '', key) new_dict['lexicon:{0}:{1}'.format( provider_name, new_param_name)] = value elif not key.startswith('auto_'): new_dict['lexicon:{0}'.format(key)] = value new_config.with_dict(new_dict) self.proxy_provider = provider_module.Provider(new_config) self.proxy_provider.authenticate()
def _test_config(self): """ This method construct a ConfigResolver suitable for tests. This will resolve any parameters required by Lexicon or the provider in the following order: * parameters that matches the ones provided by _test_parameters_overrides * parameters that matches existing environment variables at the time of test execution * parameters processed throught the lambda provided by _test_fallback_fn. See lexicon/providers/base.py for a full list of parameters available. You should not override this method. Just override `self.domain`, or use _test_parameters_overrides() to configure specific parameters for the tests. Any parameters that you expect to be passed to the provider via the cli, like --auth_username and --auth_token, will be present during the tests, with a 'placeholder_' prefix. options['auth_password'] == 'placeholder_auth_password' options['auth_username'] == 'placeholder_auth_username' options['unique_provider_option'] == 'placeholder_unique_provider_option' You can change this behavior by overriding _test_fallback_fn(). """ config = ConfigResolver() # First we load the overrides overrides = self._test_parameters_overrides() overrides['domain'] = self.domain overrides['provider_name'] = self.provider_name config.with_config_source(EngineOverrideConfigSource(overrides)) # Then we get environment variables config.with_env() # And finally we provide the fallback function config.with_config_source( FallbackConfigSource(self._test_fallback_fn())) return config