@@ -444,19 +444,23 @@ def _fix_type_to_template(fix_type):
444444 return template
445445
446446
447- def generate_fix_for_result (config , results_path , fix_type ):
448- if not os .path .exists (results_path ):
449- raise RuntimeError ("Can't generate fix for scan result. Expected "
450- "results XML at '%s' but the file doesn't exist."
451- % results_path )
447+ def _get_result_id (results_path ):
452448 tree = ElementTree .parse (results_path )
453449 root = tree .getroot ()
454450 ns = {"xccdf" : "http://checklists.nist.gov/xccdf/1.2" }
455451 test_result = root .find (".//xccdf:TestResult" , ns )
456452 if test_result is None :
457453 raise RuntimeError ("Results XML '%s' doesn't contain any results."
458454 % results_path )
459- result_id = test_result .attrib ["id" ]
455+ return test_result .attrib ["id" ]
456+
457+
458+ def generate_fix_for_result (config , results_path , fix_type ):
459+ if not os .path .exists (results_path ):
460+ raise RuntimeError ("Can't generate fix for scan result. Expected "
461+ "results XML at '%s' but the file doesn't exist."
462+ % results_path )
463+ result_id = _get_result_id (results_path )
460464 template = _fix_type_to_template (fix_type )
461465 args = [config .oscap_path , "xccdf" , "generate" , "fix" ,
462466 "--result-id" , result_id ,
@@ -466,6 +470,18 @@ def generate_fix_for_result(config, results_path, fix_type):
466470 return fix_text
467471
468472
473+ def generate_html_report_for_result (config , results_path ):
474+ if not os .path .exists (results_path ):
475+ raise RuntimeError ("Can't generate report for scan result. Expected "
476+ "results XML at '%s' but the file doesn't exist."
477+ % results_path )
478+ result_id = _get_result_id (results_path )
479+ args = [config .oscap_path , "xccdf" , "generate" , "report" ,
480+ "--result-id" , result_id , results_path ]
481+ report_text = subprocess_check_output (args ).decode ("utf-8" )
482+ return report_text
483+
484+
469485def generate_fix (spec , config , fix_type ):
470486 if spec .mode not in [EvaluationMode .SOURCE_DATASTREAM ,
471487 EvaluationMode .STANDARD_SCAN ]:
0 commit comments