Skip to content

Commit

Permalink
Merge pull request #117 from opsmill/develop
Browse files Browse the repository at this point in the history
Pre-release 1.20.1
  • Loading branch information
BeArchiTek authored Sep 9, 2024
2 parents af94640 + 297187e commit c6fc580
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 92 deletions.
5 changes: 1 addition & 4 deletions plugins/action/artifact_fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,7 @@ def run(self, tmp=None, task_vars=None):
try:
Display().v("Initializing Infrahub Client")
client = InfrahubclientWrapper(
api_endpoint=api_endpoint,
token=token,
branch=branch,
timeout=timeout,
api_endpoint=api_endpoint, token=token, branch=branch, timeout=timeout, validate_certs=validate_certs
)
Display().v("Fetch Artifacts")
result = client.fetch_single_artifact(filters=filters)
Expand Down
5 changes: 1 addition & 4 deletions plugins/action/query_graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,7 @@ def run(self, tmp=None, task_vars=None):
try:
Display().v("Initializing Infrahub Client")
client = InfrahubclientWrapper(
api_endpoint=api_endpoint,
token=token,
branch=branch,
timeout=timeout,
api_endpoint=api_endpoint, token=token, branch=branch, timeout=timeout, validate_certs=validate_certs
)
processor = InfrahubQueryProcessor(client=client)
Display().v("Processing Query")
Expand Down
1 change: 1 addition & 0 deletions plugins/inventory/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ def main(self):
branch=self.branch,
token=self.token,
timeout=self.timeout,
validate_certs=self.validate_certs,
)
processor = InfrahubNodesProcessor(client=client)
self.display.v("Processing Nodes request")
Expand Down
1 change: 1 addition & 0 deletions plugins/lookup/lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ def run(self, terms, variables=None, query=None, graph_variables=None, **kwargs)
token=token,
branch=branch,
timeout=timeout,
validate_certs=validate_certs,
)
processor = InfrahubQueryProcessor(client=client)
Display().v("Processing Query")
Expand Down
47 changes: 29 additions & 18 deletions plugins/module_utils/infrahub_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,14 @@
TYPE_MAPPING = {"str": str, "int": int, "float": float, "bool": bool}

class InfrahubclientWrapper:
def __init__(self, api_endpoint: str, branch: str, token: str, timeout: Optional[int] = 10):
def __init__(
self,
api_endpoint: str,
branch: str,
token: str,
timeout: Optional[int] = 10,
validate_certs: Optional[str] = True,
):
"""
Initializes InfrahubclientWrapper.
Expand All @@ -44,7 +51,7 @@ def __init__(self, api_endpoint: str, branch: str, token: str, timeout: Optional
"""
self.client = InfrahubClientSync(
address=api_endpoint,
config=Config(api_token=token, timeout=timeout, default_branch=branch),
config=Config(api_token=token, timeout=timeout, default_branch=branch, tls_insecure=not validate_certs),
)
self.branch_manager = InfrahubBranchManagerSync(self.client)

Expand Down Expand Up @@ -326,31 +333,35 @@ def resolve_node_mapping(
if node_attr is None:
continue

if parts[0] in node._schema.attribute_names:
if len(parts) == 1:
if parts[0] in node._schema.attribute_names and len(parts) == 1:
if node_attr.value:
attribute_dict[parts[0]] = str(node_attr.value)
else:
# attribute_dict[parts[0]] = node_attr.value
# FIXME
# If the attribute is inherited, it's not populate properly in store
tmp_node = node._client.get(id=node.id, kind=node._schema.kind)
node_attr = getattr(tmp_node, parts[0], None)
if node_attr.value:
attribute_dict[parts[0]] = str(node_attr.value)
else:
attribute_dict[parts[0]] = node_attr.value

elif parts[0] in node._schema.relationship_names:
if isinstance(node_attr, RelationshipManagerSync):
if len(parts) == 1:
peers: List[Dict[str, Any]] = []
for peer in node_attr.peers:
related_node = store.get(key=peer.id, kind=peer.schema.peer, raise_when_missing=False)
if not related_node:
peer.fetch()
related_node = peer.peer
if related_node and hasattr(related_node._schema, "attribute_names"):
peers.append(related_node.id)
attribute_dict[parts[0]] = peers
if isinstance(node_attr, RelationshipManagerSync) and len(parts) == 1:
peers: List[Dict[str, Any]] = []
for peer in node_attr.peers:
related_node = store.get(key=peer.id, raise_when_missing=False)
if not related_node:
peer.fetch()
related_node = peer.peer
if related_node and hasattr(related_node._schema, "attribute_names"):
peers.append(related_node.id)
attribute_dict[parts[0]] = peers

elif isinstance(node_attr, RelatedNodeSync):
if node_attr.id and node_attr.schema.peer:
related_node = store.get(
key=node_attr.id, kind=node_attr.schema.peer, raise_when_missing=False
)
related_node = store.get(key=node_attr.id, raise_when_missing=False)
if not related_node:
node_attr.fetch()
related_node = node_attr.peer
Expand Down
Loading

0 comments on commit c6fc580

Please sign in to comment.