From 03f04f12e1e2b37a4ee3d3769bbe5fa5f4eeaa18 Mon Sep 17 00:00:00 2001 From: Johannes Roos Date: Fri, 25 Oct 2024 17:23:56 +0200 Subject: [PATCH] fixed requirements --- fakts/base_models.py | 3 ++- fakts/graphql/mutations/client.py | 2 +- fakts/logic.py | 10 +++++----- fakts/views.py | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/fakts/base_models.py b/fakts/base_models.py index 30e8e32..729bc11 100644 --- a/fakts/base_models.py +++ b/fakts/base_models.py @@ -10,6 +10,7 @@ class Requirement(BaseModel): + key: str service: str """ The service is the service that will be used to fill the key, it will be used to find the correct instance. It needs to fullfill the reverse domain naming scheme""" @@ -35,7 +36,7 @@ class Manifest(BaseModel): """ The logo is a url to a logo that should be used for the client. """ scopes: Optional[list[str]] = Field(default_factory=list) """ The scopes are a list of scopes that the client can request. """ - requirements: Optional[dict[str, Requirement]] = Field(default_factory=dict) + requirements: Optional[List[Requirement]] = Field(default_factory=list) """ The requirements are a list of requirements that the client needs to run on (e.g. needs GPU)""" diff --git a/fakts/graphql/mutations/client.py b/fakts/graphql/mutations/client.py index bc365a8..0d0db14 100644 --- a/fakts/graphql/mutations/client.py +++ b/fakts/graphql/mutations/client.py @@ -39,7 +39,7 @@ def create_developmental_client(info: Info, input: inputs.DevelopmentClientInput version=input.manifest.version, logo=input.manifest.logo, scopes=input.manifest.scopes or [], - requirements={x.key: Requirement(service=x.service, optional=x.optional, description=x.description) for x in input.requirements}, + requirements=[strawberry.asdict(x) for x in input.requirements], ) client = create_client( diff --git a/fakts/logic.py b/fakts/logic.py index aa0df81..d6d220c 100644 --- a/fakts/logic.py +++ b/fakts/logic.py @@ -59,8 +59,8 @@ def find_instance_for_requirement(service: models.Service, requirement: base_mod -def hash_requirements(requirements: dict[str, base_models.Requirement]) -> str: - return sha256(".".join([key + req.service for key, req in requirements.items()]).encode()).hexdigest() +def hash_requirements(requirements: list[base_models.Requirement]) -> str: + return sha256(".".join([req.service + req.key for req in requirements]).encode()).hexdigest() def auto_create_composition(manifest: base_models.Manifest) -> models.Composition: @@ -78,7 +78,7 @@ def auto_create_composition(manifest: base_models.Manifest) -> models.Compositio errors = [] warnings = [] - for key, req in manifest.requirements.items(): + for req in manifest.requirements: try: service = models.Service.objects.get(identifier=req.service) @@ -88,7 +88,7 @@ def auto_create_composition(manifest: base_models.Manifest) -> models.Compositio models.ServiceInstanceMapping.objects.create( composition=composition, instance=instance, - key=key, + key=req.key, ) except Exception as e: @@ -116,7 +116,7 @@ def check_compability(manifest: base_models.Manifest) -> list[str] | list[str]: errors = [] warnings = [] - for key, req in manifest.requirements.items(): + for req in manifest.requirements: try: try: diff --git a/fakts/views.py b/fakts/views.py index d81b4ce..6e49b17 100644 --- a/fakts/views.py +++ b/fakts/views.py @@ -123,7 +123,7 @@ def get_context_data(self, **kwargs): print(manifest.requirements) - context["composition_requirements"] = {key: req.service for key, req in manifest.requirements.items()} + context["composition_requirements"] = {req.key: req.service for req in manifest.requirements} context["composition_errors"] = composition_errors context["composition_warnings"] = composition_warnings context["staging_identifier"] = x.staging_manifest["identifier"]