Skip to content

Commit

Permalink
fix settings
Browse files Browse the repository at this point in the history
  • Loading branch information
olethanh committed Oct 31, 2024
1 parent 998a0d4 commit ea51db4
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 15 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
28 changes: 20 additions & 8 deletions src/aleph/vm/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -24,7 +24,6 @@
file_hashes_differ,
is_command_available,
)
from pydantic_settings import BaseSettings, SettingsConfigDict

load_dotenv()

Expand Down Expand Up @@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -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}"
Expand Down Expand Up @@ -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:
Expand All @@ -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():
Expand Down
2 changes: 1 addition & 1 deletion src/aleph/vm/orchestrator/chain.py
Original file line number Diff line number Diff line change
@@ -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__)

Expand Down
3 changes: 1 addition & 2 deletions src/aleph/vm/orchestrator/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from aiohttp import web
from aleph_message.models import (
AlephMessage,
ItemHash,
PaymentType,
ProgramMessage,
parse_message,
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions src/aleph/vm/orchestrator/views/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"""
Expand All @@ -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"""
Expand Down

0 comments on commit ea51db4

Please sign in to comment.