Skip to content

Commit

Permalink
Updates to schema to add schemaVersion as optional field
Browse files Browse the repository at this point in the history
  • Loading branch information
sei-vsarvepalli committed Jul 12, 2024
1 parent dc1c054 commit 3101424
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 49 deletions.
3 changes: 2 additions & 1 deletion data/json/decision_points/system_exposure_1_0_0.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"namespace": "ssvc",
"schemaVersion": "1-0-1",
"version": "1.0.0",
"key": "EXP",
"name": "System Exposure",
Expand All @@ -21,4 +22,4 @@
"description": "Internet or another widely accessible network where access cannot plausibly be restricted or controlled (e.g., DNS servers, web servers, VOIP servers, email servers)"
}
]
}
}
2 changes: 1 addition & 1 deletion data/schema/current/Decision_Point_Group.schema.json
61 changes: 33 additions & 28 deletions data/schema/v1/Decision_Point-1-0-1.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,42 +36,47 @@
"type": "object",
"additionalProperties": false,
"properties": {
"namespace": {
"type": "string",
"description": "Namespace (a short, unique string): For example, \"ssvc\" or \"cvss\" to indicate the source of the decision point"
},
"version": {
"type": "string",
"description": "Version (a semantic version string) that identifies this object"
},
"key": {
"type": "string",
"description": "A key (a short, unique string) that can be used to identify the Decision Point/Decision Point value in a shorthand way"
},
"name": {
"type": "string",
"description": "A short label that captures the description of the Decision Point or the Group of Decision Points."
},
"description": {
"type": "string",
"description": "q Description of the Decision Point or the Group of Decision Points as defined."
},
"values": {
"description": "Decision Point Values are valid results from a Decision Point",
"uniqueItems": true,
"type": "array",
"items": {
"$ref": "#/definitions/decision_point_value"
"schemaVersion": {
"$ref": "#/definitions/schemaVersion"
},
"namespace": {
"type": "string",
"description": "Namespace (a short, unique string): For example, \"ssvc\" or \"cvss\" to indicate the source of the decision point"
},
"version": {
"type": "string",
"description": "Version (a semantic version string) that identifies this object"
},
"key": {
"type": "string",
"description": "A key (a short, unique string) that can be used to identify the Decision Point/Decision Point value in a shorthand way"
},
"name": {
"type": "string",
"description": "A short label that captures the description of the Decision Point or the Group of Decision Points."
},
"description": {
"type": "string",
"description": "q Description of the Decision Point or the Group of Decision Points as defined."
},
"values": {
"description": "Decision Point Values are valid results from a Decision Point",
"uniqueItems": true,
"type": "array",
"minItems": 1,
"items": {
"$ref": "#/definitions/decision_point_value"
}
}
}
},
"required": [
"namespace",
"version",
"key",
"name",
"description",
"values"
"values",
"schemaVersion"
]
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
"type": "object",
"additionalProperties": false,
"properties": {
"schemaVersion": {
"$ref": "#/definitions/schemaVersion"
},
"version": {
"type": "string",
"description": "Version (a semantic version string) that identifies this object"
Expand All @@ -26,16 +29,18 @@
},
"decision_points": {
"type": "array",
"minItems": 1,
"items": {
"$ref": "https://certcc.github.io/SSVC/data/schema/Decision_Point.schema.json"
"$ref": "https://certcc.github.io/SSVC/data/schema/v1/Decision_Point-1-0-1.schema.json"
}
}
},
"required": [
"version",
"name",
"description",
"decision_points"
"decision_points",
"schemaVersion"
]
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"description": "Evaluated values of the Decision Point",
"title": "values",
"type": "array",
"minItems": 1,
"items": {
"description": "Each value that were down-selected for a Decision Point",
"title": "values",
Expand Down Expand Up @@ -80,6 +81,7 @@
"description" : "An array of Decision Points and their Values that were down-selected or evaluated ",
"title": "selections",
"type": "array",
"minItems": 1,
"items": {
"$ref": "#/definitions/SsvcdecisionpointselectionSchema"
}
Expand Down
2 changes: 2 additions & 0 deletions src/ssvc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@
"""
Provides SSVC modules.
"""

_schemaVersion = "1-0-1"
3 changes: 2 additions & 1 deletion src/ssvc/_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

from dataclasses_json import config, dataclass_json

from . import _schemaVersion

@dataclass_json
@dataclass(kw_only=True)
Expand All @@ -31,7 +32,7 @@ class _Versioned:
"""

version: str = "0.0.0"

schemaVersion: str = _schemaVersion

@dataclass_json
@dataclass(kw_only=True)
Expand Down
33 changes: 17 additions & 16 deletions src/test/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
import unittest

import jsonschema
from jsonschema import Draft202012Validator
from referencing import Registry, Resource
import os

import ssvc.decision_points # noqa F401
from ssvc.decision_points.base import REGISTERED_DECISION_POINTS
Expand All @@ -29,15 +32,16 @@
# importing these causes the decision points to register themselves
from ssvc.dp_groups.ssvc.collections import SSVCv1, SSVCv2, SSVCv2_1 # noqa

def retrieve_local(uri):
fileuri = uri.replace("https://certcc.github.io/SSVC", os.getcwd())
if os.path.exists(fileuri):
fh = open(fileuri)
schema = json.load(fh)
fh.close()
return Resource.from_contents(schema)
raise FileNotFoundError(f"Could not find DEBUG path issues {fileuri}")

def find_schema(basepath: str) -> str:
import os

for pfx in (".", "..", "../.."):
path = os.path.join(pfx, basepath)
if os.path.exists(path):
return path
raise FileNotFoundError(f"Could not find {basepath}")
registry = Registry(retrieve=retrieve_local)


class MyTestCase(unittest.TestCase):
Expand All @@ -64,8 +68,7 @@ def test_confirm_registered_decision_points(self):

def test_decision_point_validation(self):
# path relative to top level of repo
schema_file = find_schema("data/schema/current/Decision_Point.schema.json")
schema = json.load(open(schema_file))
schema_url = "https://certcc.github.io/SSVC/data/schema/current/Decision_Point.schema.json"

decision_points = list(REGISTERED_DECISION_POINTS)
self.assertGreater(len(decision_points), 0)
Expand All @@ -76,7 +79,7 @@ def test_decision_point_validation(self):
loaded = json.loads(as_json)

try:
jsonschema.validate(loaded, schema)
Draft202012Validator({"$ref": schema_url}, registry=registry).validate(loaded)
except jsonschema.exceptions.ValidationError as e:
exp = e

Expand All @@ -86,21 +89,19 @@ def test_decision_point_validation(self):
)

def test_decision_point_group_validation(self):
schema_file = find_schema("data/schema/current/Decision_Point_Group.schema.json")
schema = json.load(open(schema_file))

schema_url = "https://certcc.github.io/SSVC/data/schema/current/Decision_Point_Group.schema.json"
for dpg in self.dpgs:
exp = None
as_json = dpg.to_json()
loaded = json.loads(as_json)

try:
jsonschema.validate(loaded, schema)
Draft202012Validator({"$ref": schema_url},registry=registry).validate(loaded)
except jsonschema.exceptions.ValidationError as e:
exp = e

self.assertIsNone(exp, f"Validation failed for {dpg.name} {dpg.version}")
self.logger.debug(f"Validation passed for {dpg.name} v{dpg.version}")
self.logger.debug(f"Validation passed for Decision Point Group {dpg.name} v{dpg.version}")


if __name__ == "__main__":
Expand Down

0 comments on commit 3101424

Please sign in to comment.