Skip to content
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

Add support for yaml OSCAL files validation #1091

Merged
Merged
Show file tree
Hide file tree
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
9 changes: 8 additions & 1 deletion src/utils/util/oscal-content-validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
import argparse
from jsonschema import validate
import xmlschema
from ruamel.yaml import YAML


def _get_oscal_file_type(filename):
if filename.endswith("json"):
return "json"
elif filename.endswith("xml") or filename.endswith("xsd"):
return "xml"
elif filename.endswith("yaml") or filename.endswith("yml"):
return "yaml"
else:
raise("Not a valid OSCAL file.")

Expand All @@ -21,6 +24,9 @@ def read_file(filename, ftype):
with io.open(filename, 'r', encoding="utf-8") as f:
if ftype == "json":
filedata = json.load(f)
if ftype == "yaml":
yaml = YAML()
filedata = yaml.load(f)
else:
filedata = f.read()
return filedata, ftype
Expand All @@ -41,7 +47,8 @@ def oscal_validator(oscal_schema, oscal_data):
schema, stype = read_file(oscal_schema, _get_oscal_file_type(oscal_schema))
data, ftype = read_file(oscal_data, _get_oscal_file_type(oscal_data))

if ftype == 'json':
if ftype == 'json' or ftype == 'yaml':
# Yaml files are validated using the json schema
validate(data, schema)
if ftype == 'xml':
xmlschema.validate(data, schema)
Expand Down
5 changes: 3 additions & 2 deletions src/utils/util/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
jsonschema
xmlschema
jsonschema==4.4.0
ruamel.yaml==0.17.10
xmlschema==1.9.2