Reduce floot on startup (#3500)

* Reduce floot on startup

* Stop loading

* Update supervisor/resolution/checks/core_trust.py

Co-authored-by: Joakim Sørensen <joasoe@gmail.com>

* Update supervisor/resolution/checks/plugin_trust.py

Co-authored-by: Joakim Sørensen <joasoe@gmail.com>

* Update supervisor/resolution/checks/core_trust.py

Co-authored-by: Joakim Sørensen <joasoe@gmail.com>

Co-authored-by: Joakim Sørensen <joasoe@gmail.com>
This commit is contained in:
Pascal Vizeli 2022-03-10 10:42:18 +01:00 committed by GitHub
parent 4339cae241
commit 1b8558ced3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 9 deletions

View File

@ -4,7 +4,7 @@ from typing import Optional
from ...const import CoreState from ...const import CoreState
from ...coresys import CoreSys from ...coresys import CoreSys
from ...exceptions import CodeNotaryError, CodeNotaryUntrusted from ...exceptions import CodeNotaryBackendError, CodeNotaryError, CodeNotaryUntrusted
from ..const import ContextType, IssueType, UnhealthyReason from ..const import ContextType, IssueType, UnhealthyReason
from .base import CheckBase from .base import CheckBase
@ -32,6 +32,8 @@ class CheckCoreTrust(CheckBase):
except CodeNotaryUntrusted: except CodeNotaryUntrusted:
self.sys_resolution.unhealthy = UnhealthyReason.UNTRUSTED self.sys_resolution.unhealthy = UnhealthyReason.UNTRUSTED
self.sys_resolution.create_issue(IssueType.TRUST, ContextType.CORE) self.sys_resolution.create_issue(IssueType.TRUST, ContextType.CORE)
except CodeNotaryBackendError:
_LOGGER.warning("CAS backend issue, skipping check")
except CodeNotaryError: except CodeNotaryError:
pass pass
@ -56,4 +58,4 @@ class CheckCoreTrust(CheckBase):
@property @property
def states(self) -> list[CoreState]: def states(self) -> list[CoreState]:
"""Return a list of valid states when this check can run.""" """Return a list of valid states when this check can run."""
return [CoreState.RUNNING, CoreState.STARTUP] return [CoreState.RUNNING]

View File

@ -4,7 +4,7 @@ from typing import Optional
from ...const import CoreState from ...const import CoreState
from ...coresys import CoreSys from ...coresys import CoreSys
from ...exceptions import CodeNotaryError, CodeNotaryUntrusted from ...exceptions import CodeNotaryBackendError, CodeNotaryError, CodeNotaryUntrusted
from ..const import ContextType, IssueType, UnhealthyReason from ..const import ContextType, IssueType, UnhealthyReason
from .base import CheckBase from .base import CheckBase
@ -35,6 +35,9 @@ class CheckPluginTrust(CheckBase):
self.sys_resolution.create_issue( self.sys_resolution.create_issue(
IssueType.TRUST, ContextType.PLUGIN, reference=plugin.slug IssueType.TRUST, ContextType.PLUGIN, reference=plugin.slug
) )
except CodeNotaryBackendError:
_LOGGER.warning("CAS backend issue, skipping check")
return
except CodeNotaryError: except CodeNotaryError:
pass pass
@ -62,4 +65,4 @@ class CheckPluginTrust(CheckBase):
@property @property
def states(self) -> list[CoreState]: def states(self) -> list[CoreState]:
"""Return a list of valid states when this check can run.""" """Return a list of valid states when this check can run."""
return [CoreState.RUNNING, CoreState.STARTUP] return [CoreState.RUNNING]

View File

@ -1,11 +1,13 @@
"""Small wrapper for CodeNotary.""" """Small wrapper for CodeNotary."""
from __future__ import annotations
import asyncio import asyncio
import hashlib import hashlib
import json import json
import logging import logging
from pathlib import Path from pathlib import Path
import shlex import shlex
from typing import Final, Union from typing import Final
import async_timeout import async_timeout
from dirhash import dirhash from dirhash import dirhash
@ -25,7 +27,7 @@ _ATTR_ERROR: Final = "error"
_ATTR_STATUS: Final = "status" _ATTR_STATUS: Final = "status"
def calc_checksum(data: Union[str, bytes]) -> str: def calc_checksum(data: str | bytes) -> str:
"""Generate checksum for CodeNotary.""" """Generate checksum for CodeNotary."""
if isinstance(data, str): if isinstance(data, str):
return hashlib.sha256(data.encode()).hexdigest() return hashlib.sha256(data.encode()).hexdigest()
@ -59,15 +61,15 @@ async def cas_validate(
env=clean_env(), env=clean_env(),
) )
async with async_timeout.timeout(30): async with async_timeout.timeout(15):
data, error = await proc.communicate() data, error = await proc.communicate()
except OSError as err: except OSError as err:
raise CodeNotaryError( raise CodeNotaryError(
f"CodeNotary fatal error: {err!s}", _LOGGER.critical f"CodeNotary fatal error: {err!s}", _LOGGER.critical
) from err ) from err
except asyncio.TimeoutError: except asyncio.TimeoutError:
raise CodeNotaryError( raise CodeNotaryBackendError(
"Timeout while processing CodeNotary", _LOGGER.error "Timeout while processing CodeNotary", _LOGGER.warning
) from None ) from None
# Check if Notarized # Check if Notarized