def test_zmq_client_configure_eslogger(self): dummy_ep = importlib.metadata.EntryPoint( 'dummy', 'test.test_plugins:DummyEventTarget', 'es_logger.plugins.event_target') dummy2_ep = importlib.metadata.EntryPoint( 'dummy2', 'test.test_plugins:DummyEventTarget', 'es_logger.plugins.event_target') ExtensionManager.ENTRY_POINT_CACHE = { 'es_logger.plugins.event_target': [dummy_ep, dummy2_ep] } with unittest.mock.patch( 'configparser.ConfigParser') as mock_config_parser: config = self.config_setup(mock_config_parser) self.set_default_config(config) self.set_eslogger_targets_config(config) self.zmqd.configure() # Reset stevedore ExtensionManager.ENTRY_POINT_CACHE = {} mgr = ExtensionManager(namespace='es_logger.plugins.event_target', invoke_on_load=False) mgr.names() # Perform validation after resetting stevedore state expected_targets = { 'dummy': { 'var1': 'var1' }, 'dummy2': { 'var2': 'var2', 'var3': 'var3' } } nose.tools.ok_( self.zmqd.targets == expected_targets, "{} did not match {}".format(expected_targets, self.zmqd.targets))
def list_opts(): """Returns a list of oslo.config options available in the library. The returned list includes all oslo.config options which may be registered at runtime by the library. Each element of the list is a tuple. The first element is the name of the group under which the list of elements in the second element will be registered. A group name of None corresponds to the [DEFAULT] group in config files. The purpose of this is to allow tools like the Oslo sample config file generator to discover the options exposed to users by this library. :returns: a list of (group_name, opts) tuples """ key_manager_opts = [] key_manager_opts.extend(key_manager.key_manager_opts) key_manager_opts.extend(utils.credential_opts) opts = [('key_manager', key_manager_opts)] ext_mgr = ExtensionManager("castellan.drivers", invoke_on_load=True, invoke_args=[cfg.CONF]) for driver in ext_mgr.names(): opts.extend(ext_mgr[driver].obj.list_options_for_discovery()) return opts
def get_event_target_plugin_help(): ret = '' mgr = ExtensionManager(namespace='es_logger.plugins.event_target', invoke_on_load=False) for target_plugin in mgr.names(): # All known target plugins drv = driver.DriverManager( namespace='es_logger.plugins.event_target', invoke_on_load=False, name=target_plugin) ret = ret + '\n{}'.format(drv.driver.get_help_string()) return ret
def set_defaults(conf, backend=None, barbican_endpoint=None, barbican_api_version=None, auth_endpoint=None, retry_delay=None, number_of_retries=None, verify_ssl=None, api_class=None, vault_root_token_id=None, vault_approle_role_id=None, vault_approle_secret_id=None, vault_kv_mountpoint=None, vault_url=None, vault_ssl_ca_crt_file=None, vault_use_ssl=None, barbican_endpoint_type=None): """Set defaults for configuration values. Overrides the default options values. :param conf: Config instance in which to set default options. :param api_class: The full class name of the key manager API class. :param barbican_endpoint: Use this endpoint to connect to Barbican. :param barbican_api_version: Version of the Barbican API. :param auth_endpoint: Use this endpoint to connect to Keystone. :param retry_delay: Use this attribute to set retry delay. :param number_of_retries: Use this attribute to set number of retries. :param verify_ssl: Use this to specify if ssl should be verified. :param vault_root_token_id: Use this for the root token id for vault. :param vault_approle_role_id: Use this for the approle role_id for vault. :param vault_approle_secret_id: Use this for the approle secret_id for vault. :param vault_kv_mountpoint: Mountpoint of KV store in vault to use. :param vault_url: Use this for the url for vault. :param vault_use_ssl: Use this to force vault driver to use ssl. :param vault_ssl_ca_crt_file: Use this for the CA file for vault. :param barbican_endpoint_type: Use this to specify the type of URL. : Valid values are: public, internal or admin. """ conf.register_opts(key_manager.key_manager_opts, group='key_manager') ext_mgr = ExtensionManager("castellan.drivers", invoke_on_load=True, invoke_args=[cfg.CONF]) for km in ext_mgr.names(): for group, opts in ext_mgr[km].obj.list_options_for_discovery(): conf.register_opts(opts, group=group) # Use the new backend option if set or fall back to the older api_class default_backend = backend or api_class if default_backend is not None: conf.set_default('backend', default_backend, group='key_manager') if bkm is not None: if barbican_endpoint is not None: conf.set_default('barbican_endpoint', barbican_endpoint, group=bkm._BARBICAN_OPT_GROUP) if barbican_api_version is not None: conf.set_default('barbican_api_version', barbican_api_version, group=bkm._BARBICAN_OPT_GROUP) if auth_endpoint is not None: conf.set_default('auth_endpoint', auth_endpoint, group=bkm._BARBICAN_OPT_GROUP) if retry_delay is not None: conf.set_default('retry_delay', retry_delay, group=bkm._BARBICAN_OPT_GROUP) if number_of_retries is not None: conf.set_default('number_of_retries', number_of_retries, group=bkm._BARBICAN_OPT_GROUP) if verify_ssl is not None: conf.set_default('verify_ssl', verify_ssl, group=bkm._BARBICAN_OPT_GROUP) if barbican_endpoint_type is not None: conf.set_default('barbican_endpoint_type', barbican_endpoint_type, group=bkm._BARBICAN_OPT_GROUP) if vkm is not None: if vault_root_token_id is not None: conf.set_default('root_token_id', vault_root_token_id, group=vkm._VAULT_OPT_GROUP) if vault_approle_role_id is not None: conf.set_default('approle_role_id', vault_approle_role_id, group=vkm._VAULT_OPT_GROUP) if vault_approle_secret_id is not None: conf.set_default('approle_secret_id', vault_approle_secret_id, group=vkm._VAULT_OPT_GROUP) if vault_kv_mountpoint is not None: conf.set_default('kv_mountpoint', vault_kv_mountpoint, group=vkm._VAULT_OPT_GROUP) if vault_url is not None: conf.set_default('vault_url', vault_url, group=vkm._VAULT_OPT_GROUP) if vault_ssl_ca_crt_file is not None: conf.set_default('ssl_ca_crt_file', vault_ssl_ca_crt_file, group=vkm._VAULT_OPT_GROUP) if vault_use_ssl is not None: conf.set_default('use_ssl', vault_use_ssl, group=vkm._VAULT_OPT_GROUP)
def generate_events(self, esl): """ Parse the console log and return a list to send as events :param console_log: A dictionary with string keys and simple types as :type console_log: str :returns: list(dict(str:?)) """ LOGGER.debug("Starting: {}".format(type(self).__name__)) output_list = [] regex_list = [] """ Load all console log plugins """ mgr = ExtensionManager( namespace='es_logger.plugins.event_generator.console_log_events', invoke_on_load=False) for plugin in mgr.names(): # All known console_log_events plugins drv = driver.DriverManager( namespace= 'es_logger.plugins.event_generator.console_log_events', invoke_on_load=False, name=plugin) regex_list = drv.driver.get_regex(regex_list) LOGGER.debug( 'Loaded plugins from {}, regex_list now with {} elements'. format(plugin, len(regex_list))) """ Look for a json file with additional regex's """ regex_filename = 'console_log_event_regex.json' if os.path.isfile(regex_filename): LOGGER.debug( "Loading console_log_regex's from {}".format(regex_filename)) with open(regex_filename, 'r') as regex_file: regex_data = json.loads(regex_file) for regex in regex_data: regex_list.append((regex['name'], re.compile(regex['pattern'], re.MULTILINE))) else: LOGGER.debug( "{} not found, not loading additional console_log_event_regex's" .format(regex_filename)) """ Processing """ for regex_name, run_regex in regex_list: LOGGER.debug("Starting regex: {}".format(regex_name)) for regex_match in run_regex.finditer(esl.console_log): add_event = { 'name': regex_name, 'match': regex_match.group(0), 'named_matches': regex_match.groupdict() } output_list.append(add_event) LOGGER.debug("Finished regex: {}".format(regex_name)) LOGGER.debug("Finished: {}".format(type(self).__name__)) # Return the data return output_list
def tearDown(self): ExtensionManager.ENTRY_POINT_CACHE = {} mgr = ExtensionManager(namespace='es_logger.plugins.event_target', invoke_on_load=False) mgr.names()