From df69e9d9d28e3327365cabb9f2fc7d5ecc8fca32 Mon Sep 17 00:00:00 2001 From: burnettk Date: Thu, 15 Aug 2024 15:35:44 -0400 Subject: [PATCH] remove hack and move function out of function --- .../aws_scan_findings_to_sarif.py | 30 ++++--------------- 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/wait-for-ecr-scan-and-get-sarif/aws_scan_findings_to_sarif.py b/wait-for-ecr-scan-and-get-sarif/aws_scan_findings_to_sarif.py index 70376f3..f2a2b2d 100644 --- a/wait-for-ecr-scan-and-get-sarif/aws_scan_findings_to_sarif.py +++ b/wait-for-ecr-scan-and-get-sarif/aws_scan_findings_to_sarif.py @@ -179,21 +179,12 @@ def convert_to_sarif(ecr_response): return sarif_report -# hack. python's validator doesn't like the regex in the sarif schema. use a slightly simpler regex to validate language. -def update_schema_patterns(schema): - if isinstance(schema, dict): - # If the schema is a dictionary, check each key-value pair - for key, value in schema.items(): - if key == "pattern" and value == "^(?i)[a-zA]{2}(-[a-z]{2})?$": - # Replace the pattern with the simplified version - schema[key] = "^[a-zA-Z]{2}(-[a-zA-Z]{2})?$" - else: - # Recursively update nested dictionaries or lists - update_schema_patterns(value) - elif isinstance(schema, list): - # If the schema is a list, update each item - for item in schema: - update_schema_patterns(item) +def validate_sarif(sarif_report, schema): + try: + jsonschema.validate(instance=sarif_report, schema=schema) + print("SARIF report is valid.") + except jsonschema.ValidationError as e: + print(f"SARIF report is invalid: {e.message}") def main(): @@ -201,15 +192,6 @@ def main(): with open(schema_path, "r") as f: return json.load(f) - def validate_sarif(sarif_report, schema): - update_schema_patterns(schema) - - try: - jsonschema.validate(instance=sarif_report, schema=schema) - print("SARIF report is valid.") - except jsonschema.ValidationError as e: - print(f"SARIF report is invalid: {e.message}") - parser = argparse.ArgumentParser( description="Convert ECR scan findings to SARIF format." )