From 7cd6458c6cf83d3288969e827d9d10ebd57ccdb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Prpi=C4=8D?= Date: Tue, 22 Nov 2022 13:54:59 -0500 Subject: [PATCH] Use published schema as default one when validating CVE records --- cvelib/cve_api.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/cvelib/cve_api.py b/cvelib/cve_api.py index 7dfcf3b..56986d8 100644 --- a/cvelib/cve_api.py +++ b/cvelib/cve_api.py @@ -34,7 +34,18 @@ class Schemas(Constants): V5_SCHEMA = next(SCHEMA_DIR.glob("CVE_JSON_5.0_bundled_*.json")) @classmethod - def validate(cls, cve_json: dict, schema_path: str) -> None: + def validate(cls, cve_json: dict, schema_path: Optional[str] = None) -> None: + """Validate a CVE record against a JSON schema. + + Optionally, specify a path to a JSON schema file with which to validate the record; if not + specified, the Published CNA container schema bundled in cvelib/schemas/ is used. All + other schemas in that directory must be explicitly specified, e.g.: + + CveRecord.validate(cve_json, schema_path=CveRecord.Schemas.CNA_REJECTED) + """ + if schema_path is None: + schema_path = cls.Schemas.CNA_PUBLISHED + with open(schema_path) as schema_file: schema = json.load(schema_file)