Skip to content

Commit 3bb827c

Browse files
committed
Merge remote-tracking branch 'origin/pr/2'
* origin/pr/2: Add property-set:template handler, refactor to reduce redundancy
2 parents 7a62789 + b69a94d commit 3bb827c

1 file changed

Lines changed: 25 additions & 9 deletions

File tree

qubeskicksecure/__init__.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,28 @@
2727
class QubesKicksecureExtension(qubes.ext.Extension):
2828
"""qubes-core-admin extension for handling Kicksecure related settings"""
2929

30+
def apply_tags(self, vm):
31+
"""Apply the appropriate tags to Kicksecure VMs."""
32+
if not isinstance(vm, qubes.vm.LocalVM):
33+
return
34+
35+
if vm.features.check_with_template(
36+
"whonix-gw", None
37+
) or vm.features.check_with_template("whonix-ws", None):
38+
return
39+
40+
if vm.features.check_with_template("kicksecure", None):
41+
vm.tags.add("sdwdate-gui-client")
42+
else:
43+
vm.tags.discard("sdwdate-gui-client")
44+
3045
@qubes.ext.handler("domain-add", system=True)
3146
def on_domain_add(self, app, _event, vm, **_kwargs):
3247
"""Handle new AppVM created on kicksecure template and adjust its
3348
default settings
3449
"""
3550
# pylint: disable=unused-argument
36-
template = getattr(vm, "template", None)
37-
if template is None:
38-
return
39-
40-
if "kicksecure" in template.features:
41-
vm.tags.add("sdwdate-gui-client")
51+
self.apply_tags(vm)
4252

4353
@qubes.ext.handler("features-request")
4454
def on_features_request(self, vm, _event, untrusted_features):
@@ -53,6 +63,12 @@ def on_features_request(self, vm, _event, untrusted_features):
5363
@qubes.ext.handler("domain-load")
5464
def on_domain_load(self, vm, _event):
5565
"""Retroactively add tags to kicksecure."""
56-
if vm.features.check_with_template("kicksecure", None):
57-
if "sdwdate-gui-client" not in vm.tags:
58-
vm.tags.add("sdwdate-gui-client")
66+
self.apply_tags(vm)
67+
68+
@qubes.ext.handler("property-set:template")
69+
def on_property_set_template(
70+
self, vm, event, name, newvalue, oldvalue=None
71+
):
72+
# pylint: disable=too-many-positional-arguments, unused-argument
73+
"""Add tags to AppVMs that become based upon Kicksecure."""
74+
self.apply_tags(vm)

0 commit comments

Comments
 (0)