remove hack and move function out of function

This commit is contained in:
burnettk 2024-08-15 15:35:44 -04:00
parent b4cf99d35d
commit df69e9d9d2
No known key found for this signature in database
1 changed files with 6 additions and 24 deletions

View File

@ -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."
)