aboutsummaryrefslogtreecommitdiffstats
path: root/keystonemiddleware-moon/keystonemiddleware/audit.py
diff options
context:
space:
mode:
Diffstat (limited to 'keystonemiddleware-moon/keystonemiddleware/audit.py')
-rw-r--r--keystonemiddleware-moon/keystonemiddleware/audit.py51
1 files changed, 35 insertions, 16 deletions
diff --git a/keystonemiddleware-moon/keystonemiddleware/audit.py b/keystonemiddleware-moon/keystonemiddleware/audit.py
index f44da80d..e3536092 100644
--- a/keystonemiddleware-moon/keystonemiddleware/audit.py
+++ b/keystonemiddleware-moon/keystonemiddleware/audit.py
@@ -30,7 +30,7 @@ import sys
from oslo_config import cfg
from oslo_context import context
try:
- import oslo.messaging
+ import oslo_messaging
messaging = True
except ImportError:
messaging = False
@@ -46,6 +46,7 @@ from pycadf import reporterstep
from pycadf import resource
from pycadf import tag
from pycadf import timestamp
+import six
from six.moves import configparser
from six.moves.urllib import parse as urlparse
import webob.dec
@@ -79,6 +80,16 @@ AuditMap = collections.namedtuple('AuditMap',
'default_target_endpoint_type'])
+# NOTE(blk-u): Compatibility for Python 2. SafeConfigParser and
+# SafeConfigParser.readfp are deprecated in Python 3. Remove this when we drop
+# support for Python 2.
+if six.PY2:
+ class _ConfigParser(configparser.SafeConfigParser):
+ read_file = configparser.SafeConfigParser.readfp
+else:
+ _ConfigParser = configparser.ConfigParser
+
+
class OpenStackAuditApi(object):
def __init__(self, cfg_file):
@@ -90,8 +101,8 @@ class OpenStackAuditApi(object):
if cfg_file:
try:
- map_conf = configparser.SafeConfigParser()
- map_conf.readfp(open(cfg_file))
+ map_conf = _ConfigParser()
+ map_conf.read_file(open(cfg_file))
try:
default_target_endpoint_type = map_conf.get(
@@ -130,12 +141,19 @@ class OpenStackAuditApi(object):
"""Take a given Request, parse url path to calculate action type.
Depending on req.method:
- if POST: path ends with 'action', read the body and use as action;
- path ends with known custom_action, take action from config;
- request ends with known path, assume is create action;
- request ends with unknown path, assume is update action.
- if GET: request ends with known path, assume is list action;
- request ends with unknown path, assume is read action.
+
+ if POST:
+
+ - path ends with 'action', read the body and use as action;
+ - path ends with known custom_action, take action from config;
+ - request ends with known path, assume is create action;
+ - request ends with unknown path, assume is update action.
+
+ if GET:
+
+ - request ends with known path, assume is list action;
+ - request ends with unknown path, assume is read action.
+
if PUT, assume update action.
if DELETE, assume delete action.
if HEAD, assume read action.
@@ -190,13 +208,13 @@ class OpenStackAuditApi(object):
endp['name'])),
admin_endp=endpoint.Endpoint(
name='admin',
- url=endp['endpoints'][0]['adminURL']),
+ url=endp['endpoints'][0].get('adminURL', taxonomy.UNKNOWN)),
private_endp=endpoint.Endpoint(
name='private',
- url=endp['endpoints'][0]['internalURL']),
+ url=endp['endpoints'][0].get('internalURL', taxonomy.UNKNOWN)),
public_endp=endpoint.Endpoint(
name='public',
- url=endp['endpoints'][0]['publicURL']))
+ url=endp['endpoints'][0].get('publicURL', taxonomy.UNKNOWN)))
return service
@@ -251,10 +269,11 @@ class OpenStackAuditApi(object):
default_endpoint = None
for endp in catalog:
+ endpoint_urls = endp['endpoints'][0]
admin_urlparse = urlparse.urlparse(
- endp['endpoints'][0]['adminURL'])
+ endpoint_urls.get('adminURL', ''))
public_urlparse = urlparse.urlparse(
- endp['endpoints'][0]['publicURL'])
+ endpoint_urls.get('publicURL', ''))
req_url = urlparse.urlparse(req.host_url)
if (req_url.netloc == admin_urlparse.netloc
or req_url.netloc == public_urlparse.netloc):
@@ -322,8 +341,8 @@ class AuditMiddleware(object):
transport_aliases = self._get_aliases(cfg.CONF.project)
if messaging:
- self._notifier = oslo.messaging.Notifier(
- oslo.messaging.get_transport(cfg.CONF,
+ self._notifier = oslo_messaging.Notifier(
+ oslo_messaging.get_transport(cfg.CONF,
aliases=transport_aliases),
os.path.basename(sys.argv[0]))