Commit Graph

152 Commits (d7981dce9fa24372b5f8f93f89a59be7d704bb0f)

Author SHA1 Message Date
Michael Chisholm d87718c15c Bug fixes, hackage removal, and some pre-commit stylistic
fixes.

- Fixed bugged logic in _STIXBase._check_at_least_one_property(),
and revamped the code to be simpler and clearer.

- Changed custom extension registration to auto-create an
"extension_type" property based on the attribute of that
name on the custom class, if present.

- The custom extension registration change above uncovered
what seemed like a bug in a unit test: a custom extension
was registered, but it was not given an extension type.  The
test used the extension as extension_type="property-extension";
this now causes a standard error about an extra property.  I
fixed the test to assign the custom extension the proper type.
2021-06-30 17:50:00 -04:00
Michael Chisholm c7b4840232 Code style and behavioral improvements in ExtensionsProperty:
- Changed an error message "Cannot determine extension type."
At that point in the code, we in fact have a registered
extension type and the class for it, so it didn't seem to make
any sense.  I changed it to say that an extension of that type
couldn't be created from type of value given.  Because this is
really about typing (in both the old and new code), I also
changed the exception class to TypeError.

- Changed customization behavior: unregistered
"extension-definition--" style extensions are no longer
considered custom.  Their mere presence can no longer be
considered a customization, since it doesn't fit the
criteria, and in fact the extension mechanism is supposed to
supplant the old customization system anyway.  Unregistered
extensions of other types are still considered custom.

- Fixed up unit tests according to the exception message
change.

- Added a unit test for unregistered "extension-definition--"
style extensions.
2021-06-25 22:20:02 -04:00
Chris Lenk 2528077eb0 Merge branch 'master' into dev-extensions-proposal 2021-06-13 01:48:33 -04:00
Chris Lenk 7209346f0b Improve error message for invalid reference types 2021-06-11 13:59:48 -04:00
Emmanuelle Vargas-Gonzalez 5d83d44d0e adding documentation on specific lines, typos, and a bit of extra code 2021-04-15 12:28:58 -04:00
Michael Chisholm f301bc144f Disable custom vocab enforcement. Custom values for open-vocab
properties are now always accepted and not considered
customizations (has_custom will be False).  Just commented out
the enforcement code and xfail'd the unit tests, which makes it
easy to reinstate these behaviors later.  It was decided this
is too likely to break user code, and we don't currently have
a way to disallow customizations in other places while still
allowing custom open vocab values.  Safest to always allow
custom open vocab values, for now.
2021-04-14 12:48:32 -04:00
Michael Chisholm 82148aa1ac Pre-commit stylistic fix 2021-03-31 21:27:06 -04:00
Michael Chisholm 0ddf0d2ca8 Clean up ReferenceProperty.clean(), to use new APIs which are
available after the rebase.  This simplifies the implementation.
Also made utils.to_enum() a module public function, since I
needed to use it outside that module.  Misc pre-commit stylistic
fixes.
2021-03-31 20:01:27 -04:00
Michael Chisholm c8b9eab53d Fixed some more silliness in properties.py... was it a rebase
glitch?  Something else I overlooked?  Not sure.
2021-03-31 16:49:14 -04:00
Michael Chisholm 6f60bed235 Make a minor post-rebase fix 2021-03-31 16:21:35 -04:00
Michael Chisholm a8a65599bf Add back spec_version kwarg to HashesProperty, since it was used
to check key lengths.  Added some unit tests for hash keys.
Also added a library hash support test module I'd forgotten to
add before.
2021-03-31 16:20:33 -04:00
Michael Chisholm c590de8ea5 Add proper customization enforcement for open vocabs. This adds
a new OpenVocabProperty class.  It also requires a redesign of
HashesProperty and redoes general library support for hash
algorithms.
2021-03-31 16:20:28 -04:00
Michael Chisholm 414694d8fa Add support in ReferenceProperty for hybrid object type
constraints (i.e. both generic type categories and specific
types).  Also:
- more expansion/refinement of reference property unit tests
- bugfix: SROs are in OBJ_MAP too, it's not just SDOs!  Oops...
- pre-commit stylistic fixes
2021-03-31 15:32:51 -04:00
Michael Chisholm 03c265c3a3 Add a check in ReferenceProperty constructor for an impossible
to satisfy type constraint: empty whitelist.  It would be silly
for anyone to do that, but I should check just in case I guess.
2021-03-31 15:26:11 -04:00
Michael Chisholm c7dd58ed89 Further ReferenceProperty refinements: make allow_custom=True
work when a whitelist of generic category types is used.
Disallow hybrid constraints (both generic and specific at the
same time).  Add more unit tests.
2021-03-31 15:26:09 -04:00
Michael Chisholm d2f960f2fc Initial revamp of customization enforcement and detection. 2021-03-31 15:21:55 -04:00
Emmanuelle Vargas-Gonzalez dd6b847b10 small tweaks and pre-commit changes 2021-03-31 12:44:15 -04:00
Emmanuelle Vargas-Gonzalez 9cc2e5bd3a remove backwards compatible imports, remove pretty=True from _STIXBase.__str()__, and simplify _STIXBase.__repr()__ (breaking) 2021-03-31 11:02:05 -04:00
Emmanuelle Vargas-Gonzalez 9043a9dc8e Merge branch 'master' of github.com:oasis-open/cti-python-stix2 into dev-extensions-proposal 2021-02-19 21:54:46 -05:00
Emmanuelle Vargas-Gonzalez a8b6fa2100 Merge branch 'master' of github.com:oasis-open/cti-python-stix2 into dev-extensions-proposal 2021-02-18 16:04:30 -05:00
Chris Lenk b4a0a9ea10 Remove six dependency (backwards breaking)
We've already removed Python 2 from our test harness, but this removes
all python 2 compatibility code left in.
2021-02-18 12:38:35 -05:00
Michael Chisholm f88fba6751 Change the stix2 class map structure to be keyed at the top
level with STIX versions in the same format as is used everywhere
else in the API: "X.Y", as opposed to the "vXY" format used by
the version-specific python packages.  This eliminates all of
the awkward conversion from public API format to "vXX" format.

Also a little bit of code rearranging in the registration module
to ensure that some STIX 2.1-specific checks are done whether
version 2.1 is given explicitly or is defaulted to.

In the same module I also added a missing import of
stix2.properties, since my IDE was claiming it could not find a
function from that module.
2021-01-20 16:59:38 -05:00
Emmanuelle Vargas-Gonzalez 82390ba648 Merge branch 'master' of github.com:oasis-open/cti-python-stix2 into dev-extensions-proposal 2021-01-15 13:01:30 -05:00
Chris Lenk a0d535336e Merge 'master' and fix imports for consistency 2021-01-15 12:34:10 -05:00
Emmanuelle Vargas-Gonzalez 85c14d1502 all changes from add-trailing-commas v2.0.2 2021-01-13 17:52:15 -05:00
Michael Chisholm f51e309775 Refactor stix2.parsing into more focused modules:
- stix2.registry, which contains the class mapping structure
  and code for scanning stix2 modules for its initial population
- stix2.registration, which contains code used to register custom
  STIX types with the registry
- stix2.parsing, which contains code for creating instances of
  registered stix2 classes from raw dicts.

This is intended to reduce circular import problems, by giving
dependent code the ability to import a module which has exactly
the functionality it needs, without pulling a lot of other stuff
it doesn't need.  Fewer imports means less chance of an import
cycle.
2021-01-08 22:08:33 -05:00
Emmanuelle Vargas-Gonzalez ef2ef95c3a `stix-extension` to `extension-definition` 2020-12-22 21:59:18 -05:00
Emmanuelle Vargas-Gonzalez 22c4351688 flatten the extensions map, remove enclosing_type from ExtensionsProperty
other minor changes
2020-11-10 17:08:51 -05:00
Chris Lenk e25734d2b6 Fix trailing commas 2020-06-26 16:43:19 -04:00
Chris Lenk b2ee33208f Set STIX 2.1 as default, fix indicator.valid_from 2020-06-26 16:43:19 -04:00
Michael Chisholm bc51cd47bd Revamp ListProperty so its logic makes more sense. 2020-06-17 16:11:30 -04:00
Chris Lenk 9d05c9d3e2
Merge pull request #401 from chisholm/fix_versionable_detection
Fix versionability detection
2020-06-10 10:22:59 -04:00
Emmanuelle Vargas-Gonzalez aa18575c83 add `id` as special-case option in regex. closes #406 2020-06-08 09:27:12 -04:00
Michael Chisholm 5522050899 Improve versionability detection when creating new versions
of objects.  Move versioning-related stuff out of stix2.utils
to its own module.  Some misc versioning-related fixes.
2020-06-05 14:24:16 -04:00
Emmanuelle Vargas-Gonzalez b4dbc419f6 Merge branch 'master' of github.com:oasis-open/cti-python-stix2 into 391-ssdeep-hash-case 2020-05-14 12:51:02 -04:00
Emmanuelle Vargas-Gonzalez 68f7ca6377 resolve problem with SSDEEP vocab use for 2.1, closes #391 2020-05-13 18:17:17 -04:00
Desai, Kartikey H 9ce299b660 Fixes #389 2020-05-13 11:40:37 -05:00
Chris Lenk df92770d25
Merge pull request #384 from oasis-open/365-versioned-classes
Validate custom type/property name formats
2020-04-03 17:30:24 -04:00
Chris Lenk 13cddf9d6d Move TypeProperty format checks to __init__
TypeProperty uses a fixed value, so check() was never called. This way
also runs the check at object registration time because the wrapper
creates an instance of TypeProperty and doesn't have to wait for the
object to be instantiated so clean() can be called.
Also fix some tests.
2020-04-02 08:17:34 -04:00
Chris Lenk c494a2e477 Use TypeProperty.clean() to verify type format 2020-04-01 21:52:04 -04:00
Chris Lenk 50df6f1474 Rename core.py -> parsing.py 2020-03-27 05:53:39 -04:00
Chris Lenk 01ba190525 Reorganize bases, use isinstance to check version
Renamed STIXDomainObject -> _DomainObject.
Renamed STIXRelationshipObject -> _RelationshipObject.
2020-03-27 02:40:42 -04:00
Michael Chisholm a9ac7ce838 pre-commit hook changes, e.g. trailing commas, import sorting,
flake8 style.
2020-03-17 18:26:57 -04:00
Michael Chisholm 4aa69fa7c9 Add support for enforcing STIX 2.1 minimum precision requirement
on versioning timestamps.
2020-03-16 20:25:38 -04:00
Michael Chisholm 176cb980a2 Remove workaround for "values" being both a Mapping method name
and sometimes a STIX property name.  It didn't work (caused
crashes under some circumstances).  Now, attributes whose names
conflict with Mapping methods will have the Mapping
interpretation.  Same-named STIX object properties will not be
accessible as attributes.
2020-01-28 18:13:36 -05:00
Chris Lenk e3c2a3a57b Fix error: dict keys changing during iteration 2020-01-04 14:48:49 -05:00
Chris Lenk 6c0fba0e67 Add Python3.8 support, fix import
Uses try/catch to still support 2.7 too
2020-01-04 13:50:06 -05:00
Desai, Kartikey H 7a47f348a0 Introduce and relocate version-based pattern checking. Fixes #307 2020-01-04 10:24:17 -05:00
Desai, Kartikey H 4350680e79 Introduce and relocate version-based pattern checking. Fixes #307 2020-01-04 10:24:17 -05:00
Desai, Kartikey H a18612bdfb Fixes #307 2020-01-04 10:24:17 -05:00