diff --git a/CHANGELOG b/CHANGELOG index 6dcfef9..5e47891 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,13 @@ CHANGELOG ========= +1.1.1 - 2019-01-11 + +* #234 Update documentation structure to better navigate between v20/v21 objects +* #232 FileSystemStore now raises an exception if you attempt to overwrite an existing file +* #236 Fix a serialization problem with the WindowsRegistryKey observable object +* #238 Fix a problem with the LanguageContent object not allowing its creation with an empty dictionary + 1.1.0 - 2018-12-11 - Most (if not all) STIX 2.1 SDOs/SROs and core objects have been implemented according to the latest CSD/WD document diff --git a/docs/api/stix2.v20.rst b/docs/api/stix2.v20.rst new file mode 100644 index 0000000..2cbb2e3 --- /dev/null +++ b/docs/api/stix2.v20.rst @@ -0,0 +1,5 @@ +v20 +========= + +.. automodule:: stix2.v20 + :members: \ No newline at end of file diff --git a/docs/api/stix2.v21.rst b/docs/api/stix2.v21.rst new file mode 100644 index 0000000..fc02330 --- /dev/null +++ b/docs/api/stix2.v21.rst @@ -0,0 +1,5 @@ +v21 +========= + +.. automodule:: stix2.v21 + :members: \ No newline at end of file diff --git a/docs/api/stix2.v20.bundle.rst b/docs/api/v20/stix2.v20.bundle.rst similarity index 100% rename from docs/api/stix2.v20.bundle.rst rename to docs/api/v20/stix2.v20.bundle.rst diff --git a/docs/api/stix2.v20.common.rst b/docs/api/v20/stix2.v20.common.rst similarity index 81% rename from docs/api/stix2.v20.common.rst rename to docs/api/v20/stix2.v20.common.rst index 8cec059..0c7a296 100644 --- a/docs/api/stix2.v20.common.rst +++ b/docs/api/v20/stix2.v20.common.rst @@ -2,4 +2,4 @@ common ================ .. automodule:: stix2.v20.common - :members: + :members: \ No newline at end of file diff --git a/docs/api/stix2.v20.observables.rst b/docs/api/v20/stix2.v20.observables.rst similarity index 84% rename from docs/api/stix2.v20.observables.rst rename to docs/api/v20/stix2.v20.observables.rst index 4d9803a..d31f75f 100644 --- a/docs/api/stix2.v20.observables.rst +++ b/docs/api/v20/stix2.v20.observables.rst @@ -2,4 +2,4 @@ observables ===================== .. automodule:: stix2.v20.observables - :members: + :members: \ No newline at end of file diff --git a/docs/api/stix2.v20.sdo.rst b/docs/api/v20/stix2.v20.sdo.rst similarity index 79% rename from docs/api/stix2.v20.sdo.rst rename to docs/api/v20/stix2.v20.sdo.rst index a115d5b..c4c97f8 100644 --- a/docs/api/stix2.v20.sdo.rst +++ b/docs/api/v20/stix2.v20.sdo.rst @@ -2,4 +2,4 @@ sdo ============= .. automodule:: stix2.v20.sdo - :members: + :members: \ No newline at end of file diff --git a/docs/api/stix2.v20.sro.rst b/docs/api/v20/stix2.v20.sro.rst similarity index 79% rename from docs/api/stix2.v20.sro.rst rename to docs/api/v20/stix2.v20.sro.rst index 397cf29..379ed18 100644 --- a/docs/api/stix2.v20.sro.rst +++ b/docs/api/v20/stix2.v20.sro.rst @@ -2,4 +2,4 @@ sro ============= .. automodule:: stix2.v20.sro - :members: + :members: \ No newline at end of file diff --git a/docs/api/stix2.v21.bundle.rst b/docs/api/v21/stix2.v21.bundle.rst similarity index 100% rename from docs/api/stix2.v21.bundle.rst rename to docs/api/v21/stix2.v21.bundle.rst diff --git a/docs/api/stix2.v21.common.rst b/docs/api/v21/stix2.v21.common.rst similarity index 100% rename from docs/api/stix2.v21.common.rst rename to docs/api/v21/stix2.v21.common.rst diff --git a/docs/api/stix2.v21.observables.rst b/docs/api/v21/stix2.v21.observables.rst similarity index 100% rename from docs/api/stix2.v21.observables.rst rename to docs/api/v21/stix2.v21.observables.rst diff --git a/docs/api/stix2.v21.sdo.rst b/docs/api/v21/stix2.v21.sdo.rst similarity index 100% rename from docs/api/stix2.v21.sdo.rst rename to docs/api/v21/stix2.v21.sdo.rst diff --git a/docs/api/stix2.v21.sro.rst b/docs/api/v21/stix2.v21.sro.rst similarity index 100% rename from docs/api/stix2.v21.sro.rst rename to docs/api/v21/stix2.v21.sro.rst diff --git a/setup.cfg b/setup.cfg index a1aaca9..e5e52e4 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 1.1.0 +current_version = 1.1.1 commit = True tag = True diff --git a/stix2/__init__.py b/stix2/__init__.py index 3bedec8..246ecaf 100644 --- a/stix2/__init__.py +++ b/stix2/__init__.py @@ -12,16 +12,8 @@ patterns properties utils - v20.bundle - v20.common - v20.observables - v20.sdo - v20.sro - v21.bundle - v21.common - v21.observables - v21.sdo - v21.sro + v20 + v21 workbench """ diff --git a/stix2/datastore/filesystem.py b/stix2/datastore/filesystem.py index b4f3d15..0e8bed2 100644 --- a/stix2/datastore/filesystem.py +++ b/stix2/datastore/filesystem.py @@ -1,21 +1,19 @@ """Python STIX2 FileSystem Source/Sink""" -# Temporary while we address TODO statement -from __future__ import print_function - import errno import io import json import os import re import stat -import sys import six from stix2 import v20, v21 from stix2.base import _STIXBase from stix2.core import parse -from stix2.datastore import DataSink, DataSource, DataStoreMixin +from stix2.datastore import ( + DataSink, DataSource, DataSourceError, DataStoreMixin, +) from stix2.datastore.filters import Filter, FilterSet, apply_common_filters from stix2.utils import format_datetime, get_type_from_id, is_marking @@ -544,9 +542,8 @@ class FileSystemSink(DataSink): else: stix_obj = v20.Bundle(stix_obj, allow_custom=self.allow_custom) - # TODO: Better handling of the overwriting case. if os.path.isfile(file_path): - print("Attempted to overwrite file!", file_path, file=sys.stderr) + raise DataSourceError("Attempted to overwrite file (!) at: {}".format(file_path)) else: with io.open(file_path, 'w', encoding=encoding) as f: stix_obj = stix_obj.serialize(pretty=True, encoding=encoding, ensure_ascii=False) diff --git a/stix2/test/v20/test_datastore_filesystem.py b/stix2/test/v20/test_datastore_filesystem.py index 84a3034..86846c4 100644 --- a/stix2/test/v20/test_datastore_filesystem.py +++ b/stix2/test/v20/test_datastore_filesystem.py @@ -9,6 +9,7 @@ import pytest import pytz import stix2 +from stix2.datastore import DataSourceError from stix2.datastore.filesystem import ( AuthSet, _find_search_optimizations, _get_matching_dir_entries, _timestamp2filename, @@ -420,6 +421,33 @@ def test_filesystem_sink_add_objects_list(fs_sink, fs_source): os.remove(camp7filepath) +def test_filesystem_attempt_stix_file_overwrite(fs_store): + # add python stix object + camp8 = stix2.v20.Campaign( + name="George Washington", + objective="Create an awesome country", + aliases=["Georgey"], + ) + + fs_store.add(camp8) + + camp8_r = fs_store.get(camp8.id) + assert camp8_r.id == camp8_r.id + assert camp8_r.name == camp8.name + + filepath = os.path.join( + FS_PATH, "campaign", camp8_r.id, + _timestamp2filename(camp8_r.modified) + ".json", + ) + + # Now attempt to overwrite the existing file + with pytest.raises(DataSourceError) as excinfo: + fs_store.add(camp8) + assert "Attempted to overwrite file" in str(excinfo) + + os.remove(filepath) + + def test_filesystem_sink_marking(fs_sink): marking = stix2.v20.MarkingDefinition( definition_type="tlp", diff --git a/stix2/v20/__init__.py b/stix2/v20/__init__.py index bef7d66..4d0a98f 100644 --- a/stix2/v20/__init__.py +++ b/stix2/v20/__init__.py @@ -1,4 +1,16 @@ -"""STIX 2.0 API Objects.""" +"""STIX 2.0 API Objects. + +.. autosummary:: + :toctree: v20 + + bundle + common + observables + sdo + sro + +| +""" # flake8: noqa diff --git a/stix2/v21/__init__.py b/stix2/v21/__init__.py index 4a8fe29..c1caae4 100644 --- a/stix2/v21/__init__.py +++ b/stix2/v21/__init__.py @@ -1,4 +1,16 @@ -"""STIX 2.1 API Objects.""" +"""STIX 2.1 API Objects. + +.. autosummary:: + :toctree: v21 + + bundle + common + observables + sdo + sro + +| +""" # flake8: noqa diff --git a/stix2/version.py b/stix2/version.py index 6849410..a82b376 100644 --- a/stix2/version.py +++ b/stix2/version.py @@ -1 +1 @@ -__version__ = "1.1.0" +__version__ = "1.1.1"