77
88from __future__ import annotations
99
10+ import json
1011from typing import TYPE_CHECKING
1112
1213if TYPE_CHECKING :
@@ -383,10 +384,10 @@ def set_efs(self) -> None:
383384 "Properties" : volume .efs_definition ,
384385 "MacroParameters" : volume .parameters ,
385386 "Lookup" : volume .lookup ,
386- "Services" : [
387- { "name" : service .name , "access " : "RW" }
387+ "Services" : {
388+ service .name : { "Access " : "RW" }
388389 for service in volume .services
389- ] ,
390+ } ,
390391 "Settings" : {"Subnets" : "StorageSubnets" },
391392 "Volume" : volume ,
392393 }
@@ -513,13 +514,11 @@ def set_families(self) -> None:
513514 LOG .debug ([self .families [family ] for family in self .families ])
514515
515516 def set_content (self , kwargs , content = None , fully_load = True ):
516- """
517- Method to initialize the compose content
517+ """Method to initialize the compose content and validate as per the compose-x specs schemas."""
518+ from jsonschema import Draft7Validator
519+
520+ from ecs_composex .specs import REGISTRY
518521
519- :param dict kwargs:
520- :param dict content:
521- :param bool fully_load:
522- """
523522 files = (
524523 []
525524 if not keyisset (self .input_file_arg , kwargs )
@@ -529,16 +528,15 @@ def set_content(self, kwargs, content=None, fully_load=True):
529528 content_def = ComposeDefinition (files , content )
530529 self .original_content = content_def .definition
531530 self .compose_content = deepcopy (content_def .definition )
532- source = pkg_files ("ecs_composex" ).joinpath ("specs/compose-spec.json" )
533- LOG .info (f"Validating against input schema { source } " )
534- resolver = jsonschema .RefResolver (
535- f"file://{ path .abspath (path .dirname (source ))} /" , None
536- )
537- jsonschema .validate (
538- content_def .definition ,
539- loads (source .read_text ()),
540- resolver = resolver ,
541- )
531+ source = str (pkg_files ("ecs_composex" ).joinpath ("specs/compose-spec.json" ))
532+ LOG .debug (f"Validating against input schema { source } " )
533+
534+ with open (source ) as compose_fd :
535+ content = compose_fd .read ()
536+ schema = json .loads (content )
537+
538+ _eval = Draft7Validator (schema , registry = REGISTRY )
539+ _eval .validate (content_def .definition )
542540 if fully_load :
543541 self .set_secrets ()
544542 self .set_volumes ()
0 commit comments