Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add checks for bad input for AT provider help paths #330

Merged
merged 1 commit into from
Oct 16, 2024
Merged
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
20 changes: 16 additions & 4 deletions broker/providers/ansible_tower.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ def extend(self, target_vm, new_expire_time=None, provider_labels=None):
provider_labels=provider_labels,
)

def provider_help( # noqa: PLR0912, PLR0915 - Possible TODO refactor
def provider_help( # noqa: PLR0911, PLR0912, PLR0915 - Possible TODO refactor
self,
workflows=False,
workflow=None,
Expand All @@ -660,7 +660,11 @@ def provider_help( # noqa: PLR0912, PLR0915 - Possible TODO refactor
"""Get a list of extra vars and their defaults from a workflow."""
results_limit = kwargs.get("results_limit", settings.ANSIBLETOWER.results_limit)
if workflow:
wfjt = self._v2.workflow_job_templates.get(name=workflow).results.pop()
if wfjt := self._v2.workflow_job_templates.get(name=workflow).results:
wfjt = wfjt.pop()
else:
logger.warning(f"Workflow {workflow} not found!")
return
default_inv = self._v2.inventory.get(id=wfjt.inventory).results.pop()
logger.info(
f"\nDescription:\n{wfjt.description}\n\n"
Expand All @@ -682,7 +686,11 @@ def provider_help( # noqa: PLR0912, PLR0915 - Possible TODO refactor
workflows = "\n".join(workflows[:results_limit])
logger.info(f"Available workflows:\n{workflows}")
elif inventory:
inv = self._v2.inventory.get(name=inventory, kind="").results.pop()
if inv := self._v2.inventory.get(name=inventory, kind="").results:
inv = inv.pop()
else:
logger.warning(f"Inventory {inventory} not found!")
return
inv = {"Name": inv.name, "ID": inv.id, "Description": inv.description}
logger.info(f"Accepted additional nick fields:\n{helpers.yaml_format(inv)}")
elif inventories:
Expand All @@ -696,7 +704,11 @@ def provider_help( # noqa: PLR0912, PLR0915 - Possible TODO refactor
inv = "\n".join(inv[:results_limit])
logger.info(f"Available Inventories:\n{inv}")
elif job_template:
jt = self._v2.job_templates.get(name=job_template).results.pop()
if jt := self._v2.job_templates.get(name=job_template).results:
jt = jt.pop()
else:
logger.warning(f"Job Template {job_template} not found!")
return
default_inv = self._v2.inventory.get(id=jt.inventory).results.pop()
logger.info(
f"\nDescription:\n{jt.description}\n\n"
Expand Down