Exemple #1
0
    def __init__(self, configs):
        super(ExecApiManager, self).__init__()
        self._exec_api_sessions = {}
        self._exec_api_endpoints = {}
        # state tracking the most recent state consisting of the union
        # of all the rows from all the _exec_api tables
        # used to determine which rows are new
        self._last_exec_api_state = set([])

        for config in configs:
            # FIXME(json_ingester): validate config
            if config.get('allow_exec_api', False) is True:
                auth_config = config.get('authentication')
                if auth_config is None:
                    session = requests.Session()
                    session.headers.update(
                        config.get('api_default_headers', {}))
                else:
                    if auth_config['type'] == 'keystone':
                        session = datasource_utils.get_keystone_session(
                            config['authentication']['config'],
                            headers=config.get('api_default_headers', {}))
                    else:
                        LOG.error('authentication type %s not supported.',
                                  auth_config.get['type'])
                        raise exception.BadConfig(
                            'authentication type {} not '
                            'supported.'.auth_config['type'])

                name = config['name']
                self._exec_api_endpoints[name] = config['api_endpoint']
                self._exec_api_sessions[name] = session
Exemple #2
0
 def load_drivers(self):
     """Load all configured drivers and check no name conflict"""
     result = {}
     for driver_path in cfg.CONF.drivers:
         # Note(thread-safety): blocking call?
         obj = importutils.import_class(driver_path)
         driver = obj.get_datasource_info()
         if driver['id'] in result:
             raise exception.BadConfig(
                 _("There is a driver loaded already"
                   "with the driver name of %s") % driver['id'])
         driver['module'] = driver_path
         result[driver['id']] = driver
     return result
Exemple #3
0
 def validate_config(config):
     # FIXME: use json schema to validate config
     config_tables = config['tables']
     poll_tables = [
         table for table in config_tables
         if 'poll' in config_tables[table]
     ]
     if len(poll_tables) > 0:
         # FIXME: when polling table exists, require configs:
         # api_endpoint, authentication
         pass
     for table_name in config_tables:
         if ('poll' in config_tables[table_name]
                 and 'webhook' in config_tables[table_name]):
             raise exception.BadConfig(
                 'Table ({}) cannot be configured for '
                 'both poll and webhook.'.format(table_name))
Exemple #4
0
 def _initialize_session(self):
     auth_config = self._config.get('authentication')
     if auth_config is None:
         self._session = requests.Session()
         self._session.headers.update(
             self._config.get('api_default_headers', {}))
     else:
         if auth_config['type'] == 'keystone':
             self._session = datasource_utils.get_keystone_session(
                 self._config['authentication']['config'],
                 headers=self._config.get('api_default_headers', {}))
         else:
             LOG.error('authentication type %s not supported.',
                       auth_config.get['type'])
             raise exception.BadConfig(
                 'authentication type {} not supported.'.format(
                     auth_config['type']))