From b264b0445f08a8b0ab84e9ff31dddc290733ef9b Mon Sep 17 00:00:00 2001 From: Mikhail Yohman Date: Sat, 14 Jun 2025 15:21:16 -0600 Subject: [PATCH 1/4] Add initial fix to 445, but need additional feedback --- infrahub_sdk/ctl/check.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/infrahub_sdk/ctl/check.py b/infrahub_sdk/ctl/check.py index 0626d884..1abf6c35 100644 --- a/infrahub_sdk/ctl/check.py +++ b/infrahub_sdk/ctl/check.py @@ -138,14 +138,13 @@ async def run_targeted_check( branch: str | None = None, ) -> bool: filters = {} - param_value = list(check_module.definition.parameters.values()) - if param_value: - filters[param_value[0]] = check_module.definition.targets - - param_key = list(check_module.definition.parameters.keys()) identifier = None - if param_key: - identifier = param_key[0] + identifier_attribute = None + # TODO: Does this support multiple parameters and we need make identifiers a dict to iterate over on L166-168? + for param_key, param_value in check_module.definition.parameters.items(): + filters[param_value] = check_module.definition.targets + identifier = param_key + identifier_attribute = param_value.split("__")[0] check_summary: list[bool] = [] if variables: @@ -164,8 +163,8 @@ async def run_targeted_check( await targets.members.fetch() for member in targets.members.peers: check_parameter = {} - if identifier: - attribute = getattr(member.peer, identifier) + if identifier and identifier_attribute: + attribute = getattr(member.peer, identifier_attribute) check_parameter = {identifier: attribute.value} result = await run_check( check_module=check_module, From dd1d2a2baa1b9cfed9918c339d7ff052800967c0 Mon Sep 17 00:00:00 2001 From: Mikhail Yohman Date: Sat, 14 Jun 2025 15:30:54 -0600 Subject: [PATCH 2/4] Making the filter for the targets to be statically set as this shouldn't change and potential issues arise if the identifier is only valid on the specific object and not the 'CoreGroup'. --- infrahub_sdk/ctl/check.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/infrahub_sdk/ctl/check.py b/infrahub_sdk/ctl/check.py index 1abf6c35..572ee58c 100644 --- a/infrahub_sdk/ctl/check.py +++ b/infrahub_sdk/ctl/check.py @@ -137,12 +137,10 @@ async def run_targeted_check( variables: dict[str, str], branch: str | None = None, ) -> bool: - filters = {} identifier = None identifier_attribute = None # TODO: Does this support multiple parameters and we need make identifiers a dict to iterate over on L166-168? for param_key, param_value in check_module.definition.parameters.items(): - filters[param_value] = check_module.definition.targets identifier = param_key identifier_attribute = param_value.split("__")[0] @@ -159,7 +157,9 @@ async def run_targeted_check( ) check_summary.append(result) else: - targets = await client.get(kind="CoreGroup", include=["members"], **filters) + targets = await client.get( + kind="CoreGroup", include=["members"], **{"name__value": check_module.definition.targets} + ) await targets.members.fetch() for member in targets.members.peers: check_parameter = {} From e973fc183c321ed346933ee8216869021a151175 Mon Sep 17 00:00:00 2001 From: Mikhail Yohman Date: Sat, 14 Jun 2025 15:35:26 -0600 Subject: [PATCH 3/4] Fix filter to not use kwargs unpacking. --- infrahub_sdk/ctl/check.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/infrahub_sdk/ctl/check.py b/infrahub_sdk/ctl/check.py index 572ee58c..7d81a3dd 100644 --- a/infrahub_sdk/ctl/check.py +++ b/infrahub_sdk/ctl/check.py @@ -157,9 +157,7 @@ async def run_targeted_check( ) check_summary.append(result) else: - targets = await client.get( - kind="CoreGroup", include=["members"], **{"name__value": check_module.definition.targets} - ) + targets = await client.get(kind="CoreGroup", include=["members"], name__value=check_module.definition.targets) await targets.members.fetch() for member in targets.members.peers: check_parameter = {} From 11590598742ad6d3cd6d1d788c898391cf99ba07 Mon Sep 17 00:00:00 2001 From: Mikhail Yohman Date: Sat, 14 Jun 2025 15:44:29 -0600 Subject: [PATCH 4/4] Had to change filters to unpack kwargs due to MyPy typing issue. --- infrahub_sdk/ctl/check.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/infrahub_sdk/ctl/check.py b/infrahub_sdk/ctl/check.py index 7d81a3dd..c71c373d 100644 --- a/infrahub_sdk/ctl/check.py +++ b/infrahub_sdk/ctl/check.py @@ -137,6 +137,7 @@ async def run_targeted_check( variables: dict[str, str], branch: str | None = None, ) -> bool: + filters = {"name__value": check_module.definition.targets} identifier = None identifier_attribute = None # TODO: Does this support multiple parameters and we need make identifiers a dict to iterate over on L166-168? @@ -157,7 +158,7 @@ async def run_targeted_check( ) check_summary.append(result) else: - targets = await client.get(kind="CoreGroup", include=["members"], name__value=check_module.definition.targets) + targets = await client.get(kind="CoreGroup", include=["members"], **filters) await targets.members.fetch() for member in targets.members.peers: check_parameter = {}