Skip to content

Commit

Permalink
q-dev: keep consistency in fire_event_for_permission
Browse files Browse the repository at this point in the history
Since API changed it is a good opportunity to remove redundant `devclass` argument which is presented in device instance
  • Loading branch information
piotrbartman committed Oct 15, 2024
1 parent 4b8d41f commit 6122028
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
18 changes: 5 additions & 13 deletions qubes/api/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1304,15 +1304,10 @@ async def vm_device_assign(self, endpoint, untrusted_payload):
dev = self.load_device_info(devclass)

assignment = qubes.device_protocol.DeviceAssignment.deserialize(
untrusted_payload, expected_device=dev
)
untrusted_payload, expected_device=dev)

self.fire_event_for_permission(
device=dev, devclass=devclass,
required=assignment.required,
attach_automatically=assignment.attach_automatically,
options=assignment.options
)
device=dev, mode=assignment.mode, options=assignment.options,)

await self.dest.devices[devclass].assign(assignment)
self.app.save()
Expand Down Expand Up @@ -1347,7 +1342,7 @@ async def vm_device_unassign(self, endpoint):
dev = self.load_device_info(devclass)
assignment = DeviceAssignment(dev)

self.fire_event_for_permission(device=dev, devclass=devclass)
self.fire_event_for_permission(device=dev)

await self.dest.devices[devclass].unassign(assignment)
self.app.save()
Expand All @@ -1367,10 +1362,7 @@ async def vm_device_attach(self, endpoint, untrusted_payload):
untrusted_payload, expected_device=dev)

self.fire_event_for_permission(
device=dev,
mode=assignment.mode.value,
options=assignment.options
)
device=dev, mode=assignment.mode.value, options=assignment.options)

await self.dest.devices[devclass].attach(assignment)

Expand All @@ -1386,7 +1378,7 @@ async def vm_device_detach(self, endpoint):
devclass = endpoint
dev = self.load_device_info(devclass)

self.fire_event_for_permission(device=dev, devclass=devclass)
self.fire_event_for_permission(device=dev)

assignment = qubes.device_protocol.DeviceAssignment(dev)
await self.dest.devices[devclass].detach(assignment)
Expand Down
2 changes: 1 addition & 1 deletion qubes/ext/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def on_tag_add(self, vm, event, tag, **kwargs):
@qubes.ext.handler(*(f'admin-permission:admin.vm.device.{ep.name}.Attach'
for ep in importlib.metadata.entry_points(group='qubes.devices')))
def on_device_attach(
self, vm, event, dest, arg, device, mode, options, **kwargs
self, vm, event, dest, arg, device, devclass, mode, options, **kwargs
):
# pylint: disable=unused-argument
# ignore auto-attachment
Expand Down

0 comments on commit 6122028

Please sign in to comment.