Remove string formatting from policy logging
Policy violation logging was added in I32afbfc98a3de6370b0396f39c2cf481f6fc47a9, but it used explicit string formatting in each log statement. This is a follow-up patch to refactor it to let logging decide when to do the formatting. Change-Id: Ia7feb581adcfe727d602b91debdc33dae42ec50a
This commit is contained in:
parent
7896c00635
commit
6a19f549a5
|
@ -101,7 +101,7 @@ class CacheFilter(wsgi.Middleware):
|
|||
try:
|
||||
self.policy.enforce(req.context, action, target)
|
||||
except exception.Forbidden as e:
|
||||
LOG.debug("User not permitted to perform '%s' action" % action)
|
||||
LOG.debug("User not permitted to perform '%s' action", action)
|
||||
raise webob.exc.HTTPForbidden(explanation=e.msg, request=req)
|
||||
|
||||
def _get_v1_image_metadata(self, request, image_id):
|
||||
|
@ -114,7 +114,7 @@ class CacheFilter(wsgi.Middleware):
|
|||
image_id)
|
||||
return utils.create_mashup_dict(image_metadata)
|
||||
except exception.NotFound as e:
|
||||
LOG.debug("No metadata found for image '%s'" % image_id)
|
||||
LOG.debug("No metadata found for image '%s'", image_id)
|
||||
raise webob.exc.HTTPNotFound(explanation=e.msg, request=request)
|
||||
|
||||
def _get_v2_image_metadata(self, request, image_id):
|
||||
|
|
|
@ -46,7 +46,7 @@ class Controller(controller.BaseController):
|
|||
try:
|
||||
self.policy.enforce(req.context, action, {})
|
||||
except exception.Forbidden:
|
||||
LOG.debug("User not permitted to perform '%s' action" % action)
|
||||
LOG.debug("User not permitted to perform '%s' action", action)
|
||||
raise webob.exc.HTTPForbidden()
|
||||
|
||||
def _raise_404_if_image_deleted(self, req, image_id):
|
||||
|
@ -101,7 +101,7 @@ class Controller(controller.BaseController):
|
|||
raise webob.exc.HTTPNotFound(explanation=e.msg)
|
||||
except exception.Forbidden as e:
|
||||
LOG.debug("User not permitted to remove membership from image "
|
||||
"'%s'" % image_id)
|
||||
"'%s'", image_id)
|
||||
raise webob.exc.HTTPNotFound(explanation=e.msg)
|
||||
|
||||
return webob.exc.HTTPNoContent()
|
||||
|
|
|
@ -52,7 +52,7 @@ class ImageActionsController(object):
|
|||
except exception.NotFound as e:
|
||||
raise webob.exc.HTTPNotFound(explanation=e.msg)
|
||||
except exception.Forbidden as e:
|
||||
LOG.debug("User not permitted to deactivate image '%s'" % image_id)
|
||||
LOG.debug("User not permitted to deactivate image '%s'", image_id)
|
||||
raise webob.exc.HTTPForbidden(explanation=e.msg)
|
||||
except exception.InvalidImageStatusTransition as e:
|
||||
raise webob.exc.HTTPBadRequest(explanation=e.msg)
|
||||
|
@ -68,7 +68,7 @@ class ImageActionsController(object):
|
|||
except exception.NotFound as e:
|
||||
raise webob.exc.HTTPNotFound(explanation=e.msg)
|
||||
except exception.Forbidden as e:
|
||||
LOG.debug("User not permitted to reactivate image '%s'" % image_id)
|
||||
LOG.debug("User not permitted to reactivate image '%s'", image_id)
|
||||
raise webob.exc.HTTPForbidden(explanation=e.msg)
|
||||
except exception.InvalidImageStatusTransition as e:
|
||||
raise webob.exc.HTTPBadRequest(explanation=e.msg)
|
||||
|
|
|
@ -180,7 +180,7 @@ class ImageDataController(object):
|
|||
except exception.NotFound as e:
|
||||
raise webob.exc.HTTPNotFound(explanation=e.msg)
|
||||
except exception.Forbidden as e:
|
||||
LOG.debug("User not permitted to download image '%s'" % image_id)
|
||||
LOG.debug("User not permitted to download image '%s'", image_id)
|
||||
raise webob.exc.HTTPForbidden(explanation=e.msg)
|
||||
|
||||
return image
|
||||
|
@ -229,7 +229,7 @@ class ResponseSerializer(wsgi.JSONResponseSerializer):
|
|||
glance_store.StoreRandomGetNotSupported) as e:
|
||||
raise webob.exc.HTTPBadRequest(explanation=e.msg)
|
||||
except exception.Forbidden as e:
|
||||
LOG.debug("User not permitted to download image '%s'" % image)
|
||||
LOG.debug("User not permitted to download image '%s'", image)
|
||||
raise webob.exc.HTTPForbidden(explanation=e.msg)
|
||||
# NOTE(saschpe): "response.app_iter = ..." currently resets Content-MD5
|
||||
# (https://github.com/Pylons/webob/issues/86), so it should be set
|
||||
|
|
|
@ -127,7 +127,7 @@ class ImagesController(object):
|
|||
try:
|
||||
return image_repo.get(image_id)
|
||||
except exception.Forbidden as e:
|
||||
LOG.debug("User not permitted to show image '%s'" % image_id)
|
||||
LOG.debug("User not permitted to show image '%s'", image_id)
|
||||
raise webob.exc.HTTPForbidden(explanation=e.msg)
|
||||
except exception.NotFound as e:
|
||||
raise webob.exc.HTTPNotFound(explanation=e.msg)
|
||||
|
@ -151,7 +151,7 @@ class ImagesController(object):
|
|||
except exception.Invalid as e:
|
||||
raise webob.exc.HTTPBadRequest(explanation=e.msg)
|
||||
except exception.Forbidden as e:
|
||||
LOG.debug("User not permitted to update image '%s'" % image_id)
|
||||
LOG.debug("User not permitted to update image '%s'", image_id)
|
||||
raise webob.exc.HTTPForbidden(explanation=e.msg)
|
||||
except exception.InvalidParameterValue as e:
|
||||
raise webob.exc.HTTPBadRequest(explanation=e.msg)
|
||||
|
@ -224,7 +224,7 @@ class ImagesController(object):
|
|||
image.delete()
|
||||
image_repo.remove(image)
|
||||
except exception.Forbidden as e:
|
||||
LOG.debug("User not permitted to delete image '%s'" % image_id)
|
||||
LOG.debug("User not permitted to delete image '%s'", image_id)
|
||||
raise webob.exc.HTTPForbidden(explanation=e.msg)
|
||||
except exception.NotFound as e:
|
||||
msg = (_("Failed to find image %(image_id)s to delete") %
|
||||
|
@ -725,7 +725,7 @@ class ResponseSerializer(wsgi.JSONResponseSerializer):
|
|||
# locations but it's just non-existent.
|
||||
image_view['locations'] = []
|
||||
LOG.debug("There is not available location "
|
||||
"for image %s" % image.image_id)
|
||||
"for image %s", image.image_id)
|
||||
|
||||
if CONF.show_image_direct_url:
|
||||
if image.locations:
|
||||
|
@ -734,7 +734,7 @@ class ResponseSerializer(wsgi.JSONResponseSerializer):
|
|||
image_view['direct_url'] = l['url']
|
||||
else:
|
||||
LOG.debug("There is not available location "
|
||||
"for image %s" % image.image_id)
|
||||
"for image %s", image.image_id)
|
||||
|
||||
image_view['tags'] = list(image.tags)
|
||||
image_view['self'] = self._get_image_href(image)
|
||||
|
|
|
@ -263,7 +263,7 @@ class NamespaceController(object):
|
|||
|
||||
except exception.Forbidden as e:
|
||||
LOG.debug("User not permitted to show metadata namespace "
|
||||
"'%s'" % namespace)
|
||||
"'%s'", namespace)
|
||||
raise webob.exc.HTTPForbidden(explanation=e.msg)
|
||||
except exception.NotFound as e:
|
||||
raise webob.exc.HTTPNotFound(explanation=e.msg)
|
||||
|
@ -291,7 +291,7 @@ class NamespaceController(object):
|
|||
updated_namespace = namespace_repo.save(ns_obj)
|
||||
except exception.Forbidden as e:
|
||||
LOG.debug("User not permitted to update metadata namespace "
|
||||
"'%s'" % namespace)
|
||||
"'%s'", namespace)
|
||||
raise webob.exc.HTTPForbidden(explanation=e.msg)
|
||||
except exception.NotFound as e:
|
||||
raise webob.exc.HTTPNotFound(explanation=e.msg)
|
||||
|
@ -313,7 +313,7 @@ class NamespaceController(object):
|
|||
namespace_repo.remove(namespace_obj)
|
||||
except exception.Forbidden as e:
|
||||
LOG.debug("User not permitted to delete metadata namespace "
|
||||
"'%s'" % namespace)
|
||||
"'%s'", namespace)
|
||||
raise webob.exc.HTTPForbidden(explanation=e.msg)
|
||||
except exception.NotFound as e:
|
||||
raise webob.exc.HTTPNotFound(explanation=e.msg)
|
||||
|
@ -329,7 +329,7 @@ class NamespaceController(object):
|
|||
ns_repo.remove_objects(namespace_obj)
|
||||
except exception.Forbidden as e:
|
||||
LOG.debug("User not permitted to delete metadata objects "
|
||||
"within '%s' namespace" % namespace)
|
||||
"within '%s' namespace", namespace)
|
||||
raise webob.exc.HTTPForbidden(explanation=e.msg)
|
||||
except exception.NotFound as e:
|
||||
raise webob.exc.HTTPNotFound(explanation=e.msg)
|
||||
|
@ -345,7 +345,7 @@ class NamespaceController(object):
|
|||
ns_repo.remove_tags(namespace_obj)
|
||||
except exception.Forbidden as e:
|
||||
LOG.debug("User not permitted to delete metadata tags "
|
||||
"within '%s' namespace" % namespace)
|
||||
"within '%s' namespace", namespace)
|
||||
raise webob.exc.HTTPForbidden(explanation=e.msg)
|
||||
except exception.NotFound as e:
|
||||
raise webob.exc.HTTPNotFound(explanation=e.msg)
|
||||
|
@ -361,7 +361,7 @@ class NamespaceController(object):
|
|||
ns_repo.remove_properties(namespace_obj)
|
||||
except exception.Forbidden as e:
|
||||
LOG.debug("User not permitted to delete metadata properties "
|
||||
"within '%s' namespace" % namespace)
|
||||
"within '%s' namespace", namespace)
|
||||
raise webob.exc.HTTPForbidden(explanation=e.msg)
|
||||
except exception.NotFound as e:
|
||||
raise webob.exc.HTTPNotFound(explanation=e.msg)
|
||||
|
|
|
@ -62,7 +62,7 @@ class MetadefObjectsController(object):
|
|||
|
||||
except exception.Forbidden as e:
|
||||
LOG.debug("User not permitted to create metadata object within "
|
||||
"'%s' namespace" % namespace)
|
||||
"'%s' namespace", namespace)
|
||||
raise webob.exc.HTTPForbidden(explanation=e.msg)
|
||||
except exception.NotFound as e:
|
||||
raise webob.exc.HTTPNotFound(explanation=e.msg)
|
||||
|
@ -93,7 +93,7 @@ class MetadefObjectsController(object):
|
|||
metadef_objects.objects = object_list
|
||||
except exception.Forbidden as e:
|
||||
LOG.debug("User not permitted to retrieve metadata objects within "
|
||||
"'%s' namespace" % namespace)
|
||||
"'%s' namespace", namespace)
|
||||
raise webob.exc.HTTPForbidden(explanation=e.msg)
|
||||
except exception.NotFound as e:
|
||||
raise webob.exc.HTTPNotFound(explanation=e.msg)
|
||||
|
@ -113,7 +113,7 @@ class MetadefObjectsController(object):
|
|||
self.obj_schema_link)
|
||||
except exception.Forbidden as e:
|
||||
LOG.debug("User not permitted to show metadata object '%s' "
|
||||
"within '%s' namespace" % (namespace, object_name))
|
||||
"within '%s' namespace", namespace, object_name)
|
||||
raise webob.exc.HTTPForbidden(explanation=e.msg)
|
||||
except exception.NotFound as e:
|
||||
raise webob.exc.HTTPNotFound(explanation=e.msg)
|
||||
|
@ -137,7 +137,7 @@ class MetadefObjectsController(object):
|
|||
updated_metadata_obj = meta_repo.save(metadef_object)
|
||||
except exception.Forbidden as e:
|
||||
LOG.debug("User not permitted to update metadata object '%s' "
|
||||
"within '%s' namespace " % (object_name, namespace))
|
||||
"within '%s' namespace ", object_name, namespace)
|
||||
raise webob.exc.HTTPForbidden(explanation=e.msg)
|
||||
except exception.NotFound as e:
|
||||
raise webob.exc.HTTPNotFound(explanation=e.msg)
|
||||
|
@ -159,7 +159,7 @@ class MetadefObjectsController(object):
|
|||
meta_repo.remove(metadef_object)
|
||||
except exception.Forbidden as e:
|
||||
LOG.debug("User not permitted to delete metadata object '%s' "
|
||||
"within '%s' namespace" % (object_name, namespace))
|
||||
"within '%s' namespace", object_name, namespace)
|
||||
raise webob.exc.HTTPForbidden(explanation=e.msg)
|
||||
except exception.NotFound as e:
|
||||
raise webob.exc.HTTPNotFound(explanation=e.msg)
|
||||
|
|
|
@ -74,7 +74,7 @@ class NamespacePropertiesController(object):
|
|||
namespace_properties.properties = property_list
|
||||
except exception.Forbidden as e:
|
||||
LOG.debug("User not permitted to retrieve metadata properties "
|
||||
"within '%s' namespace" % namespace)
|
||||
"within '%s' namespace", namespace)
|
||||
raise webob.exc.HTTPForbidden(explanation=e.msg)
|
||||
except exception.NotFound as e:
|
||||
raise webob.exc.HTTPNotFound(explanation=e.msg)
|
||||
|
@ -106,7 +106,7 @@ class NamespacePropertiesController(object):
|
|||
property = self._to_model(db_property)
|
||||
except exception.Forbidden as e:
|
||||
LOG.debug("User not permitted to show metadata property '%s' "
|
||||
"within '%s' namespace" % (property_name, namespace))
|
||||
"within '%s' namespace", property_name, namespace)
|
||||
raise webob.exc.HTTPForbidden(explanation=e.msg)
|
||||
except exception.NotFound as e:
|
||||
raise webob.exc.HTTPNotFound(explanation=e.msg)
|
||||
|
@ -124,7 +124,7 @@ class NamespacePropertiesController(object):
|
|||
prop_repo.add(new_property_type)
|
||||
except exception.Forbidden as e:
|
||||
LOG.debug("User not permitted to create metadata property within "
|
||||
"'%s' namespace" % namespace)
|
||||
"'%s' namespace", namespace)
|
||||
raise webob.exc.HTTPForbidden(explanation=e.msg)
|
||||
except exception.NotFound as e:
|
||||
raise webob.exc.HTTPNotFound(explanation=e.msg)
|
||||
|
@ -145,7 +145,7 @@ class NamespacePropertiesController(object):
|
|||
updated_property_type = prop_repo.save(db_property_type)
|
||||
except exception.Forbidden as e:
|
||||
LOG.debug("User not permitted to update metadata property '%s' "
|
||||
"within '%s' namespace" % (property_name, namespace))
|
||||
"within '%s' namespace", property_name, namespace)
|
||||
raise webob.exc.HTTPForbidden(explanation=e.msg)
|
||||
except exception.NotFound as e:
|
||||
raise webob.exc.HTTPNotFound(explanation=e.msg)
|
||||
|
@ -164,7 +164,7 @@ class NamespacePropertiesController(object):
|
|||
prop_repo.remove(property_type)
|
||||
except exception.Forbidden as e:
|
||||
LOG.debug("User not permitted to delete metadata property '%s' "
|
||||
"within '%s' namespace" % (property_name, namespace))
|
||||
"within '%s' namespace", property_name, namespace)
|
||||
raise webob.exc.HTTPForbidden(explanation=e.msg)
|
||||
except exception.NotFound as e:
|
||||
raise webob.exc.HTTPNotFound(explanation=e.msg)
|
||||
|
|
|
@ -83,7 +83,7 @@ class ResourceTypeController(object):
|
|||
resource_types.resource_type_associations = resource_type_list
|
||||
except exception.Forbidden as e:
|
||||
LOG.debug("User not permitted to retrieve metadata resource types "
|
||||
"within '%s' namespace" % namespace)
|
||||
"within '%s' namespace", namespace)
|
||||
raise webob.exc.HTTPForbidden(explanation=e.msg)
|
||||
except exception.NotFound as e:
|
||||
raise webob.exc.HTTPNotFound(explanation=e.msg)
|
||||
|
@ -103,7 +103,7 @@ class ResourceTypeController(object):
|
|||
|
||||
except exception.Forbidden as e:
|
||||
LOG.debug("User not permitted to create metadata resource type "
|
||||
"within '%s' namespace" % namespace)
|
||||
"within '%s' namespace", namespace)
|
||||
raise webob.exc.HTTPForbidden(explanation=e.msg)
|
||||
except exception.NotFound as e:
|
||||
raise webob.exc.HTTPNotFound(explanation=e.msg)
|
||||
|
@ -130,8 +130,7 @@ class ResourceTypeController(object):
|
|||
raise exception.NotFound()
|
||||
except exception.Forbidden as e:
|
||||
LOG.debug("User not permitted to delete metadata resource type "
|
||||
"'%s' within '%s' namespace" % (resource_type,
|
||||
namespace))
|
||||
"'%s' within '%s' namespace", resource_type, namespace)
|
||||
raise webob.exc.HTTPForbidden(explanation=e.msg)
|
||||
except exception.NotFound as e:
|
||||
msg = (_("Failed to find resource type %(resourcetype)s to "
|
||||
|
|
|
@ -61,7 +61,7 @@ class TagsController(object):
|
|||
tag_repo.add(new_meta_tag)
|
||||
except exception.Forbidden as e:
|
||||
LOG.debug("User not permitted to create metadata tag within "
|
||||
"'%s' namespace" % namespace)
|
||||
"'%s' namespace", namespace)
|
||||
raise webob.exc.HTTPForbidden(explanation=e.msg)
|
||||
except exception.NotFound as e:
|
||||
raise webob.exc.HTTPNotFound(explanation=e.msg)
|
||||
|
@ -88,7 +88,7 @@ class TagsController(object):
|
|||
metadef_tags.tags = tag_list_out
|
||||
except exception.Forbidden as e:
|
||||
LOG.debug("User not permitted to create metadata tags within "
|
||||
"'%s' namespace" % namespace)
|
||||
"'%s' namespace", namespace)
|
||||
raise webob.exc.HTTPForbidden(explanation=e.msg)
|
||||
except exception.NotFound as e:
|
||||
raise webob.exc.HTTPNotFound(explanation=e.msg)
|
||||
|
@ -122,7 +122,7 @@ class TagsController(object):
|
|||
metadef_tags.tags = tag_list
|
||||
except exception.Forbidden as e:
|
||||
LOG.debug("User not permitted to retrieve metadata tags "
|
||||
"within '%s' namespace" % namespace)
|
||||
"within '%s' namespace", namespace)
|
||||
raise webob.exc.HTTPForbidden(explanation=e.msg)
|
||||
except exception.NotFound as e:
|
||||
raise webob.exc.HTTPNotFound(explanation=e.msg)
|
||||
|
@ -139,7 +139,7 @@ class TagsController(object):
|
|||
return MetadefTag.to_wsme_model(metadef_tag)
|
||||
except exception.Forbidden as e:
|
||||
LOG.debug("User not permitted to show metadata tag '%s' "
|
||||
"within '%s' namespace" % (tag_name, namespace))
|
||||
"within '%s' namespace", tag_name, namespace)
|
||||
raise webob.exc.HTTPForbidden(explanation=e.msg)
|
||||
except exception.NotFound as e:
|
||||
raise webob.exc.HTTPNotFound(explanation=e.msg)
|
||||
|
@ -157,7 +157,7 @@ class TagsController(object):
|
|||
updated_metadata_tag = meta_repo.save(metadef_tag)
|
||||
except exception.Forbidden as e:
|
||||
LOG.debug("User not permitted to update metadata tag '%s' "
|
||||
"within '%s' namespace" % (tag_name, namespace))
|
||||
"within '%s' namespace", tag_name, namespace)
|
||||
raise webob.exc.HTTPForbidden(explanation=e.msg)
|
||||
except exception.NotFound as e:
|
||||
raise webob.exc.HTTPNotFound(explanation=e.msg)
|
||||
|
@ -177,7 +177,7 @@ class TagsController(object):
|
|||
meta_repo.remove(metadef_tag)
|
||||
except exception.Forbidden as e:
|
||||
LOG.debug("User not permitted to delete metadata tag '%s' "
|
||||
"within '%s' namespace" % (tag_name, namespace))
|
||||
"within '%s' namespace", tag_name, namespace)
|
||||
raise webob.exc.HTTPForbidden(explanation=e.msg)
|
||||
except exception.NotFound as e:
|
||||
raise webob.exc.HTTPNotFound(explanation=e.msg)
|
||||
|
|
Loading…
Reference in New Issue