jsonschema validation

This commit is contained in:
burnettk 2024-08-15 11:46:59 -04:00
parent 30a1424f57
commit ba2c38ac9d
No known key found for this signature in database
2 changed files with 14 additions and 0 deletions

View File

@ -1,5 +1,6 @@
import json import json
import argparse import argparse
import jsonschema
def convert_to_sarif(ecr_response): def convert_to_sarif(ecr_response):
@ -152,6 +153,12 @@ def convert_to_sarif(ecr_response):
def main(): def main():
def load_sarif_schema(schema_path):
with open(schema_path, "r") as f:
return json.load(f)
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description="Convert ECR scan findings to SARIF format." description="Convert ECR scan findings to SARIF format."
) )
@ -161,13 +168,19 @@ def main():
help="The input JSON file with ECR scan findings.", help="The input JSON file with ECR scan findings.",
) )
parser.add_argument("--output_file", required=True, help="The output SARIF file.") parser.add_argument("--output_file", required=True, help="The output SARIF file.")
SCHEMA_FILE_PATH = "./wait-for-ecr-scan-and-get-sarif/sarif-schema-2.1.0.json"
args = parser.parse_args() args = parser.parse_args()
sarif_schema = load_sarif_schema(SCHEMA_FILE_PATH)
with open(args.input_file, "r") as f: with open(args.input_file, "r") as f:
ecr_response = json.load(f) ecr_response = json.load(f)
sarif_report = convert_to_sarif(ecr_response) sarif_report = convert_to_sarif(ecr_response)
validate_sarif(sarif_report, sarif_schema)
with open(args.output_file, "w") as f: with open(args.output_file, "w") as f:
json.dump(sarif_report, f, indent=2) json.dump(sarif_report, f, indent=2)

View File

@ -0,0 +1 @@
jsonschema