mgmt: factor out filtering by mgmt-permission:... events

Split actual filtering done by mgmt-permission: events into calling an
event and applying returned filters. This way filtering done in
mgmt.Events handler could reuse the same function.
This commit is contained in:
Marek Marczykowski-Górecki 2017-05-10 14:29:19 +02:00
parent 6926725e02
commit cddc507788
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724

View File

@ -81,6 +81,14 @@ def api(name, *, no_payload=False):
return decorator
def apply_filters(iterable, filters):
'''Apply filters returned by mgmt-permission:... event'''
for selector in filters:
iterable = filter(selector, iterable)
return iterable
class AbstractQubesMgmt(object):
'''Common code for Qubes Management Protocol handling
@ -167,9 +175,8 @@ class AbstractQubesMgmt(object):
def fire_event_for_filter(self, iterable, **kwargs):
'''Fire an event on the source qube to filter for permission'''
for selector in self.fire_event_for_permission(**kwargs):
iterable = filter(selector, iterable)
return iterable
return apply_filters(iterable,
self.fire_event_for_permission(**kwargs))
class QubesMgmt(AbstractQubesMgmt):
@ -588,9 +595,9 @@ class QubesMgmt(AbstractQubesMgmt):
return
if event.startswith('mgmt-permission:'):
return
for selector in event_filters:
if not selector((subject, event, kwargs)):
return
if not list(apply_filters([(subject, event, kwargs)],
event_filters)):
return
self.send_event(subject, event, **kwargs)
if self.dest.name == 'dom0':