Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/+3bf1c5c.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix an issue with with `infrahubctl menu load` that would fail while loading the menu
22 changes: 22 additions & 0 deletions infrahub_sdk/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,12 @@
MANY = "many"


class RelationshipDirection(str, Enum):
BIDIR = "bidirectional"
OUTBOUND = "outbound"
INBOUND = "inbound"


class BranchSupportType(str, Enum):
AWARE = "aware"
AGNOSTIC = "agnostic"
Expand Down Expand Up @@ -339,6 +345,7 @@
state: SchemaState = SchemaState.PRESENT
name: str
peer: str
direction: RelationshipDirection = RelationshipDirection.BIDIR
kind: RelationshipKind = RelationshipKind.GENERIC
label: Optional[str] = None
description: Optional[str] = None
Expand Down Expand Up @@ -413,6 +420,21 @@

raise ValueError(f"Unable to find the relationship {id}")

def get_matching_relationship(
self, id: str, direction: RelationshipDirection = RelationshipDirection.BIDIR
) -> RelationshipSchema:
valid_direction = RelationshipDirection.BIDIR

Check warning on line 426 in infrahub_sdk/schema.py

View check run for this annotation

Codecov / codecov/patch

infrahub_sdk/schema.py#L426

Added line #L426 was not covered by tests
if direction == RelationshipDirection.INBOUND:
valid_direction = RelationshipDirection.OUTBOUND

Check warning on line 428 in infrahub_sdk/schema.py

View check run for this annotation

Codecov / codecov/patch

infrahub_sdk/schema.py#L428

Added line #L428 was not covered by tests
elif direction == RelationshipDirection.OUTBOUND:
valid_direction = RelationshipDirection.INBOUND

Check warning on line 430 in infrahub_sdk/schema.py

View check run for this annotation

Codecov / codecov/patch

infrahub_sdk/schema.py#L430

Added line #L430 was not covered by tests

for item in self.relationships:
if item.identifier == id and item.direction == valid_direction:
return item

Check warning on line 434 in infrahub_sdk/schema.py

View check run for this annotation

Codecov / codecov/patch

infrahub_sdk/schema.py#L434

Added line #L434 was not covered by tests

raise ValueError(f"Unable to find the relationship {id} / ({valid_direction.value})")

Check warning on line 436 in infrahub_sdk/schema.py

View check run for this annotation

Codecov / codecov/patch

infrahub_sdk/schema.py#L436

Added line #L436 was not covered by tests

@property
def attribute_names(self) -> list[str]:
return [item.name for item in self.attributes]
Expand Down
2 changes: 1 addition & 1 deletion infrahub_sdk/spec/object.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
if rel_schema.identifier is None:
raise ValueError("identifier must be defined")

peer_rel = peer_schema.get_relationship_by_identifier(id=rel_schema.identifier)
peer_rel = peer_schema.get_matching_relationship(id=rel_schema.identifier, direction=rel_schema.direction)

Check warning on line 81 in infrahub_sdk/spec/object.py

View check run for this annotation

Codecov / codecov/patch

infrahub_sdk/spec/object.py#L81

Added line #L81 was not covered by tests

rel_data = data[rel]["data"]
context = {}
Expand Down
Loading