[SGL] Use admin context to retrieve log objs
Previously we tried to search which log objects existed based on the context of the user who is creating a change on a security group rule. This is not correct as only admin can fetch log objects. Closes-Bug: #2107446 Change-Id: Ia65e06c83ced9cde7618d4d7f3c7b0b3ae48c3fa Signed-off-by: Elvira Garcia <egarciar@redhat.com>
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from neutron_lib import context as n_context
|
||||
from neutron_lib.services.logapi import constants as log_const
|
||||
|
||||
from neutron.services.logapi.common import db_api
|
||||
@@ -23,14 +24,16 @@ class SecurityGroupRuleCallBack(manager.ResourceCallBackBase):
|
||||
|
||||
def handle_event(self, resource, event, trigger, payload):
|
||||
context = payload.context
|
||||
admin_context = n_context.get_admin_context()
|
||||
sg_rule = payload.latest_state
|
||||
if sg_rule:
|
||||
sg_id = sg_rule.get('security_group_id')
|
||||
else:
|
||||
sg_id = payload.resource_id
|
||||
|
||||
# Log resources can only be fetched from admin context.
|
||||
log_resources = db_api.get_logs_bound_sg(
|
||||
context, sg_id=sg_id, project_id=context.project_id)
|
||||
admin_context, sg_id=sg_id, project_id=context.project_id)
|
||||
if log_resources:
|
||||
self.resource_push_api(
|
||||
log_const.RESOURCE_UPDATE, context, log_resources)
|
||||
|
Reference in New Issue
Block a user