Compare commits

...

1 Commits

Author SHA1 Message Date
Stefan Agner
f3770fe8f7 Add explicit StrEnum conversions for D-Bus and Docker properties
Convert string values from D-Bus and Docker API to their respective StrEnum
types explicitly to satisfy typeguard runtime type checking.

The conversions will raise ValueError if an unknown enum value is encountered,
this will be caught in Sentry. Since D-Bus and the particular property from
Docker API are not mission critical for Supervisor update functionality, it
will be possible to add new enum values in the future as they arise.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-05 16:52:14 +01:00
2 changed files with 19 additions and 7 deletions

View File

@@ -103,19 +103,25 @@ class Resolved(DBusInterfaceProxy):
@dbus_property
def dns_over_tls(self) -> DNSOverTLSEnabled | None:
"""Return DNS over TLS enabled."""
return self.properties[DBUS_ATTR_DNS_OVER_TLS]
if (value := self.properties.get(DBUS_ATTR_DNS_OVER_TLS)) is not None:
return DNSOverTLSEnabled(value)
return None
@property
@dbus_property
def dns_stub_listener(self) -> DNSStubListenerEnabled | None:
"""Return DNS stub listener enabled on port 53."""
return self.properties[DBUS_ATTR_DNS_STUB_LISTENER]
if (value := self.properties.get(DBUS_ATTR_DNS_STUB_LISTENER)) is not None:
return DNSStubListenerEnabled(value)
return None
@property
@dbus_property
def dnssec(self) -> DNSSECValidation | None:
"""Return DNSSEC validation enforced."""
return self.properties[DBUS_ATTR_DNSSEC]
if (value := self.properties.get(DBUS_ATTR_DNSSEC)) is not None:
return DNSSECValidation(value)
return None
@property
@dbus_property
@@ -159,7 +165,9 @@ class Resolved(DBusInterfaceProxy):
@dbus_property
def llmnr(self) -> MulticastProtocolEnabled | None:
"""Return LLMNR enabled."""
return self.properties[DBUS_ATTR_LLMNR]
if (value := self.properties.get(DBUS_ATTR_LLMNR)) is not None:
return MulticastProtocolEnabled(value)
return None
@property
@dbus_property
@@ -171,13 +179,17 @@ class Resolved(DBusInterfaceProxy):
@dbus_property
def multicast_dns(self) -> MulticastProtocolEnabled | None:
"""Return MDNS enabled."""
return self.properties[DBUS_ATTR_MULTICAST_DNS]
if (value := self.properties.get(DBUS_ATTR_MULTICAST_DNS)) is not None:
return MulticastProtocolEnabled(value)
return None
@property
@dbus_property
def resolv_conf_mode(self) -> ResolvConfMode | None:
"""Return how /etc/resolv.conf managed on host."""
return self.properties[DBUS_ATTR_RESOLV_CONF_MODE]
if (value := self.properties.get(DBUS_ATTR_RESOLV_CONF_MODE)) is not None:
return ResolvConfMode(value)
return None
@property
@dbus_property

View File

@@ -161,7 +161,7 @@ class DockerInterface(JobGroup, ABC):
return None
policy = self.meta_host["RestartPolicy"].get("Name")
return policy if policy else RestartPolicy.NO
return RestartPolicy(policy) if policy else RestartPolicy.NO
@property
def security_opt(self) -> list[str]: