diff --git a/supervisor/api/const.py b/supervisor/api/const.py index 0e4b3bdaa..19da56d8b 100644 --- a/supervisor/api/const.py +++ b/supervisor/api/const.py @@ -9,3 +9,4 @@ ATTR_DT_UTC = "dt_utc" ATTR_STARTUP_TIME = "startup_time" ATTR_USE_NTP = "use_ntp" ATTR_USE_RTC = "use_rtc" +ATTR_APPARMOR_VERSION = "apparmor_version" diff --git a/supervisor/api/host.py b/supervisor/api/host.py index 3bb06bcff..6445bc84c 100644 --- a/supervisor/api/host.py +++ b/supervisor/api/host.py @@ -27,6 +27,7 @@ from ..const import ( from ..coresys import CoreSysAttributes from .const import ( ATTR_AGENT_VERSION, + ATTR_APPARMOR_VERSION, ATTR_BOOT_TIMESTAMP, ATTR_DT_SYNCHRONIZED, ATTR_DT_UTC, @@ -49,6 +50,7 @@ class APIHost(CoreSysAttributes): """Return host information.""" return { ATTR_AGENT_VERSION: self.sys_dbus.agent.version, + ATTR_APPARMOR_VERSION: self.sys_host.apparmor.version, ATTR_CHASSIS: self.sys_host.info.chassis, ATTR_CPE: self.sys_host.info.cpe, ATTR_DEPLOYMENT: self.sys_host.info.deployment, diff --git a/supervisor/host/apparmor.py b/supervisor/host/apparmor.py index f09888a69..380e1a8ad 100644 --- a/supervisor/host/apparmor.py +++ b/supervisor/host/apparmor.py @@ -1,12 +1,15 @@ """AppArmor control for host.""" +from __future__ import annotations + import logging from pathlib import Path import shutil -from supervisor.resolution.const import UnsupportedReason +from awesomeversion import AwesomeVersion from ..coresys import CoreSys, CoreSysAttributes from ..exceptions import DBusError, HostAppArmorError +from ..resolution.const import UnsupportedReason from ..utils.apparmor import validate_profile from .const import HostFeature @@ -29,6 +32,11 @@ class AppArmorControl(CoreSysAttributes): and UnsupportedReason.APPARMOR not in self.sys_resolution.unsupported ) + @property + def version(self) -> AwesomeVersion | None: + """Return hosts AppArmor Version.""" + return self.sys_dbus.agent.apparmor.version + def exists(self, profile_name: str) -> bool: """Return True if a profile exists.""" return profile_name in self._profiles diff --git a/tests/api/test_host.py b/tests/api/test_host.py new file mode 100644 index 000000000..f5fcc5b68 --- /dev/null +++ b/tests/api/test_host.py @@ -0,0 +1,24 @@ +"""Test Host API.""" + +import pytest + +from supervisor.coresys import CoreSys + +# pylint: disable=protected-access + + +@pytest.mark.asyncio +async def test_api_host_info(api_client, tmp_path, coresys: CoreSys): + """Test host info api.""" + await coresys.dbus.agent.connect() + await coresys.dbus.agent.update() + + coresys.hardware.disk.get_disk_life_time = lambda x: 0 + coresys.hardware.disk.get_disk_free_space = lambda x: 5000 + coresys.hardware.disk.get_disk_total_space = lambda x: 50000 + coresys.hardware.disk.get_disk_used_space = lambda x: 45000 + + resp = await api_client.get("/host/info") + result = await resp.json() + + assert result["data"]["apparmor_version"] == "2.13.2"