agent
This commit is contained in:
26
agent/app/core/manifest_validator.py
Normal file
26
agent/app/core/manifest_validator.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from app.config import settings
|
||||
from app.models.schemas import AppManifest, DebComponent
|
||||
from app.utils.validators import validate_url_host
|
||||
|
||||
|
||||
class ManifestValidator:
|
||||
def validate(self, payload: dict) -> dict:
|
||||
manifest = AppManifest.model_validate(payload).model_dump(by_alias=True)
|
||||
components = []
|
||||
for raw_component in manifest["components"]:
|
||||
component_type = raw_component.get("type")
|
||||
if component_type == "deb":
|
||||
component = DebComponent.model_validate(raw_component).model_dump(by_alias=True)
|
||||
validate_url_host(component["downloadUrl"], settings.allowed_download_hosts)
|
||||
components.append(component)
|
||||
elif component_type == "docker" and not settings.allow_docker:
|
||||
raise ValueError("Docker components are not enabled on this Agent")
|
||||
elif component_type == "docker_compose" and not settings.allow_docker_compose:
|
||||
raise ValueError("Docker Compose components are not enabled on this Agent")
|
||||
else:
|
||||
raise ValueError(f"Unsupported component type: {component_type}")
|
||||
manifest["components"] = sorted(components, key=lambda item: item.get("installOrder", 10))
|
||||
return manifest
|
||||
|
||||
Reference in New Issue
Block a user