コード例 #1
0
    def link_to(self, target, relationship_type=None, stix_rel=None):
        """Creates a link between two YetiObjects.

        Args:
          target: The YetiObject to link to.
          relationship_type: The type of link. (e.g. targets, uses, mitigates)
          stix_rel: STIX Relationship object
        """
        from yeti.core.relationships import Relationship
        if stix_rel is None:
            stix_rel = StixRelationship(relationship_type=relationship_type,
                                        source_ref=self.id,
                                        target_ref=target.id)
            stix_rel = json.loads(stix_rel.serialize())

        existing = list(Relationship.filter({'attributes.id': stix_rel['id']}))
        if existing:
            return existing[0]
        # pylint: disable=protected-access
        return Relationship(self._arango_id, target._arango_id, stix_rel).save()
コード例 #2
0
    def link_to(self, link_type, target, attributes=None):
        """Creates a link between two YetiObjects.

        Args:
          link_type: The type of link.
          target: The YetiObject to link to.
          attributes: A dictionary with attributes to add to the link.
        """
        stix_rel = Relationship(relationship_type=link_type,
                                source_ref=self.id,
                                target_ref=target.id)

        graph = self._db.graph('stix')
        edge_collection = graph.edge_collection('relationships')
        document = {
            '_from': self._arango_id,
            '_to': target._arango_id,  # pylint: disable=protected-access
            'attributes': stix_rel.serialize(),
        }
        return edge_collection.insert(document)