Support making unauthenticated APIs requests by JSON ingester
Change-Id: I90ee25aea04559af720f573ff065da0c2b4b20e0 partially-implements: bp json-data-model
This commit is contained in:
parent
86a778ca59
commit
eb8520d684
|
@ -25,8 +25,10 @@ from oslo_config import cfg
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
import psycopg2
|
import psycopg2
|
||||||
from psycopg2 import sql
|
from psycopg2 import sql
|
||||||
|
import requests
|
||||||
|
|
||||||
from congress.datasources import datasource_utils
|
from congress.datasources import datasource_utils
|
||||||
|
from congress import exception
|
||||||
|
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
@ -45,14 +47,28 @@ class ExecApiManager(object):
|
||||||
for config in configs:
|
for config in configs:
|
||||||
# FIXME(json_ingester): validate config
|
# FIXME(json_ingester): validate config
|
||||||
if config.get('allow_exec_api', False) is True:
|
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']
|
name = config['name']
|
||||||
self._exec_api_endpoints[name] = (
|
self._exec_api_endpoints[name] = (
|
||||||
config.get('api_endpoint_host', '').rstrip('/') + '/'
|
config.get('api_endpoint_host', '').rstrip('/') + '/'
|
||||||
+ config.get('api_endpoint_path', '').lstrip('/'))
|
+ config.get('api_endpoint_path', '').lstrip('/'))
|
||||||
self._exec_api_sessions[
|
self._exec_api_sessions[name] = session
|
||||||
name] = datasource_utils.get_keystone_session(
|
|
||||||
config['authentication']['config'],
|
|
||||||
headers=config.get('api_default_headers', {}))
|
|
||||||
|
|
||||||
@lockutils.synchronized('congress_json_ingester_exec_api')
|
@lockutils.synchronized('congress_json_ingester_exec_api')
|
||||||
def evaluate_and_execute_actions(self):
|
def evaluate_and_execute_actions(self):
|
||||||
|
|
|
@ -26,6 +26,7 @@ from oslo_config import cfg
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
import psycopg2
|
import psycopg2
|
||||||
from psycopg2 import sql
|
from psycopg2 import sql
|
||||||
|
import requests
|
||||||
|
|
||||||
from congress.api import base as api_base
|
from congress.api import base as api_base
|
||||||
from congress.datasources import datasource_driver
|
from congress.datasources import datasource_driver
|
||||||
|
@ -214,10 +215,21 @@ class JsonIngester(datasource_driver.PollingDataSourceDriver):
|
||||||
self.update_methods[table_name] = method
|
self.update_methods[table_name] = method
|
||||||
|
|
||||||
def _initialize_session(self):
|
def _initialize_session(self):
|
||||||
if 'authentication' in self._config:
|
auth_config = self._config.get('authentication')
|
||||||
self._session = datasource_utils.get_keystone_session(
|
if auth_config is None:
|
||||||
self._config['authentication']['config'],
|
self._session = requests.Session()
|
||||||
headers=self._config.get('api_default_headers', {}))
|
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.'.auth_config['type'])
|
||||||
|
|
||||||
def _initialize_update_methods(self):
|
def _initialize_update_methods(self):
|
||||||
for table_name in self._config['tables']:
|
for table_name in self._config['tables']:
|
||||||
|
|
|
@ -115,7 +115,7 @@ PyYAML==3.10.0
|
||||||
reno==2.5.0
|
reno==2.5.0
|
||||||
repoze.lru==0.7
|
repoze.lru==0.7
|
||||||
requests-mock==1.2.0
|
requests-mock==1.2.0
|
||||||
requests==2.18.4
|
requests==2.14.2
|
||||||
requestsexceptions==1.4.0
|
requestsexceptions==1.4.0
|
||||||
rfc3986==1.1.0
|
rfc3986==1.1.0
|
||||||
Routes==2.3.1
|
Routes==2.3.1
|
||||||
|
|
|
@ -29,6 +29,7 @@ jsonpath-rw<2.0,>=1.2.0 # Apache-2.0
|
||||||
psycopg2>=2.7 # LGPL/ZPL
|
psycopg2>=2.7 # LGPL/ZPL
|
||||||
python-dateutil>=2.5.3 # BSD
|
python-dateutil>=2.5.3 # BSD
|
||||||
python-glanceclient>=2.8.0 # Apache-2.0
|
python-glanceclient>=2.8.0 # Apache-2.0
|
||||||
|
requests>=2.14.2,!=2.20.0 # Apache-2.0
|
||||||
Routes>=2.3.1 # MIT
|
Routes>=2.3.1 # MIT
|
||||||
six>=1.10.0 # MIT
|
six>=1.10.0 # MIT
|
||||||
tenacity>=4.4.0 # Apache-2.0
|
tenacity>=4.4.0 # Apache-2.0
|
||||||
|
|
Loading…
Reference in New Issue