colander_data_converter.formats.threatr.converter module

class colander_data_converter.formats.threatr.converter.ColanderToThreatrMapper[source]

Bases: ThreatrMapper

Mapper for converting Colander data model to Threatr data model.

This class handles the conversion of Colander feeds, entities, relations, and events to their corresponding Threatr equivalents. It processes reference fields and creates appropriate relationship mappings between entities.

Note

The mapper uses the mapping configuration loaded from the parent ThreatrMapper class to determine appropriate field and relation name mappings.

convert(colander_feed, root_entity)[source]

Convert a Colander data model to a Threatr data model.

This method transforms a complete Colander feed including all entities, relations, and events into the equivalent Threatr representation. It handles reference field extraction and conversion to explicit relations.

Parameters:
  • colander_feed (ColanderFeed) – The Colander feed to convert

  • root_entity (Union[str, UUID, EntityTypes]) – The root entity ID, UUID, or entity object to use as the root

Returns:

A ThreatrFeed object containing the converted data

Return type:

ThreatrFeed

Raises:

ValueError – If the root entity cannot be found or is invalid

Important

The root entity must exist in the provided Colander feed. If a string ID is provided, it must be a valid UUID format.

class colander_data_converter.formats.threatr.converter.ThreatrToColanderMapper[source]

Bases: ThreatrMapper

Mapper for converting Threatr data model to Colander data model.

This class handles the conversion of Threatr feeds, entities, events, and relations to their corresponding Colander equivalents. It processes explicit relations and attempts to convert them back to reference fields where appropriate.

Important

This mapper maintains state during conversion, storing the input ThreatrFeed and building the output ColanderFeed incrementally.

Variables:
  • threatr_feed – The input Threatr feed being converted

  • colander_feed – The output Colander feed being built

convert(threatr_feed)[source]

Convert a Threatr data model to a Colander data model.

This method performs a complete conversion of a ThreatrFeed to a ColanderFeed, handling entities, events, and relations. It attempts to convert explicit relations back to reference fields where possible.

Parameters:

threatr_feed (ThreatrFeed) – The Threatr feed to convert

Returns:

A ColanderFeed object containing the converted data

Return type:

ColanderFeed

Raises:

AssertionError – If threatr_feed is None or not a ThreatrFeed instance

Important

The method resolves all references in the input feed before processing to ensure consistent object relationships.