@@ -330,8 +330,9 @@ def process_input_dict(cls, input_contents, env_yaml, product_cpes=None):
330330 Raises:
331331 ValueError: If the operator in the input data is not one of the expected possible operators.
332332 """
333- input_contents ["interactive" ] = (
334- input_contents .get ("interactive" , "false" ).lower () == "true" )
333+ if "interactive" in input_contents and isinstance (input_contents ["interactive" ], str ):
334+ input_contents ["interactive" ] = (
335+ input_contents .get ("interactive" , "false" ).lower () == "true" )
335336
336337 data = super (Value , cls ).process_input_dict (input_contents , env_yaml )
337338
@@ -578,7 +579,7 @@ def add_profiles_from_dir(self, dir_, env_yaml, product_cpes):
578579 continue
579580
580581 try :
581- new_profile = ProfileWithInlinePolicies .from_yaml (
582+ new_profile = ProfileWithInlinePolicies .from_compiled_json (
582583 dir_item_path , env_yaml , product_cpes )
583584 except DocumentationNotComplete :
584585 continue
@@ -2867,9 +2868,9 @@ def save_entities(self, entities, destdir):
28672868 if not entities :
28682869 return
28692870 for entity in entities :
2870- basename = entity .id_ + ".yml "
2871+ basename = entity .id_ + ".json "
28712872 dest_filename = os .path .join (destdir , basename )
2872- entity .dump_yaml (dest_filename )
2873+ entity .dump_json (dest_filename )
28732874
28742875
28752876class BuildLoader (DirectoryLoader ):
@@ -3097,18 +3098,18 @@ def find_first_groups_ids(self, start_dir):
30973098
30983099 def load_entities_by_id (self , filenames , destination , cls ):
30993100 """
3100- Loads entities from a list of YAML files and stores them in a destination dictionary by their ID.
3101+ Loads entities from a list of JSON files and stores them in a destination dictionary by their ID.
31013102
31023103 Args:
3103- filenames (list of str): List of file paths to YAML files.
3104+ filenames (list of str): List of file paths to JSON files.
31043105 destination (dict): Dictionary to store the loaded entities, keyed by their ID.
3105- cls (type): Class type that has a `from_yaml` method to create an instance from a YAML file.
3106+ cls (type): Class type that has a `from_yaml` method to create an instance from a JSON file.
31063107
31073108 Returns:
31083109 None
31093110 """
31103111 for fname in filenames :
3111- entity = cls .from_yaml (fname , self .env_yaml , self .product_cpes )
3112+ entity = cls .from_compiled_json (fname , self .env_yaml , self .product_cpes )
31123113 destination [entity .id_ ] = entity
31133114
31143115 def add_fixes_to_rules (self ):
@@ -3187,7 +3188,7 @@ def get_benchmark_xml_by_profile(self, rule_and_variables_dict):
31873188 )
31883189
31893190 for profile in self .benchmark .profiles :
3190- if profile .single_rule_profile == "true" :
3191+ if profile .single_rule_profile :
31913192 profiles_ids , benchmark = self .benchmark .get_benchmark_xml_for_profiles (
31923193 self .env_yaml , [profile ], rule_and_variables_dict , include_contributors = False
31933194 )
@@ -3225,16 +3226,16 @@ def load_compiled_content(self):
32253226
32263227 self .fixes = ssg .build_remediations .load_compiled_remediations (self .fixes_dir )
32273228
3228- filenames = glob .glob (os .path .join (self .resolved_rules_dir , "*.yml " ))
3229+ filenames = glob .glob (os .path .join (self .resolved_rules_dir , "*.json " ))
32293230 self .load_entities_by_id (filenames , self .rules , Rule )
32303231
3231- filenames = glob .glob (os .path .join (self .resolved_groups_dir , "*.yml " ))
3232+ filenames = glob .glob (os .path .join (self .resolved_groups_dir , "*.json " ))
32323233 self .load_entities_by_id (filenames , self .groups , Group )
32333234
3234- filenames = glob .glob (os .path .join (self .resolved_values_dir , "*.yml " ))
3235+ filenames = glob .glob (os .path .join (self .resolved_values_dir , "*.json " ))
32353236 self .load_entities_by_id (filenames , self .values , Value )
32363237
3237- filenames = glob .glob (os .path .join (self .resolved_platforms_dir , "*.yml " ))
3238+ filenames = glob .glob (os .path .join (self .resolved_platforms_dir , "*.json " ))
32383239 self .load_entities_by_id (filenames , self .platforms , Platform )
32393240 self .product_cpes .platforms = self .platforms
32403241
@@ -3253,7 +3254,7 @@ def export_benchmark_to_xml(self, rule_and_variables_dict, ignore_single_rule_pr
32533254 str: The benchmark data in XML format.
32543255 """
32553256 if ignore_single_rule_profiles :
3256- profiles = [p for p in self .benchmark .profiles if p .single_rule_profile == "false" ]
3257+ profiles = [p for p in self .benchmark .profiles if not p .single_rule_profile ]
32573258 else :
32583259 profiles = self .benchmark .profiles
32593260 _ , benchmark = self .benchmark .get_benchmark_xml_for_profiles (
@@ -3535,12 +3536,12 @@ def from_yaml(cls, yaml_file, env_yaml=None, product_cpes=None):
35353536 Platform: A Platform object created from the YAML file.
35363537 """
35373538 platform = super (Platform , cls ).from_yaml (yaml_file , env_yaml )
3538- # If we received a product_cpes, we can restore also the original test object
3539- # it can be later used e.g. for comparison
3540- if product_cpes :
3541- platform . test = product_cpes . algebra . parse ( platform . original_expression , simplify = True )
3542- product_cpes . add_resolved_cpe_items_from_platform ( platform )
3543- return platform
3539+ return restore_original_test_object ( platform , product_cpes )
3540+
3541+ @ classmethod
3542+ def from_compiled_json ( cls , json_file_path , env_yaml = None , product_cpes = None ):
3543+ platform = super ( Platform , cls ). from_compiled_json ( json_file_path , env_yaml )
3544+ return restore_original_test_object ( platform , product_cpes )
35443545
35453546 def get_fact_refs (self ):
35463547 """
@@ -3602,3 +3603,12 @@ def add_platform_if_not_defined(platform, product_cpes):
36023603 return p
36033604 product_cpes .platforms [platform .id_ ] = platform
36043605 return platform
3606+
3607+
3608+ def restore_original_test_object (platform , product_cpes ):
3609+ # If we received a product_cpes, we can restore also the original test object
3610+ # it can be later used e.g. for comparison
3611+ if product_cpes :
3612+ platform .test = product_cpes .algebra .parse (platform .original_expression , simplify = True )
3613+ product_cpes .add_resolved_cpe_items_from_platform (platform )
3614+ return platform
0 commit comments