Skip to content

Commit

Permalink
Merge branch 'main' into add-embedded-object-property
Browse files Browse the repository at this point in the history
  • Loading branch information
rpiazza authored Apr 12, 2024
2 parents 5046a40 + cc40071 commit b0e628f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 68 deletions.
12 changes: 6 additions & 6 deletions how-to-contribute.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ To contribute an extension implementation:

- Create a subdirectory named after your extension.

- The naming convention is: ``<STIX object type name>-extension-<extension definition id's UUID first grouping>``. For multiple extension definitions which are related, use the "root" STIX object type name.
- The naming convention is: ``<STIX object type name>-extension-<extension definition id's UUID first three digits>``. For multiple extension definitions which are related, use the "root" STIX object type name.

For example: incident-extension-ef765651
For example: incident-extension-ef7
- Create a buildable Python project in your subdirectory:

- The project name should also reflect your extension ``python-stix2-<directory name from previous step>``

For example: python-stix2-incident-extension-ef765651
For example: python-stix2-incident-extension-ef7
- Recommended style is `pyproject.toml <https://packaging.python.org/en/latest/guides/writing-pyproject-toml>`_,
e.g. using setuptools build backend with a `src-layout <https://setuptools.pypa.io/en/latest/userguide/package_discovery.html#src-layout>`_.
- Unit tests should be included
- The code should work on the same versions of Python as the stix2 library
it will integrate with. (suggests we really should have CI enabled,
since few will have all those versions of Python installed to test with.)
- (Should examples be included? Must they be jupyter notebooks?)
it will integrate with.
- In the future, CI will be enabled to run the tests.
- Examples should be included in an examples directory. Some examples might found in the `common object repository <https://github.com/oasis-open/cti-stix-common-objects/tree/main/extension-definition-specifications>`_.
- Make a pull request to merge your work into this repository.
2 changes: 1 addition & 1 deletion pap-marking-definition-f8d/src/pap/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# ruff: noqa: F401
from .pap import PAPExtension, PAPMarkingDefinitionError, PAP_AMBER, PAP_GREEN, PAP_RED, PAP_WHITE
from .pap import PAPExtension, PAPMarkingDefinitionError
88 changes: 28 additions & 60 deletions pap-marking-definition-f8d/src/pap/pap.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,23 @@
"PAP:GREEN",
"PAP:WHITE",
"PAP:RED",
"PAP:AMBER"
"PAP:AMBER",
"PAP:CLEAR"
]

PAP_COLORS = [
"green",
"white",
"red",
"amber"
"amber",
"clear"
]

PAP_AMBER = {
'id': 'marking-definition--60f8932b-e51e-4458-b265-a2e8be9a80ab',
'created': '2022-10-02T00:00:00.000Z',
'name': 'PAP:AMBER',
'extensions': {
'id':'marking-definition--60f8932b-e51e-4458-b265-a2e8be9a80ab',
'created':"2022-10-02T00:00:00.000Z",
'name':"PAP:AMBER",
'extensions':{
PAP_MARKING_EXTENSION_ID:{
'pap':'amber'
}
Expand All @@ -43,8 +45,8 @@ class PAPExtension:
class PAPMarkingDefinitionError(ObjectConfigurationError):

def __str__(self):
return "The only instances of PAP marking definitions permitted are those defined in the PAP Extension Specification"

msg = "The only instances of PAP marking definitions permitted are those defined in the PAP Extension Specification"
return msg.format(self)

class PAPMarkingDefinition(MarkingDefinition):

Expand All @@ -55,67 +57,33 @@ def __init__(self, **kwargs):
])

def __eq__(self, other):
properties_to_compare = ['id', 'created', 'name']
properties_to_compare = ['id', 'name']
for field in properties_to_compare:
if self[field] != other[field]:
return False

if isinstance(other, dict):
if self['created'] != stix2.utils.parse_into_datetime(other['created']):
return False
else:
if self['created'] != other['created']:
return False

if self['extensions'][PAP_MARKING_EXTENSION_ID]['pap'] != other['extensions'][PAP_MARKING_EXTENSION_ID]['pap']:
return False

return True

def _check_object_constraints(self):
super(PAPMarkingDefinition, self)._check_object_constraints()
check_pap_marking(self)


PAP_AMBER = PAPMarkingDefinition(
id='marking-definition--60f8932b-e51e-4458-b265-a2e8be9a80ab',
created="2022-10-02T00:00:00.000Z",
name="PAP:AMBER",
extensions={
PAP_MARKING_EXTENSION_ID:{
'pap':'amber'
}
}
)

PAP_GREEN = PAPMarkingDefinition(
id='marking-definition--c43594d1-4b11-4c59-93ab-1c9b14d53ce9',
created="2022-10-09T00:00:00.000Z",
name="PAP:GREEN",
extensions={
PAP_MARKING_EXTENSION_ID:{
'pap':'green'
}
}
)

PAP_RED = PAPMarkingDefinition(
id='marking-definition--740d36e5-7714-4c30-961a-3ae632ceee0e',
created="2022-10-06T00:00:00.000Z",
name="PAP:RED",
extensions={
PAP_MARKING_EXTENSION_ID:{
'pap':'red'
}
}
)

PAP_WHITE = PAPMarkingDefinition(
id='marking-definition--a3bea94c-b469-41dc-9cfe-d6e7daba7730',
created="2022-10-01T00:00:00.000Z",
name="PAP:WHITE",
extensions={
PAP_MARKING_EXTENSION_ID:{
'pap':'white'
}
}
)

pap_objects = [PAP_AMBER, PAP_GREEN, PAP_RED, PAP_WHITE, PAP_CLEAR]

def check_pap_marking(pap_marking):
pap_objects = [PAP_AMBER, PAP_GREEN, PAP_RED, PAP_WHITE]
if pap_marking not in pap_objects:
raise PAPMarkingDefinitionError
match_found = False
for pap in pap_objects:
if pap['name'] == self['name']:
match_found = True
if not self == pap:
raise PAPMarkingDefinitionError

if not match_found:
raise PAPMarkingDefinitionError
2 changes: 1 addition & 1 deletion pap-marking-definition-f8d/tests/pap/test_pap.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_bad_pap_green():
)

def test_bad_pap_red():
with pytest.raises(stix2.exceptions.InvalidValueError):
with pytest.raises(PAPMarkingDefinitionError):
PAPMarkingDefinition(
id='marking-definition--740d36e5-7714-4c30-961a-3ae632ceee0e',
created="2022-10-06T00:00:00.000Z",
Expand Down

0 comments on commit b0e628f

Please sign in to comment.