Edge

class bhopengraph.Edge.Edge(start_node, end_node, kind, properties=None, start_match_by='id', end_match_by='id')[source]

Bases: object

Edge class representing a directed edge in the OpenGraph.

Follows BloodHound OpenGraph schema requirements with start/end nodes, kind, and properties. All edges are directed and one-way as per BloodHound requirements.

Sources: - https://bloodhound.specterops.io/opengraph/schema#edges - https://bloodhound.specterops.io/opengraph/schema#minimal-working-json

Parameters:
__init__(start_node, end_node, kind, properties=None, start_match_by='id', end_match_by='id')[source]

Initialize an Edge.

Parameters:
  • start_node (-) – ID of the source node

  • end_node (-) – ID of the destination node

  • kind (-) – Type/class of the edge relationship

  • properties (-) – Edge properties

  • start_match_by (str)

  • end_match_by (str)

set_property(key, value)[source]

Set a property on the edge.

Parameters:
  • key (-) – Property name

  • value (-) – Property value

get_property(key, default=None)[source]

Get a property from the edge.

Parameters:
  • key (-) – Property name

  • default (-) – Default value if property doesn’t exist

Returns:

  • Property value or default

remove_property(key)[source]

Remove a property from the edge.

Parameters:

key (-) – Property name to remove

to_dict()[source]

Convert edge to dictionary for JSON serialization.

Returns:

Edge as dictionary following BloodHound OpenGraph schema

Return type:

  • dict

classmethod from_dict(edge_data)[source]

Create an Edge instance from a dictionary.

Parameters:

edge_data (-) – Dictionary containing edge data

Returns:

Edge instance or None if data is invalid

Return type:

  • Edge

get_start_node()[source]

Get the start node ID.

Returns:

Start node ID

Return type:

  • str

get_end_node()[source]

Get the end node ID.

Returns:

End node ID

Return type:

  • str

get_kind()[source]

Get the edge kind/type.

Returns:

Edge kind

Return type:

  • str

get_unique_id()[source]

Get a unique ID for the edge.

Returns:

Unique ID for the edge

Return type:

  • str

__eq__(other)[source]

Check if two edges are equal based on their start, end, and kind.

Parameters:

other (-) – The other edge to compare to

Returns:

True if the edges are equal, False otherwise

Return type:

  • bool

__hash__()[source]

Hash based on start, end, and kind for use in sets and as dictionary keys.

Returns:

Hash of the start, end, and kind

Return type:

  • int

validate()[source]

Validate the edge against the EDGE_SCHEMA.

Returns:

(is_valid, list_of_errors)

Return type:

  • tuple[bool, list[str]]