From 771bf70e54e9a37aaf3cade711aa580734e6d56c Mon Sep 17 00:00:00 2001 From: Valentin Robert Date: Tue, 5 Sep 2023 12:57:27 -0700 Subject: [PATCH] migration: v13 changes --- migration/migration_helpers/create_class.py | 41 + .../migration_helpers/create_property.py | 51 + .../relocate_class_and_properties.py | 49 + migration/ontology_changes/ontology_change.py | 4 +- .../utils/delete_property_from_node_list.py | 2 +- migration/rack/commits/__init__.py | 15 +- ...00edc6e33bc50fc4ee4d3bd01268d297e48dce6.py | 227 +++++ ...497287426ac99acffbd51858ebf4722af06dae2.py | 19 + ...a9c143c53933d7eeb51f19c3ddc4ccf5fda95a8.py | 19 + ...454889c706f02818f4badc3360a3c068fa014a0.py | 890 ++++++++++++++++++ ...485aa4268867521cc8d6f9c3a0f6fd2aef4311b.py | 20 + migration/rack/namespaces/rack_ontology.py | 2 + migration/rack_migrate/rack_migrate | 1 - 13 files changed, 1335 insertions(+), 5 deletions(-) create mode 100644 migration/migration_helpers/create_class.py create mode 100644 migration/migration_helpers/create_property.py create mode 100644 migration/migration_helpers/relocate_class_and_properties.py create mode 100644 migration/rack/commits/commit000edc6e33bc50fc4ee4d3bd01268d297e48dce6.py create mode 100644 migration/rack/commits/commitd497287426ac99acffbd51858ebf4722af06dae2.py create mode 100644 migration/rack/commits/commitda9c143c53933d7eeb51f19c3ddc4ccf5fda95a8.py create mode 100644 migration/rack/commits/commite454889c706f02818f4badc3360a3c068fa014a0.py create mode 100644 migration/rack/commits/commite485aa4268867521cc8d6f9c3a0f6fd2aef4311b.py diff --git a/migration/migration_helpers/create_class.py b/migration/migration_helpers/create_class.py new file mode 100644 index 00000000..15fea817 --- /dev/null +++ b/migration/migration_helpers/create_class.py @@ -0,0 +1,41 @@ + +# Copyright (c) 2023, Galois, Inc. +# +# All Rights Reserved +# +# This material is based upon work supported by the Defense Advanced Research +# Projects Agency (DARPA) under Contract No. FA8750-20-C-0203. +# +# Any opinions, findings and conclusions or recommendations expressed in this +# material are those of the author(s) and do not necessarily reflect the views +# of the Defense Advanced Research Projects Agency (DARPA). + +from typing import List + +from migration_helpers.name_space import NameSpace +from ontology_changes import ( + AddClassIsATypeOf, + CreateClass, +) +from ontology_changes.cardinality import Cardinality +from ontology_changes.ontology_change import OntologyChange +from ontology_changes.range_restriction import RangeRestriction + +def create_class_with_type_of( + namespace: NameSpace, + class_id: str, + type_of_namespace: NameSpace, + type_of_class: str, +) -> List[OntologyChange]: + return [ + CreateClass( + name_space=namespace, + class_id=class_id, + ), + AddClassIsATypeOf( + name_space=namespace, + class_id=class_id, + range_name_space=type_of_namespace, + range_id=type_of_class, + ), + ] diff --git a/migration/migration_helpers/create_property.py b/migration/migration_helpers/create_property.py new file mode 100644 index 00000000..f047eef2 --- /dev/null +++ b/migration/migration_helpers/create_property.py @@ -0,0 +1,51 @@ +# Copyright (c) 2023, Galois, Inc. +# +# All Rights Reserved +# +# This material is based upon work supported by the Defense Advanced Research +# Projects Agency (DARPA) under Contract No. FA8750-20-C-0203. +# +# Any opinions, findings and conclusions or recommendations expressed in this +# material are those of the author(s) and do not necessarily reflect the views +# of the Defense Advanced Research Projects Agency (DARPA). + +from typing import List, List + +from migration_helpers.name_space import NameSpace +from ontology_changes import ( + AddRangeRestriction, + ChangeCardinality, + CreateProperty, +) +from ontology_changes.cardinality import Cardinality +from ontology_changes.ontology_change import OntologyChange +from ontology_changes.range_restriction import RangeRestriction + +def create_property_with_cardinality_and_range( + namespace: NameSpace, + class_id: str, + property_id: str, + range: RangeRestriction, + cardinality: Cardinality, +) -> List[OntologyChange]: + return [ + CreateProperty( + name_space=namespace, + class_id=class_id, + property_id=property_id, + ), + AddRangeRestriction( + domain_name_space=namespace, + domain_class=class_id, + prop_name_space=namespace, + prop_name=property_id, + restriction=range, + ), + ChangeCardinality( + name_space=namespace, + class_id=class_id, + property_id=property_id, + to_cardinality=cardinality, + ), + + ] diff --git a/migration/migration_helpers/relocate_class_and_properties.py b/migration/migration_helpers/relocate_class_and_properties.py new file mode 100644 index 00000000..ba6e95c7 --- /dev/null +++ b/migration/migration_helpers/relocate_class_and_properties.py @@ -0,0 +1,49 @@ +# Copyright (c) 2023, Galois, Inc. +# +# All Rights Reserved +# +# This material is based upon work supported by the Defense Advanced Research +# Projects Agency (DARPA) under Contract No. FA8750-20-C-0203. +# +# Any opinions, findings and conclusions or recommendations expressed in this +# material are those of the author(s) and do not necessarily reflect the views +# of the Defense Advanced Research Projects Agency (DARPA). + +from typing import List + +from migration_helpers.name_space import NameSpace +from ontology_changes import ( + RenameClass, + RenameProperty, +) +from ontology_changes.ontology_change import OntologyChange + + +def relocate_class_and_properties( + from_namespace: NameSpace, + to_namespace: NameSpace, + class_id: str, + properties: List[str], +) -> List[OntologyChange]: + # Explicit type ascriptions to circumvent the fact that List is not + # covariant + rename_class: List[OntologyChange] = [ + RenameClass( + from_name_space=from_namespace, + from_name=class_id, + to_name_space=to_namespace, + to_name=class_id, + ) + ] + rename_properties: List[OntologyChange] = [ + RenameProperty( + from_name_space=from_namespace, + from_class=class_id, + from_name=property_id, + to_name_space=to_namespace, + to_class=class_id, + to_name=property_id, + ) + for property_id in properties + ] + return rename_class + rename_properties diff --git a/migration/ontology_changes/ontology_change.py b/migration/ontology_changes/ontology_change.py index 7f2bf50d..6de11edd 100644 --- a/migration/ontology_changes/ontology_change.py +++ b/migration/ontology_changes/ontology_change.py @@ -12,7 +12,7 @@ from dataclasses import dataclass import logging from abc import ABC, abstractmethod -from typing import List, Optional +from typing import Optional, Sequence from colorama import Fore, Style from semtk import SemTKJSON @@ -124,6 +124,6 @@ def migrate_json(self, json: SemTKJSON) -> None: @dataclass class Commit: - changes: List[OntologyChange] + changes: Sequence[OntologyChange] number: str tag: Optional[str] = None diff --git a/migration/ontology_changes/utils/delete_property_from_node_list.py b/migration/ontology_changes/utils/delete_property_from_node_list.py index 4d230d5c..e71ecd24 100644 --- a/migration/ontology_changes/utils/delete_property_from_node_list.py +++ b/migration/ontology_changes/utils/delete_property_from_node_list.py @@ -41,9 +41,9 @@ def delete_property_from_node_list( for sparqlID in node.SnodeSparqlIDs: if json.importSpec is None: continue + field = stylize_json("sparqlID") for index, importSpecNode in enumerate(json.importSpec.nodes): if importSpecNode.sparqlID == sparqlID: - field = stylize_json("sparqlID") log_additional_deletion( f"importSpec.nodes[{index}]", f"it has {field} = {sparqlID}", diff --git a/migration/rack/commits/__init__.py b/migration/rack/commits/__init__.py index 2726ffc3..2cc86d81 100644 --- a/migration/rack/commits/__init__.py +++ b/migration/rack/commits/__init__.py @@ -14,6 +14,7 @@ from ontology_changes.ontology_change import Commit from rack.commits import ( # DO NOT EDIT OR MOVE THIS LINE + commit000edc6e33bc50fc4ee4d3bd01268d297e48dce6, commit05a03cd687e3bdce425794763e0957d3ccaf8ff0, commit096749fb6a984d801d9ace5ccf5ec269de390a66, commit09962dd9ab9d252639d9e4324288fd6b47cbd91f, @@ -81,9 +82,13 @@ commitc6692fed3e150e7df53d4a2a8f8c84f760087420, commitcafce30763b5332106340cc8cbeb8fdac3b8132d, commitd48e208669c589d070c7c5fb7e3129ababbb9193, + commitd497287426ac99acffbd51858ebf4722af06dae2, commitd8271d216704351cf0007a04abac47f4abc993ad, + commitda9c143c53933d7eeb51f19c3ddc4ccf5fda95a8, commitdf67562c4e5305fc9082fc369570de0a49089ccf, commite18de6ebaa298881aab7e8e69580905ffb97e0c4, + commite454889c706f02818f4badc3360a3c068fa014a0, + commite485aa4268867521cc8d6f9c3a0f6fd2aef4311b, commite5e8a35322fab104a42cc0f46d16c27ffc10adbb, commite696969a9d85ca8f894eea12305412bdc05521b3, commiteb2f51ed862f33d2a56bbd6d43af27d9524912c9, @@ -107,7 +112,6 @@ commits_in_chronological_order: List[Commit] = [ # DO NOT EDIT OR MOVE THIS LINE - # oldest (in history) commita9210534a2ceb9ea5595df9eb5cd02df3abe3cb3.commit, # v4.0 @@ -212,6 +216,15 @@ commit8a01ff1b53e0b4979f0120a362b8fd3776a6586c.commit, # 2023 Jan 10 commit96c4d5d8672bbb8e8b5ff44ea928638092f91b82.commit, # 2023 Feb 21 + commite485aa4268867521cc8d6f9c3a0f6fd2aef4311b.commit, # v12.0 + + commitd497287426ac99acffbd51858ebf4722af06dae2.commit, # 2023 Apr 11 + commit000edc6e33bc50fc4ee4d3bd01268d297e48dce6.commit, # 2023 May 01 + commite454889c706f02818f4badc3360a3c068fa014a0.commit, # 2023 May 02 + commitda9c143c53933d7eeb51f19c3ddc4ccf5fda95a8.commit, # 2023 May 12 + + # commit???.commit, # v13 + # most recent (in history) ] diff --git a/migration/rack/commits/commit000edc6e33bc50fc4ee4d3bd01268d297e48dce6.py b/migration/rack/commits/commit000edc6e33bc50fc4ee4d3bd01268d297e48dce6.py new file mode 100644 index 00000000..4b82aba1 --- /dev/null +++ b/migration/rack/commits/commit000edc6e33bc50fc4ee4d3bd01268d297e48dce6.py @@ -0,0 +1,227 @@ +# Copyright (c) 2023, Galois, Inc. +# +# All Rights Reserved +# +# This material is based upon work supported by the Defense Advanced Research +# Projects Agency (DARPA) under Contract No. FA8750-20-C-0203. +# +# Any opinions, findings and conclusions or recommendations expressed in this +# material are those of the author(s) and do not necessarily reflect the views +# of the Defense Advanced Research Projects Agency (DARPA). + +from migration_helpers.create_property import create_property_with_cardinality_and_range +from ontology_changes import ( + AddClassIsATypeOf, + AddRangeRestriction, + AddPropertyIsATypeOf, + ChangeClassIsATypeOf, + Commit, + CreateClass, + CreateProperty, + DeleteProperty, +) +from ontology_changes.cardinality import SingleValue, Unconstrained +from ontology_changes.range_restriction import OnlyValuesOfType +from rack.namespaces.rack_ontology import AGENTS, FILE, PROV_S, TESTING +from rack.namespaces.xml_schema import XMLSCHEMA + +commit = Commit( + number="000edc6e33bc50fc4ee4d3bd01268d297e48dce6", + changes=[ + # AGENTS.sadl + CreateProperty( + name_space=AGENTS, + class_id="PERSON", + property_id="role", + ), + # TESTING.sadl + CreateProperty( + name_space=TESTING, + class_id="TEST_PROCEDURE", + property_id="independentTest", + ), + AddRangeRestriction( + domain_name_space=TESTING, + domain_class="TEST_PROCEDURE", + prop_name_space=TESTING, + prop_name="independentTest", + restriction=OnlyValuesOfType( + type_namespace=TESTING, + type_class="TEST_STEP", + ), + ), + AddPropertyIsATypeOf( + name_space=TESTING, + class_id="TEST_PROCEDURE", + property_id="independentTest", + range_name_space=PROV_S, + range="content", + ), + ChangeClassIsATypeOf( + name_space=TESTING, + class_id="TEST_STEP", + from_name_space=PROV_S, + from_class_id="COLLECTION", + to_name_space=PROV_S, + to_class_id="ENTITY", + ), + DeleteProperty( + name_space=TESTING, + property_id="content", + ), + ] + + create_property_with_cardinality_and_range( + namespace=TESTING, + class_id="TEST_STEP", + property_id="thisStep", + range=OnlyValuesOfType( + type_namespace=TESTING, + type_class="TEST", + ), + cardinality=Unconstrained(), + ) + + [ + ChangeClassIsATypeOf( + name_space=TESTING, + class_id="TEST_RECORD", + from_name_space=PROV_S, + from_class_id="COLLECTION", + to_name_space=PROV_S, + to_class_id="ENTITY", + ), + # NOTE: this is redundant because we did not distinguish multiple + # properties with the same name in the same namespace. Looks like maybe + # SADL actually supports it? + DeleteProperty( + name_space=TESTING, + property_id="content", + ), + ] + + create_property_with_cardinality_and_range( + namespace=TESTING, + class_id="TEST_RECORD", + property_id="testRecordProcedure", + range=OnlyValuesOfType( + type_namespace=TESTING, + type_class="TEST_PROCEDURE", + ), + cardinality=SingleValue(), + ) + + create_property_with_cardinality_and_range( + namespace=TESTING, + class_id="TEST_RECORD", + property_id="testRecordSteps", + range=OnlyValuesOfType( + type_namespace=TESTING, + type_class="TEST_STEP", + ), + cardinality=Unconstrained(), + ) + + create_property_with_cardinality_and_range( + namespace=TESTING, + class_id="TEST_RECORD", + property_id="testConfiguration", + range=OnlyValuesOfType( + type_namespace=PROV_S, + type_class="ENTITY", + ), + cardinality=Unconstrained(), + ) + + create_property_with_cardinality_and_range( + namespace=TESTING, + class_id="TEST_RECORD", + property_id="targetPackage", + range=OnlyValuesOfType( + type_namespace=FILE, + type_class="FILE", + ), + cardinality=Unconstrained(), + ) + + create_property_with_cardinality_and_range( + namespace=TESTING, + class_id="TEST_RECORD", + property_id="targetVersion", + range=OnlyValuesOfType( + type_namespace=XMLSCHEMA, + type_class="string", + ), + cardinality=SingleValue(), + ) + + create_property_with_cardinality_and_range( + namespace=TESTING, + class_id="TEST_RECORD", + property_id="testPackage", + range=OnlyValuesOfType( + type_namespace=FILE, + type_class="FILE", + ), + cardinality=Unconstrained(), + ) + + create_property_with_cardinality_and_range( + namespace=TESTING, + class_id="TEST_RECORD", + property_id="testVersion", + range=OnlyValuesOfType( + type_namespace=XMLSCHEMA, + type_class="string", + ), + cardinality=SingleValue(), + ) + + create_property_with_cardinality_and_range( + namespace=TESTING, + class_id="TEST_EXECUTION", + property_id="testLog", + range=OnlyValuesOfType( + type_namespace=TESTING, + type_class="TEST_LOG", + ), + cardinality=Unconstrained(), + ) + + [ + AddPropertyIsATypeOf( + name_space=TESTING, + class_id="TEST_EXECUTION", + property_id="testLog", + range_name_space=PROV_S, + range="goal", + ), + CreateClass(name_space=TESTING, class_id="TEST_ANNOTATION"), + AddClassIsATypeOf( + name_space=TESTING, + class_id="TEST_ANNOTATION", + range_name_space=PROV_S, + range_id="ENTITY", + ), + ] + + create_property_with_cardinality_and_range( + namespace=TESTING, + class_id="TEST_ANNOTATION", + property_id="annotatedValue", + range=OnlyValuesOfType( + type_namespace=TESTING, + type_class="TEST_ANNOTATION_VALUE", + ), + cardinality=Unconstrained(), + ) + + create_property_with_cardinality_and_range( + namespace=TESTING, + class_id="TEST_ANNOTATION", + property_id="annotatedResult", + range=OnlyValuesOfType( + type_namespace=TESTING, + type_class="TEST_RESULT", + ), + cardinality=Unconstrained(), + ) + + [ + CreateClass(name_space=TESTING, class_id="TEST_ANNOTATION_VALUE"), + AddClassIsATypeOf( + name_space=TESTING, + class_id="TEST_ANNOTATION_VALUE", + range_name_space=PROV_S, + range_id="THING", + ), + # TODO: OneOf + # TODO? Instance + ], +) diff --git a/migration/rack/commits/commitd497287426ac99acffbd51858ebf4722af06dae2.py b/migration/rack/commits/commitd497287426ac99acffbd51858ebf4722af06dae2.py new file mode 100644 index 00000000..6a5c521c --- /dev/null +++ b/migration/rack/commits/commitd497287426ac99acffbd51858ebf4722af06dae2.py @@ -0,0 +1,19 @@ +# Copyright (c) 2023, Galois, Inc. +# +# All Rights Reserved +# +# This material is based upon work supported by the Defense Advanced Research +# Projects Agency (DARPA) under Contract No. FA8750-20-C-0203. +# +# Any opinions, findings and conclusions or recommendations expressed in this +# material are those of the author(s) and do not necessarily reflect the views +# of the Defense Advanced Research Projects Agency (DARPA). + +from ontology_changes import Commit + +commit = Commit( + number="d497287426ac99acffbd51858ebf4722af06dae2", + changes=[ + # Nothing + ], +) diff --git a/migration/rack/commits/commitda9c143c53933d7eeb51f19c3ddc4ccf5fda95a8.py b/migration/rack/commits/commitda9c143c53933d7eeb51f19c3ddc4ccf5fda95a8.py new file mode 100644 index 00000000..dc1bbc13 --- /dev/null +++ b/migration/rack/commits/commitda9c143c53933d7eeb51f19c3ddc4ccf5fda95a8.py @@ -0,0 +1,19 @@ +# Copyright (c) 2023, Galois, Inc. +# +# All Rights Reserved +# +# This material is based upon work supported by the Defense Advanced Research +# Projects Agency (DARPA) under Contract No. FA8750-20-C-0203. +# +# Any opinions, findings and conclusions or recommendations expressed in this +# material are those of the author(s) and do not necessarily reflect the views +# of the Defense Advanced Research Projects Agency (DARPA). + +from ontology_changes import Commit + +commit = Commit( + number="da9c143c53933d7eeb51f19c3ddc4ccf5fda95a8", + changes=[ + # Nothing + ], +) diff --git a/migration/rack/commits/commite454889c706f02818f4badc3360a3c068fa014a0.py b/migration/rack/commits/commite454889c706f02818f4badc3360a3c068fa014a0.py new file mode 100644 index 00000000..387581f1 --- /dev/null +++ b/migration/rack/commits/commite454889c706f02818f4badc3360a3c068fa014a0.py @@ -0,0 +1,890 @@ +# Copyright (c) 2023, Galois, Inc. +# +# All Rights Reserved +# +# This material is based upon work supported by the Defense Advanced Research +# Projects Agency (DARPA) under Contract No. FA8750-20-C-0203. +# +# Any opinions, findings and conclusions or recommendations expressed in this +# material are those of the author(s) and do not necessarily reflect the views +# of the Defense Advanced Research Projects Agency (DARPA). + +from migration_helpers.create_class import create_class_with_type_of +from migration_helpers.create_property import create_property_with_cardinality_and_range +from migration_helpers.relocate_class_and_properties import ( + relocate_class_and_properties, +) +from ontology_changes import ( + AddClassIsATypeOf, + AddPropertyIsATypeOf, + AddRangeRestriction, + Commit, + CreateClass, + RenameClass, +) +from ontology_changes.cardinality import AtMost, SingleValue, Unconstrained +from rack.namespaces.rack_ontology import ( + HARDWARE, + HAZARD, + PROCESS, + PROV_S, + REQUIREMENTS, + SAFETY_SECURITY, + SECURITY, + SOFTWARE, + SYSTEM, +) +from rack.namespaces.xml_schema import XMLSCHEMA +from ontology_changes.range_restriction import OnlyValuesOfType + +commit = Commit( + number="e454889c706f02818f4badc3360a3c068fa014a0", + changes=[ + # REQUIREMENTS.sadl + CreateClass( + name_space=REQUIREMENTS, + class_id="REQUIREMENT_SET", + ), + AddClassIsATypeOf( + name_space=REQUIREMENTS, + class_id="REQUIREMENT_SET", + range_name_space=PROV_S, + range_id="COLLECTION", + ), + AddRangeRestriction( + domain_name_space=REQUIREMENTS, + domain_class="REQUIREMENT_SET", + prop_name_space=PROV_S, + prop_name="content", + restriction=OnlyValuesOfType( + type_namespace=REQUIREMENTS, + type_class="REQUIREMENT", + ), + ), + ] + + create_property_with_cardinality_and_range( + namespace=REQUIREMENTS, + class_id="REQUIREMENT_SET", + property_id="specifies", + range=OnlyValuesOfType( + type_namespace=PROV_S, + type_class="ENTITY", + ), + cardinality=Unconstrained(), + ) + # SAFETY_SECURITY.sadl + # NOTE: The following were moved from SECURITY.sadl, see further below: + # - THREAT + # - THREAT_IDENTIFICATION + # - SECURITY_LABEL + # - CONTROL + # - CONTROLSET + + create_class_with_type_of( + namespace=SAFETY_SECURITY, + class_id="PORT", + type_of_namespace=SAFETY_SECURITY, + type_of_class="PORT_DIRECTION", + ) + + create_class_with_type_of( + namespace=SAFETY_SECURITY, + class_id="PORT_DIRECTION", + type_of_namespace=PROV_S, + type_of_class="THING", + ) + + create_class_with_type_of( + namespace=SAFETY_SECURITY, + class_id="GUARANTEE", + type_of_namespace=PROCESS, + type_of_class="PROPERTY", + ) + + create_property_with_cardinality_and_range( + namespace=SAFETY_SECURITY, + class_id="PORT", + property_id="direction", + range=OnlyValuesOfType( + type_namespace=SAFETY_SECURITY, + type_class="PORT_DIRECTION", + ), + cardinality=SingleValue(), + ) + + create_class_with_type_of( + namespace=SAFETY_SECURITY, + class_id="COMPONENT_GUARANTEE", + type_of_namespace=SAFETY_SECURITY, + type_of_class="GUARANTEE", + ) + + create_class_with_type_of( + namespace=SAFETY_SECURITY, + class_id="INTERFACE_GUARANTEE", + type_of_namespace=SAFETY_SECURITY, + type_of_class="GUARANTEE", + ) + + create_class_with_type_of( + namespace=SAFETY_SECURITY, + class_id="GUARANTEE_TYPE", + type_of_namespace=PROV_S, + type_of_class="THING", + ) + + create_class_with_type_of( + namespace=SAFETY_SECURITY, + class_id="PEDIGREE", + type_of_namespace=PROV_S, + type_of_class="THING", + ) + + create_class_with_type_of( + namespace=SAFETY_SECURITY, + class_id="TRUSTWORTHINESS", + type_of_namespace=PROV_S, + type_of_class="THING", + ) + + create_class_with_type_of( + namespace=SAFETY_SECURITY, + class_id="INTERFACE_TYPE", + type_of_namespace=PROV_S, + type_of_class="THING", + ) + + create_class_with_type_of( + namespace=SAFETY_SECURITY, + class_id="HWCOMPONENT_SS", + type_of_namespace=HARDWARE, + type_of_class="HWCOMPONENT", + ) + + create_property_with_cardinality_and_range( + namespace=SAFETY_SECURITY, + class_id="HWCOMPONENT_SS", + property_id="port", + range=OnlyValuesOfType( + type_namespace=SAFETY_SECURITY, + type_class="PORT", + ), + cardinality=Unconstrained(), + ) + + create_property_with_cardinality_and_range( + namespace=SAFETY_SECURITY, + class_id="HWCOMPONENT_SS", + property_id="partOf", + range=OnlyValuesOfType( + type_namespace=SAFETY_SECURITY, + type_class="HWCOMPONENT_SS", + ), + cardinality=Unconstrained(), + ) + + create_property_with_cardinality_and_range( + namespace=SAFETY_SECURITY, + class_id="HWCOMPONENT_SS", + property_id="hosts", + range=OnlyValuesOfType( + type_namespace=SOFTWARE, + type_class="SWCOMPONENT", + ), + cardinality=Unconstrained(), + ) + + create_property_with_cardinality_and_range( + namespace=SAFETY_SECURITY, + class_id="HWCOMPONENT_SS", + property_id="pedigree", + range=OnlyValuesOfType( + type_namespace=SAFETY_SECURITY, + type_class="PEDIGREE", + ), + cardinality=AtMost(1), + ) + + create_property_with_cardinality_and_range( + namespace=SAFETY_SECURITY, + class_id="HWCOMPONENT_SS", + property_id="trustworthiness", + range=OnlyValuesOfType( + type_namespace=SAFETY_SECURITY, + type_class="TRUSTWORTHINESS", + ), + cardinality=AtMost(1), + ) + + create_class_with_type_of( + namespace=SAFETY_SECURITY, + class_id="SWCOMPONENT_SS", + type_of_namespace=SOFTWARE, + type_of_class="SWCOMPONENT", + ) + + create_property_with_cardinality_and_range( + namespace=SAFETY_SECURITY, + class_id="SWCOMPONENT_SS", + property_id="instantiates", + range=OnlyValuesOfType( + type_namespace=SYSTEM, + type_class="FUNCTION", + ), + cardinality=Unconstrained(), + ) + + create_property_with_cardinality_and_range( + namespace=SAFETY_SECURITY, + class_id="SWCOMPONENT_SS", + property_id="partOf", + range=OnlyValuesOfType( + type_namespace=SAFETY_SECURITY, + type_class="SWCOMPONENT_SS", + ), + cardinality=Unconstrained(), + ) + + create_property_with_cardinality_and_range( + namespace=SAFETY_SECURITY, + class_id="SWCOMPONENT_SS", + property_id="pedigree", + range=OnlyValuesOfType( + type_namespace=SAFETY_SECURITY, + type_class="PEDIGREE", + ), + cardinality=AtMost(1), + ) + + create_property_with_cardinality_and_range( + namespace=SAFETY_SECURITY, + class_id="SWCOMPONENT_SS", + property_id="trustworthiness", + range=OnlyValuesOfType( + type_namespace=SAFETY_SECURITY, + type_class="TRUSTWORTHINESS", + ), + cardinality=AtMost(1), + ) + + create_class_with_type_of( + namespace=SAFETY_SECURITY, + class_id="PHYSICAL_INTERFACE", + type_of_namespace=PROV_S, + type_of_class="ENTITY", + ) + + create_property_with_cardinality_and_range( + namespace=SAFETY_SECURITY, + class_id="PHYSICAL_INTERFACE", + property_id="srcPort", + range=OnlyValuesOfType( + type_namespace=SAFETY_SECURITY, + type_class="PORT", + ), + cardinality=Unconstrained(), + ) + + create_property_with_cardinality_and_range( + namespace=SAFETY_SECURITY, + class_id="PHYSICAL_INTERFACE", + property_id="dstPort", + range=OnlyValuesOfType( + type_namespace=SAFETY_SECURITY, + type_class="PORT", + ), + cardinality=Unconstrained(), + ) + + create_property_with_cardinality_and_range( + namespace=SAFETY_SECURITY, + class_id="PHYSICAL_INTERFACE", + property_id="protocol", + range=OnlyValuesOfType( + type_namespace=PROV_S, + type_class="ENTITY", + ), + cardinality=Unconstrained(), + ) + + create_property_with_cardinality_and_range( + namespace=SAFETY_SECURITY, + class_id="PHYSICAL_INTERFACE", + property_id="pedigree", + range=OnlyValuesOfType( + type_namespace=SAFETY_SECURITY, + type_class="PEDIGREE", + ), + cardinality=AtMost(1), + ) + + create_property_with_cardinality_and_range( + namespace=SAFETY_SECURITY, + class_id="PHYSICAL_INTERFACE", + property_id="trustworthiness", + range=OnlyValuesOfType( + type_namespace=SAFETY_SECURITY, + type_class="TRUSTWORTHINESS", + ), + cardinality=AtMost(1), + ) + + create_class_with_type_of( + namespace=SAFETY_SECURITY, + class_id="VIRTUAL_CHANNEL", + type_of_namespace=SYSTEM, + type_of_class="INTERFACE", + ) + + create_property_with_cardinality_and_range( + namespace=SAFETY_SECURITY, + class_id="VIRTUAL_CHANNEL", + property_id="utilizes", + range=OnlyValuesOfType( + type_namespace=SAFETY_SECURITY, + type_class="PHYSICAL_INTERFACE", + ), + cardinality=Unconstrained(), + ) + + create_class_with_type_of( + namespace=SAFETY_SECURITY, + class_id="DATA_FLOW", + type_of_namespace=PROV_S, + type_of_class="ENTITY", + ) + + create_property_with_cardinality_and_range( + namespace=SAFETY_SECURITY, + class_id="DATA_FLOW", + property_id="communicatesOver", + range=OnlyValuesOfType( + type_namespace=SAFETY_SECURITY, + type_class="VIRTUAL_CHANNEL", + ), + cardinality=SingleValue(), + ) + + create_property_with_cardinality_and_range( + namespace=SAFETY_SECURITY, + class_id="DATA_FLOW", + property_id="source", + range=OnlyValuesOfType( + type_namespace=SYSTEM, + type_class="FUNCTION", + ), + cardinality=Unconstrained(), + ) + + create_property_with_cardinality_and_range( + namespace=SAFETY_SECURITY, + class_id="DATA_FLOW", + property_id="destination", + range=OnlyValuesOfType( + type_namespace=SYSTEM, + type_class="FUNCTION", + ), + cardinality=Unconstrained(), + ) + + create_class_with_type_of( + namespace=SAFETY_SECURITY, + class_id="SAFETY_DESIGN_ASSURANCE_LEVEL", + type_of_namespace=PROV_S, + type_of_class="THING", + ) + + create_class_with_type_of( + namespace=SAFETY_SECURITY, + class_id="SECURITY_ASSURANCE_LEVEL", + type_of_namespace=PROV_S, + type_of_class="THING", + ) + + create_class_with_type_of( + namespace=SAFETY_SECURITY, + class_id="SECURITY_ENCLAVE", + type_of_namespace=PROV_S, + type_of_class="COLLECTION", + ) + + [ + AddRangeRestriction( + domain_name_space=SAFETY_SECURITY, + domain_class="SECURITY_ENCLAVE", + prop_name_space=PROV_S, + prop_name="content", + # FIXME: need disjunctions + restriction=OnlyValuesOfType( + type_namespace=SAFETY_SECURITY, # or others... + type_class="{HWCOMPONENT or PHYSICAL_INTERFACE or SWCOMPONENT or PORT}", + ), + ) + ] + + create_property_with_cardinality_and_range( + namespace=SAFETY_SECURITY, + class_id="SECURITY_ENCLAVE", + property_id="dal", + range=OnlyValuesOfType( + type_namespace=SAFETY_SECURITY, + type_class="SAFETY_DESIGN_ASSURANCE_LEVEL", + ), + cardinality=AtMost(1), + ) + + create_property_with_cardinality_and_range( + namespace=SAFETY_SECURITY, + class_id="SECURITY_ENCLAVE", + property_id="sal", + range=OnlyValuesOfType( + type_namespace=SAFETY_SECURITY, + type_class="SECURITY_ASSURANCE_LEVEL", + ), + cardinality=AtMost(1), + ) + + create_class_with_type_of( + namespace=SAFETY_SECURITY, + class_id="SECURITY_PERIMETER", + type_of_namespace=PROV_S, + type_of_class="COLLECTION", + ) + + create_class_with_type_of( + namespace=SAFETY_SECURITY, + class_id="VULNERABILITY", + type_of_namespace=PROV_S, + type_of_class="ENTITY", + ) + + create_property_with_cardinality_and_range( + namespace=SAFETY_SECURITY, + class_id="VULNERABILITY", + property_id="mitigatedBy", + range=OnlyValuesOfType( + type_namespace=SAFETY_SECURITY, # or PROCESS + # TODO: support disjunctions + type_class="{CONTROL or PROPERTY}", + ), + cardinality=Unconstrained(), + ) + + [ + AddPropertyIsATypeOf( + name_space=SAFETY_SECURITY, + class_id="VULNERABILITY", + property_id="mitigatedBy", + range_name_space=PROV_S, + range="wasImpactedBy", + ) + ] + + create_property_with_cardinality_and_range( + namespace=SAFETY_SECURITY, + class_id="VULNERABILITY", + property_id="enhancedBy", + range=OnlyValuesOfType( + type_namespace=SAFETY_SECURITY, # or PROCESS + # TODO: support disjunctions + type_class="{CONTROL or PROPERTY}", + ), + cardinality=Unconstrained(), + ) + + [ + AddPropertyIsATypeOf( + name_space=SAFETY_SECURITY, + class_id="VULNERABILITY", + property_id="enhancedBy", + range_name_space=PROV_S, + range="wasImpactedBy", + ) + ] + + create_property_with_cardinality_and_range( + namespace=SAFETY_SECURITY, + class_id="VULNERABILITY", + property_id="recoveredBy", + range=OnlyValuesOfType( + type_namespace=SAFETY_SECURITY, # or PROCESS + # TODO: support disjunctions + type_class="{CONTROL or PROPERTY}", + ), + cardinality=Unconstrained(), + ) + + [ + AddPropertyIsATypeOf( + name_space=SAFETY_SECURITY, + class_id="VULNERABILITY", + property_id="recoveredBy", + range_name_space=PROV_S, + range="wasImpactedBy", + ) + ] + + create_property_with_cardinality_and_range( + namespace=SAFETY_SECURITY, + class_id="VULNERABILITY", + property_id="vulnerabilityTouchPoints", + range=OnlyValuesOfType( + type_namespace=SAFETY_SECURITY, + type_class="ARCHITECTURE_TOUCHPOINTS", + ), + cardinality=Unconstrained(), + ) + + create_property_with_cardinality_and_range( + namespace=SAFETY_SECURITY, + class_id="VULNERABILITY", + property_id="cweReference", + range=OnlyValuesOfType( + type_namespace=PROV_S, + type_class="ENTITY", + ), + cardinality=Unconstrained(), + ) + + [ + AddPropertyIsATypeOf( + name_space=SAFETY_SECURITY, + class_id="VULNERABILITY", + property_id="cweReference", + range_name_space=PROV_S, + range="wasImpactedBy", + ) + ] + + create_class_with_type_of( + namespace=SAFETY_SECURITY, + class_id="ATTACKER", + type_of_namespace=PROV_S, + type_of_class="AGENT", + ) + + create_class_with_type_of( + namespace=SAFETY_SECURITY, + class_id="ATTACK", + type_of_namespace=PROV_S, + type_of_class="ACTIVITY", + ) + + create_property_with_cardinality_and_range( + namespace=SAFETY_SECURITY, + class_id="VULNERABILITY", + property_id="attacker", + range=OnlyValuesOfType( + type_namespace=SAFETY_SECURITY, + type_class="ATTACKER", + ), + cardinality=Unconstrained(), + ) + + [ + AddPropertyIsATypeOf( + name_space=SAFETY_SECURITY, + class_id="VULNERABILITY", + property_id="attacker", + range_name_space=PROV_S, + range="wasAssociatedWith", + ) + ] + + create_class_with_type_of( + namespace=SAFETY_SECURITY, + class_id="ATTACK_ACCESS_VECTORS", + type_of_namespace=PROV_S, + type_of_class="ENTITY", + ) + + [ + AddRangeRestriction( + domain_name_space=SAFETY_SECURITY, + domain_class="ATTACK_ACCESS_VECTORS", + prop_name_space=PROV_S, + prop_name="wasGeneratedBy", + restriction=OnlyValuesOfType( + type_namespace=SAFETY_SECURITY, + type_class="ATTACK", + ), + ) + ] + + create_property_with_cardinality_and_range( + namespace=SAFETY_SECURITY, + class_id="ATTACK_ACCESS_VECTORS", + property_id="attackTouchPoints", + range=OnlyValuesOfType( + type_namespace=SAFETY_SECURITY, + type_class="ATTACK", + ), + cardinality=Unconstrained(), + ) + + create_property_with_cardinality_and_range( + namespace=SAFETY_SECURITY, + class_id="ATTACK_ACCESS_VECTORS", + property_id="capecReference", + range=OnlyValuesOfType( + type_namespace=PROV_S, + type_class="ENTITY", + ), + cardinality=Unconstrained(), + ) + + [ + AddPropertyIsATypeOf( + name_space=SAFETY_SECURITY, + class_id="ATTACK_ACCESS_VECTORS", + property_id="capecReference", + range_name_space=PROV_S, + range="wasImpactedBy", + ) + ] + + create_class_with_type_of( + namespace=SAFETY_SECURITY, + class_id="ARCHITECTURE_TOUCHPOINTS", + type_of_namespace=PROV_S, + type_of_class="COLLECTION", + ) + + create_property_with_cardinality_and_range( + namespace=SAFETY_SECURITY, + class_id="CONTROL", + property_id="mitigatesHazard", + range=OnlyValuesOfType( + type_namespace=HAZARD, + type_class="HAZARD_CONDITION", + ), + cardinality=Unconstrained(), + ) + + create_property_with_cardinality_and_range( + namespace=SAFETY_SECURITY, + class_id="CONTROL", + property_id="enhancesHazard", + range=OnlyValuesOfType( + type_namespace=HAZARD, + type_class="HAZARD_CONDITION", + ), + cardinality=Unconstrained(), + ) + + create_property_with_cardinality_and_range( + namespace=SAFETY_SECURITY, + class_id="CONTROL", + property_id="location", + range=OnlyValuesOfType( + type_namespace=SAFETY_SECURITY, + type_class="ARCHITECTURE_TOUCHPOINTS", + ), + cardinality=Unconstrained(), + ) + + create_property_with_cardinality_and_range( + namespace=SAFETY_SECURITY, + class_id="CONTROL", + property_id="nist_800_53Reference", + range=OnlyValuesOfType( + type_namespace=PROV_S, + type_class="ENTITY", + ), + cardinality=Unconstrained(), + ) + + [ + AddPropertyIsATypeOf( + name_space=SAFETY_SECURITY, + class_id="CONTROL", + property_id="nist_800_53Reference", + range_name_space=PROV_S, + range="wasImpactedBy", + ) + ] + + create_class_with_type_of( + namespace=SAFETY_SECURITY, + class_id="LOSS_CATEGORY", + type_of_namespace=SAFETY_SECURITY, + type_of_class="SECURITY_LABEL", + ) + + create_class_with_type_of( + namespace=SAFETY_SECURITY, + class_id="HAZARD_CONDITION", + type_of_namespace=HAZARD, + type_of_class="HAZARD", + ) + + create_property_with_cardinality_and_range( + namespace=SAFETY_SECURITY, + class_id="HAZARD_CONDITION", + property_id="mitigatesControl", + range=OnlyValuesOfType( + type_namespace=SAFETY_SECURITY, + type_class="CONTROL", + ), + cardinality=Unconstrained(), + ) + + create_property_with_cardinality_and_range( + namespace=SAFETY_SECURITY, + class_id="HAZARD_CONDITION", + property_id="enhancesControl", + range=OnlyValuesOfType( + type_namespace=SAFETY_SECURITY, + type_class="CONTROL", + ), + cardinality=Unconstrained(), + ) + + create_property_with_cardinality_and_range( + namespace=SAFETY_SECURITY, + class_id="HAZARD_CONDITION", + property_id="lossCategory", + range=OnlyValuesOfType( + type_namespace=SAFETY_SECURITY, + type_class="LOSS_CATEGORY", + ), + cardinality=Unconstrained(), + ) + + create_property_with_cardinality_and_range( + namespace=SAFETY_SECURITY, + class_id="HAZARD_CONDITION", + property_id="triggers", + range=OnlyValuesOfType( + type_namespace=SAFETY_SECURITY, + type_class="SAFETY_ACCIDENT", + ), + cardinality=Unconstrained(), + ) + + create_class_with_type_of( + namespace=SAFETY_SECURITY, + class_id="EXPLOITATION", + type_of_namespace=PROV_S, + type_of_class="ENTITY", + ) + + create_property_with_cardinality_and_range( + namespace=SAFETY_SECURITY, + class_id="EXPLOITATION", + property_id="uses", + range=OnlyValuesOfType( + type_namespace=SAFETY_SECURITY, + type_class="ATTACK_ACCESS_VECTORS", + ), + cardinality=Unconstrained(), + ) + + [ + AddPropertyIsATypeOf( + name_space=SAFETY_SECURITY, + class_id="EXPLOITATION", + property_id="uses", + range_name_space=PROV_S, + range="wasImpactedBy", + ) + ] + + create_property_with_cardinality_and_range( + namespace=SAFETY_SECURITY, + class_id="EXPLOITATION", + property_id="exploits", + range=OnlyValuesOfType( + type_namespace=SAFETY_SECURITY, + type_class="VULNERABILITY", + ), + cardinality=Unconstrained(), + ) + + [ + AddPropertyIsATypeOf( + name_space=SAFETY_SECURITY, + class_id="EXPLOITATION", + property_id="exploits", + range_name_space=PROV_S, + range="wasImpactedBy", + ) + ] + + create_class_with_type_of( + namespace=SAFETY_SECURITY, + class_id="THREAT_CONDITION", + type_of_namespace=SAFETY_SECURITY, + type_of_class="THREAT", + ) + + create_property_with_cardinality_and_range( + namespace=SAFETY_SECURITY, + class_id="THREAT_CONDITION", + property_id="source", + range=OnlyValuesOfType( + type_namespace=SAFETY_SECURITY, + type_class="EXPLOITATION", + ), + cardinality=Unconstrained(), + ) + + create_property_with_cardinality_and_range( + namespace=SAFETY_SECURITY, + class_id="THREAT_CONDITION", + property_id="securityLabel", + range=OnlyValuesOfType( + type_namespace=SAFETY_SECURITY, + type_class="SECURITY_LABEL", + ), + cardinality=Unconstrained(), + ) + + create_property_with_cardinality_and_range( + namespace=SAFETY_SECURITY, + class_id="THREAT_CONDITION", + property_id="triggers", + range=OnlyValuesOfType( + type_namespace=SAFETY_SECURITY, + type_class="SECURITY_VIOLATION", + ), + cardinality=Unconstrained(), + ) + + create_class_with_type_of( + namespace=SAFETY_SECURITY, + class_id="SAFETY_REQUIREMENT", + type_of_namespace=REQUIREMENTS, + type_of_class="REQUIREMENT", + ) + + create_class_with_type_of( + namespace=SAFETY_SECURITY, + class_id="SECURITY_REQUIREMENT", + type_of_namespace=REQUIREMENTS, + type_of_class="REQUIREMENT", + ) + + create_class_with_type_of( + namespace=SAFETY_SECURITY, + class_id="SAFETY_REQUIREMENT_SET", + type_of_namespace=REQUIREMENTS, + type_of_class="REQUIREMENT_SET", + ) + + [ + AddRangeRestriction( + domain_name_space=SAFETY_SECURITY, + domain_class="SAFETY_REQUIREMENT_SET", + prop_name_space=PROV_S, + prop_name="content", + restriction=OnlyValuesOfType( + type_namespace=SAFETY_SECURITY, + type_class="SAFETY_REQUIREMENT", + ), + ) + ] + + create_class_with_type_of( + namespace=SAFETY_SECURITY, + class_id="SECURITY_REQUIREMENT_SET", + type_of_namespace=REQUIREMENTS, + type_of_class="REQUIREMENT_SET", + ) + + [ + AddRangeRestriction( + domain_name_space=SAFETY_SECURITY, + domain_class="SECURITY_REQUIREMENT_SET", + prop_name_space=PROV_S, + prop_name="content", + restriction=OnlyValuesOfType( + type_namespace=SAFETY_SECURITY, + type_class="SECURITY_REQUIREMENT", + ), + ) + ] + + create_class_with_type_of( + namespace=SAFETY_SECURITY, + class_id="RISK_EVENT", + type_of_namespace=PROV_S, + type_of_class="ENTITY", + ) + + create_property_with_cardinality_and_range( + namespace=SAFETY_SECURITY, + class_id="RISK_EVENT", + property_id="severity", + range=OnlyValuesOfType( + type_namespace=XMLSCHEMA, + type_class="float", + ), + cardinality=AtMost(1), + ) + + create_property_with_cardinality_and_range( + namespace=SAFETY_SECURITY, + class_id="RISK_EVENT", + property_id="probability", + range=OnlyValuesOfType( + type_namespace=XMLSCHEMA, + type_class="float", + ), + cardinality=AtMost(1), + ) + + create_class_with_type_of( + namespace=SAFETY_SECURITY, + class_id="SECURITY_VIOLATION", + type_of_namespace=SAFETY_SECURITY, + type_of_class="RISK_EVENT", + ) + + create_class_with_type_of( + namespace=SAFETY_SECURITY, + class_id="SAFETY_ACCIDENT", + type_of_namespace=SAFETY_SECURITY, + type_of_class="RISK_EVENT", + ) + # SECURITY.sadl + + relocate_class_and_properties( + from_namespace=SECURITY, + to_namespace=SAFETY_SECURITY, + class_id="THREAT", + properties=["source", "identified", "effect", "severity", "likelihood"], + ) + + relocate_class_and_properties( + from_namespace=SECURITY, + to_namespace=SAFETY_SECURITY, + class_id="THREAT_IDENTIFICATION", + properties=["author"], + ) + + relocate_class_and_properties( + from_namespace=SECURITY, + to_namespace=SAFETY_SECURITY, + class_id="SECURITY_LABEL", + properties=[], + ) + + relocate_class_and_properties( + from_namespace=SECURITY, + to_namespace=SAFETY_SECURITY, + class_id="CONTROL", + properties=[], + ) + + relocate_class_and_properties( + from_namespace=SECURITY, + to_namespace=SAFETY_SECURITY, + class_id="CONTROLSET", + properties=["content", "mitigates"], + ), +) diff --git a/migration/rack/commits/commite485aa4268867521cc8d6f9c3a0f6fd2aef4311b.py b/migration/rack/commits/commite485aa4268867521cc8d6f9c3a0f6fd2aef4311b.py new file mode 100644 index 00000000..edc58ab3 --- /dev/null +++ b/migration/rack/commits/commite485aa4268867521cc8d6f9c3a0f6fd2aef4311b.py @@ -0,0 +1,20 @@ +# Copyright (c) 2023, Galois, Inc. +# +# All Rights Reserved +# +# This material is based upon work supported by the Defense Advanced Research +# Projects Agency (DARPA) under Contract No. FA8750-20-C-0203. +# +# Any opinions, findings and conclusions or recommendations expressed in this +# material are those of the author(s) and do not necessarily reflect the views +# of the Defense Advanced Research Projects Agency (DARPA). + +from ontology_changes import Commit + +commit = Commit( + number="e485aa4268867521cc8d6f9c3a0f6fd2aef4311b", + tag="v12.0", + changes=[ + # no ontology change, just here for the tag + ], +) diff --git a/migration/rack/namespaces/rack_ontology.py b/migration/rack/namespaces/rack_ontology.py index b2f43da2..f11bfbaa 100644 --- a/migration/rack/namespaces/rack_ontology.py +++ b/migration/rack/namespaces/rack_ontology.py @@ -31,6 +31,8 @@ def rack(name_space: str) -> NameSpace: REQUIREMENTS = rack("REQUIREMENTS") RESOLUTIONS = rack("RESOLUTIONS") REVIEW = rack("REVIEW") +SAFETY_SECURITY = rack("SAFETY_SECURITY") +SECURITY = rack("SECURITY") SOFTWARE = rack("SOFTWARE") SYSTEM = rack("SYSTEM") TESTING = rack("TESTING") diff --git a/migration/rack_migrate/rack_migrate b/migration/rack_migrate/rack_migrate index 2e3915cc..42074ff8 100644 --- a/migration/rack_migrate/rack_migrate +++ b/migration/rack_migrate/rack_migrate @@ -151,7 +151,6 @@ commits_to_consider_in_git_log_order = reversed( commits_to_consider_in_chronological_order ) - if len(commits_to_consider_in_chronological_order) == 0: logger.error("We did not find any commits in the range you specified, aborting.") sys.exit(1)