Skip to content

Update validate.py - Comply with ISO 8601 for LastModified and Create… #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions bin/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import argparse
from pathlib import Path
from os import path, walk

import datetime

def check_md5_length(object):
md5_len = 32
Expand Down Expand Up @@ -59,6 +59,25 @@ def check_network_structure(object):
return f"ERROR: 'Ports' is not a list for object: {object['Name']}"
return None

# Add this function to validate ISO 8601 format for Created
def check_created_iso8601(object):
created = object.get('Created', None)
if created:
try:
datetime.datetime.fromisoformat(created)
except ValueError:
return f"ERROR: Created field is not valid ISO 8601 format for object: {object.get('Id', 'Unknown')}"
return None

# Add this function to validate ISO 8601 format for LastModified
def check_last_modified_iso8601(object):
last_modified = object.get('LastModified', None)
if last_modified:
try:
datetime.datetime.fromisoformat(last_modified)
except ValueError:
return f"ERROR: LastModified field is not valid ISO 8601 format for object: {object.get('Id', 'Unknown')}"
return None

def validate_schema(yaml_dir, schema_file, verbose):

Expand Down Expand Up @@ -93,11 +112,13 @@ def validate_schema(yaml_dir, schema_file, verbose):
error = True

# Additional YAML checks
check_errors = [
check_errors = [
check_md5_length(yaml_data),
check_sha1_length(yaml_data),
check_sha256_length(yaml_data),
check_network_structure(yaml_data),
check_created_iso8601(yaml_data), # ISO 8601 check for Created
check_last_modified_iso8601(yaml_data), # ISO 8601 check for LastModified
]

for check_error in check_errors:
Expand All @@ -107,7 +128,6 @@ def validate_schema(yaml_dir, schema_file, verbose):

return error, errors


def main(yaml_dir, schema_file, verbose):

error, errors = validate_schema(yaml_dir, schema_file, verbose)
Expand All @@ -120,7 +140,6 @@ def main(yaml_dir, schema_file, verbose):
else:
print("No Errors found")


if __name__ == "__main__":
# grab arguments
parser = argparse.ArgumentParser(description="Validates YAML files in a directory against a JSON schema")
Expand All @@ -133,4 +152,4 @@ def main(yaml_dir, schema_file, verbose):
schema_file = args.schema_file
verbose = args.verbose

main(yaml_dir, schema_file, verbose)
main(yaml_dir, schema_file, verbose)
Loading