63 lines
2.5 KiB
Python
63 lines
2.5 KiB
Python
|
|
from dataclasses import dataclass, field
|
||
|
|
import json
|
||
|
|
import os
|
||
|
|
from pathlib import Path
|
||
|
|
|
||
|
|
|
||
|
|
@dataclass
|
||
|
|
class Settings:
|
||
|
|
root: Path
|
||
|
|
sources: list
|
||
|
|
allowed_hosts: list = field(default_factory=lambda: ["10.88.118.188:14442", "10.88.118.188:14440"])
|
||
|
|
allowed_networks: list = field(default_factory=lambda: ["10.88.0.0/17", "10.20.0.0/21"])
|
||
|
|
test_mode: bool = False
|
||
|
|
max_upload: int = 1024 * 1024
|
||
|
|
max_log: int = 16 * 1024 * 1024
|
||
|
|
max_artifact: int = 32 * 1024 * 1024
|
||
|
|
max_run_files: int = 64
|
||
|
|
test_definitions: list = field(default_factory=list)
|
||
|
|
example_script_ids: list = field(default_factory=list)
|
||
|
|
native_catalog: dict = field(default_factory=lambda: {"profiles": [], "targets": []})
|
||
|
|
|
||
|
|
@property
|
||
|
|
def native_socket(self):
|
||
|
|
return self.root / "native-ipc" / "control.sock"
|
||
|
|
|
||
|
|
@property
|
||
|
|
def library(self):
|
||
|
|
return self.root / "library"
|
||
|
|
|
||
|
|
@property
|
||
|
|
def runs(self):
|
||
|
|
return self.root / "runs"
|
||
|
|
|
||
|
|
@property
|
||
|
|
def db(self):
|
||
|
|
return self.root / "console-data" / "console.sqlite3"
|
||
|
|
|
||
|
|
def prepare(self):
|
||
|
|
self.validate_paths()
|
||
|
|
for directory in (self.root, self.library, self.runs, self.db.parent):
|
||
|
|
directory.mkdir(parents=True, exist_ok=True)
|
||
|
|
|
||
|
|
def validate_paths(self):
|
||
|
|
for directory in (self.root, self.library, self.runs, self.db.parent):
|
||
|
|
if not directory.is_absolute():
|
||
|
|
raise ValueError("Runtime must be an absolute path")
|
||
|
|
for part in (directory, *directory.parents):
|
||
|
|
if part.is_symlink():
|
||
|
|
raise ValueError("Runtime paths must not contain symlinks")
|
||
|
|
for path in (self.db, Path(str(self.db) + "-wal"), Path(str(self.db) + "-shm")):
|
||
|
|
if path.is_symlink():
|
||
|
|
raise ValueError("Database symlinks are not supported")
|
||
|
|
|
||
|
|
@classmethod
|
||
|
|
def from_env(cls):
|
||
|
|
project = Path(__file__).resolve().parents[1]
|
||
|
|
catalog = json.loads((project / "catalog/external-sources.json").read_text(encoding="utf-8"))
|
||
|
|
tests = json.loads((project / "catalog/test-definitions.json").read_text(encoding="utf-8"))
|
||
|
|
native_file = project / "catalog/native-profiles.json"
|
||
|
|
native = json.loads(native_file.read_text(encoding="utf-8")) if native_file.exists() else {"profiles": [], "targets": []}
|
||
|
|
return cls(Path(os.environ.get("XAS_CONSOLE_ROOT", str(project / "runtime"))), catalog["sources"],
|
||
|
|
test_definitions=tests["tests"], example_script_ids=tests.get("example_script_ids", []), native_catalog=native)
|