Commit Graph

11 Commits (81550cab92aaacbca5db0d37c607dfd1707ce4c3)

Author SHA1 Message Date
maybe-sybr bd897c9848 improv: Check reference prop types for all customs
Previously the requirement that properties ending in `_ref(s)` were
instances of an appropriate type capable of containing a STIX
`identifier` (the current interpretation of section 3.1 of the STIX 2.1
spec) was only enforced for custom observables. This change refactors
the property checks for custom objects to enforce this and the STIX 2.1
property name requirement (also from section 3.1) in a common helper,
therefore extending the enforcement of both requirements to all custom
object types created by downstream projects.

There is a special case carved out for STIX 2.0 observables which are
required to contain "object references" rather than identifiers. This
special logic is encoded in the reference property validation helper and
enabled by a kwarg which is passed exclusively by the custom observable
registration helper.
2021-07-22 14:55:14 +10:00
Michael Chisholm 945e3375aa Fix extension registration to not only check nested properties
for spec compliance, but also the toplevel properties, if any.
2021-07-09 20:24:31 -04:00
Michael Chisholm e99be67c1e Remove registration._get_extension_class() since it's redundant
with registry.class_for_type().
2021-07-09 18:11:11 -04:00
Emmanuelle Vargas-Gonzalez 5067a3ff76 couple of changes after merging against master 2021-02-19 10:05:56 -05:00
Michael Chisholm f8c86f7352 Fixups after a rebase. There were several conflict resolutions
and I probably forgot some stuff...
2021-01-20 16:59:39 -05:00
Michael Chisholm db1d0b736b Remove registry.get_stix2_class_maps(), since now that the
class map structure is keyed by normal "X.Y" style versions,
the convenience that function provided is no longer necessary.
So it no longer makes sense to have the function (at least,
not for that reason).  Change users of that function to use
the STIX2_OBJ_MAPS structure directly.
2021-01-20 16:59:39 -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
Michael Chisholm 24307626b0 Move get_stix2_class_maps() from .utils to .registry (since it's
really just a simple accessor into the class maps table), and
change other code to use it, in places where it was simple and
made sense.
2021-01-20 16:59:38 -05:00
Chris Lenk a0d535336e Merge 'master' and fix imports for consistency 2021-01-15 12:34:10 -05:00
Chris Lenk 7de5c458bb Fix import sort order 2021-01-15 10:27:39 -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