From 1b8558ced3c5b18b34befcc1ea13a518ffc38110 Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Thu, 10 Mar 2022 10:42:18 +0100 Subject: [PATCH] Reduce floot on startup (#3500) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Reduce floot on startup * Stop loading * Update supervisor/resolution/checks/core_trust.py Co-authored-by: Joakim Sørensen * Update supervisor/resolution/checks/plugin_trust.py Co-authored-by: Joakim Sørensen * Update supervisor/resolution/checks/core_trust.py Co-authored-by: Joakim Sørensen Co-authored-by: Joakim Sørensen --- supervisor/resolution/checks/core_trust.py | 6 ++++-- supervisor/resolution/checks/plugin_trust.py | 7 +++++-- supervisor/utils/codenotary.py | 12 +++++++----- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/supervisor/resolution/checks/core_trust.py b/supervisor/resolution/checks/core_trust.py index 9f636f2fe..8f43508f5 100644 --- a/supervisor/resolution/checks/core_trust.py +++ b/supervisor/resolution/checks/core_trust.py @@ -4,7 +4,7 @@ from typing import Optional from ...const import CoreState from ...coresys import CoreSys -from ...exceptions import CodeNotaryError, CodeNotaryUntrusted +from ...exceptions import CodeNotaryBackendError, CodeNotaryError, CodeNotaryUntrusted from ..const import ContextType, IssueType, UnhealthyReason from .base import CheckBase @@ -32,6 +32,8 @@ class CheckCoreTrust(CheckBase): except CodeNotaryUntrusted: self.sys_resolution.unhealthy = UnhealthyReason.UNTRUSTED self.sys_resolution.create_issue(IssueType.TRUST, ContextType.CORE) + except CodeNotaryBackendError: + _LOGGER.warning("CAS backend issue, skipping check") except CodeNotaryError: pass @@ -56,4 +58,4 @@ class CheckCoreTrust(CheckBase): @property def states(self) -> list[CoreState]: """Return a list of valid states when this check can run.""" - return [CoreState.RUNNING, CoreState.STARTUP] + return [CoreState.RUNNING] diff --git a/supervisor/resolution/checks/plugin_trust.py b/supervisor/resolution/checks/plugin_trust.py index 1588db0d7..38179a45f 100644 --- a/supervisor/resolution/checks/plugin_trust.py +++ b/supervisor/resolution/checks/plugin_trust.py @@ -4,7 +4,7 @@ from typing import Optional from ...const import CoreState from ...coresys import CoreSys -from ...exceptions import CodeNotaryError, CodeNotaryUntrusted +from ...exceptions import CodeNotaryBackendError, CodeNotaryError, CodeNotaryUntrusted from ..const import ContextType, IssueType, UnhealthyReason from .base import CheckBase @@ -35,6 +35,9 @@ class CheckPluginTrust(CheckBase): self.sys_resolution.create_issue( IssueType.TRUST, ContextType.PLUGIN, reference=plugin.slug ) + except CodeNotaryBackendError: + _LOGGER.warning("CAS backend issue, skipping check") + return except CodeNotaryError: pass @@ -62,4 +65,4 @@ class CheckPluginTrust(CheckBase): @property def states(self) -> list[CoreState]: """Return a list of valid states when this check can run.""" - return [CoreState.RUNNING, CoreState.STARTUP] + return [CoreState.RUNNING] diff --git a/supervisor/utils/codenotary.py b/supervisor/utils/codenotary.py index c08e20f7f..78b5560b3 100644 --- a/supervisor/utils/codenotary.py +++ b/supervisor/utils/codenotary.py @@ -1,11 +1,13 @@ """Small wrapper for CodeNotary.""" +from __future__ import annotations + import asyncio import hashlib import json import logging from pathlib import Path import shlex -from typing import Final, Union +from typing import Final import async_timeout from dirhash import dirhash @@ -25,7 +27,7 @@ _ATTR_ERROR: Final = "error" _ATTR_STATUS: Final = "status" -def calc_checksum(data: Union[str, bytes]) -> str: +def calc_checksum(data: str | bytes) -> str: """Generate checksum for CodeNotary.""" if isinstance(data, str): return hashlib.sha256(data.encode()).hexdigest() @@ -59,15 +61,15 @@ async def cas_validate( env=clean_env(), ) - async with async_timeout.timeout(30): + async with async_timeout.timeout(15): data, error = await proc.communicate() except OSError as err: raise CodeNotaryError( f"CodeNotary fatal error: {err!s}", _LOGGER.critical ) from err except asyncio.TimeoutError: - raise CodeNotaryError( - "Timeout while processing CodeNotary", _LOGGER.error + raise CodeNotaryBackendError( + "Timeout while processing CodeNotary", _LOGGER.warning ) from None # Check if Notarized