Implemented audit.update notification
In this changeset, I implemented the sending of update notifications whenever an audit is modified. Change-Id: I5ccc2516ce896ae7d4ef542b133e8f052eaed602 Partially-Implements: blueprint audit-versioned-notifications-api
This commit is contained in:
@@ -544,14 +544,11 @@ class AuditsController(rest.RestController):
|
||||
raise exception.OperationNotPermitted
|
||||
|
||||
context = pecan.request.context
|
||||
audit_to_update = api_utils.get_resource('Audit',
|
||||
audit_uuid)
|
||||
audit_to_update = api_utils.get_resource(
|
||||
'Audit', audit_uuid, eager=True)
|
||||
policy.enforce(context, 'audit:update', audit_to_update,
|
||||
action='audit:update')
|
||||
|
||||
audit_to_update = objects.Audit.get_by_uuid(pecan.request.context,
|
||||
audit_uuid)
|
||||
|
||||
try:
|
||||
audit_dict = audit_to_update.as_dict()
|
||||
audit = Audit(**api_utils.apply_jsonpatch(audit_dict, patch))
|
||||
@@ -580,7 +577,8 @@ class AuditsController(rest.RestController):
|
||||
:param audit_uuid: UUID of a audit.
|
||||
"""
|
||||
context = pecan.request.context
|
||||
audit_to_delete = api_utils.get_resource('Audit', audit_uuid)
|
||||
audit_to_delete = api_utils.get_resource(
|
||||
'Audit', audit_uuid, eager=True)
|
||||
policy.enforce(context, 'audit:update', audit_to_delete,
|
||||
action='audit:update')
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
import jsonpatch
|
||||
from oslo_config import cfg
|
||||
from oslo_utils import reflection
|
||||
from oslo_utils import uuidutils
|
||||
import pecan
|
||||
import wsme
|
||||
@@ -81,7 +82,7 @@ def as_filters_dict(**filters):
|
||||
return filters_dict
|
||||
|
||||
|
||||
def get_resource(resource, resource_id):
|
||||
def get_resource(resource, resource_id, eager=False):
|
||||
"""Get the resource from the uuid, id or logical name.
|
||||
|
||||
:param resource: the resource type.
|
||||
@@ -91,10 +92,17 @@ def get_resource(resource, resource_id):
|
||||
"""
|
||||
resource = getattr(objects, resource)
|
||||
|
||||
_get = None
|
||||
if utils.is_int_like(resource_id):
|
||||
return resource.get(pecan.request.context, int(resource_id))
|
||||
resource_id = int(resource_id)
|
||||
_get = resource.get
|
||||
elif uuidutils.is_uuid_like(resource_id):
|
||||
_get = resource.get_by_uuid
|
||||
else:
|
||||
_get = resource.get_by_name
|
||||
|
||||
if uuidutils.is_uuid_like(resource_id):
|
||||
return resource.get_by_uuid(pecan.request.context, resource_id)
|
||||
method_signature = reflection.get_signature(_get)
|
||||
if 'eager' in method_signature.parameters:
|
||||
return _get(pecan.request.context, resource_id, eager=eager)
|
||||
|
||||
return resource.get_by_name(pecan.request.context, resource_id)
|
||||
return _get(pecan.request.context, resource_id)
|
||||
|
||||
Reference in New Issue
Block a user