From ea51db419f96c26f89606c0088b97758e8102089 Mon Sep 17 00:00:00 2001 From: Olivier Le Thanh Duong Date: Thu, 31 Oct 2024 16:37:26 +0100 Subject: [PATCH] fix settings --- pyproject.toml | 1 - src/aleph/vm/conf.py | 28 +++++++++++++------ src/aleph/vm/orchestrator/chain.py | 2 +- src/aleph/vm/orchestrator/tasks.py | 3 +- .../vm/orchestrator/views/authentication.py | 6 ++-- 5 files changed, 25 insertions(+), 15 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 3209ad34..99e68031 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -200,7 +200,6 @@ lint.per-file-ignores."tests/**/*" = [ "PLR2004", "S101", "TID252" ] # # Don't touch unused imports # "F401", #] -lint.isort = [ "aleph.vm" ] [tool.pytest.ini_options] pythonpath = [ diff --git a/src/aleph/vm/conf.py b/src/aleph/vm/conf.py index 7f740d67..45d2d611 100644 --- a/src/aleph/vm/conf.py +++ b/src/aleph/vm/conf.py @@ -13,9 +13,9 @@ from aleph_message.models import Chain from aleph_message.models.execution.environment import HypervisorType -from pydantic import Field, HttpUrl from dotenv import load_dotenv -from pathlib import Path +from pydantic import Field, HttpUrl +from pydantic_settings import BaseSettings, SettingsConfigDict from aleph.vm.orchestrator.chain import STREAM_CHAINS from aleph.vm.utils import ( @@ -24,7 +24,6 @@ file_hashes_differ, is_command_available, ) -from pydantic_settings import BaseSettings, SettingsConfigDict load_dotenv() @@ -288,7 +287,9 @@ class Settings(BaseSettings): FAKE_DATA_MESSAGE: Path = Path(abspath(join(__file__, "../../../../examples/program_message_from_aleph.json"))) FAKE_DATA_DATA: Path | None = Path(abspath(join(__file__, "../../../../examples/data/"))) - FAKE_DATA_RUNTIME: Path = Path(abspath(join(__file__, "../../../../runtimes/aleph-debian-12-python/rootfs.squashfs"))) + FAKE_DATA_RUNTIME: Path = Path( + abspath(join(__file__, "../../../../runtimes/aleph-debian-12-python/rootfs.squashfs")) + ) FAKE_DATA_VOLUME: Path | None = Path(abspath(join(__file__, "../../../../examples/volumes/volume-venv.squashfs"))) # Tests on instances @@ -307,7 +308,9 @@ class Settings(BaseSettings): "examples/instance_message_from_aleph.json", ) FAKE_INSTANCE_MESSAGE: Path = Path(abspath(join(__file__, "../../../../examples/instance_message_from_aleph.json"))) - FAKE_INSTANCE_QEMU_MESSAGE: Path = Path(abspath(join(__file__, "../../../../examples/qemu_message_from_aleph.json"))) + FAKE_INSTANCE_QEMU_MESSAGE: Path = Path( + abspath(join(__file__, "../../../../examples/qemu_message_from_aleph.json")) + ) CHECK_FASTAPI_VM_ID: str = "63faf8b5db1cf8d965e6a464a0cb8062af8e7df131729e48738342d956f29ace" LEGACY_CHECK_FASTAPI_VM_ID: str = "67705389842a0a1b95eaa408b009741027964edc805997475e95c505d642edd8" @@ -343,7 +346,7 @@ def check(self): assert isfile(self.JAILER_PATH), f"File not found {self.JAILER_PATH}" assert isfile(self.LINUX_PATH), f"File not found {self.LINUX_PATH}" assert self.NETWORK_INTERFACE, "Network interface is not specified" - assert self.CONNECTOR_URL.startswith("http://") or self.CONNECTOR_URL.startswith("https://") + assert str(self.CONNECTOR_URL).startswith("http://") or str(self.CONNECTOR_URL).startswith("https://") if self.ALLOW_VM_NETWORKING: assert exists( f"/sys/class/net/{self.NETWORK_INTERFACE}" @@ -469,7 +472,13 @@ def __init__( _secrets_dir: Path | None = None, **values: Any, ) -> None: - super().__init__(_env_file, _env_file_encoding, _env_nested_delimiter, _secrets_dir, **values) + super().__init__( + _env_file, + _env_file_encoding, + _env_nested_delimiter, + _secrets_dir, + **values, + ) if not self.MESSAGE_CACHE: self.MESSAGE_CACHE = self.CACHE_ROOT / "message" if not self.CODE_CACHE: @@ -492,7 +501,10 @@ def __init__( self.JAILER_BASE_DIR = self.EXECUTION_ROOT / "jailer" if not self.CONFIDENTIAL_SESSION_DIRECTORY: self.CONFIDENTIAL_SESSION_DIRECTORY = self.EXECUTION_ROOT / "sessions" - model_config = SettingsConfigDict(env_prefix="ALEPH_VM_", case_sensitive=False, env_file=".env") + + model_config = SettingsConfigDict( + env_prefix="ALEPH_VM_", case_sensitive=False, env_file=".env", validate_default=False + ) def make_db_url(): diff --git a/src/aleph/vm/orchestrator/chain.py b/src/aleph/vm/orchestrator/chain.py index 02e878f9..14bde475 100644 --- a/src/aleph/vm/orchestrator/chain.py +++ b/src/aleph/vm/orchestrator/chain.py @@ -1,7 +1,7 @@ import logging from aleph_message.models import Chain -from pydantic import model_validator, BaseModel +from pydantic import BaseModel, model_validator logger = logging.getLogger(__name__) diff --git a/src/aleph/vm/orchestrator/tasks.py b/src/aleph/vm/orchestrator/tasks.py index c7062d93..921a2265 100644 --- a/src/aleph/vm/orchestrator/tasks.py +++ b/src/aleph/vm/orchestrator/tasks.py @@ -11,7 +11,6 @@ from aiohttp import web from aleph_message.models import ( AlephMessage, - ItemHash, PaymentType, ProgramMessage, parse_message, @@ -23,7 +22,7 @@ from aleph.vm.pool import VmPool from aleph.vm.utils import create_task_log_exceptions -from .messages import get_message_status, load_updated_message +from .messages import get_message_status from .payment import ( compute_required_balance, compute_required_flow, diff --git a/src/aleph/vm/orchestrator/views/authentication.py b/src/aleph/vm/orchestrator/views/authentication.py index 023bee48..40ab4a39 100644 --- a/src/aleph/vm/orchestrator/views/authentication.py +++ b/src/aleph/vm/orchestrator/views/authentication.py @@ -22,7 +22,7 @@ from jwcrypto import jwk from jwcrypto.jwa import JWA from nacl.exceptions import BadSignatureError -from pydantic import field_validator, model_validator, BaseModel, ValidationError +from pydantic import BaseModel, ValidationError, field_validator, model_validator from solathon.utils import verify_signature from aleph.vm.conf import settings @@ -102,7 +102,7 @@ def payload_must_be_hex(cls, v: bytes) -> bytes: """Convert the payload from hexadecimal to bytes""" return bytes.fromhex(v.decode()) - @model_validator(skip_on_failure=True) + @model_validator(mode="after") @classmethod def check_expiry(cls, values) -> dict[str, bytes]: """Check that the token has not expired""" @@ -113,7 +113,7 @@ def check_expiry(cls, values) -> dict[str, bytes]: raise ValueError(msg) return values - @model_validator(skip_on_failure=True) + @model_validator(mode="after") @classmethod def check_signature(cls, values) -> dict[str, bytes]: """Check that the signature is valid"""