Skip to content

Commit

Permalink
permissionError exception handling in _resolve_labels
Browse files Browse the repository at this point in the history
  • Loading branch information
rplevka committed Apr 18, 2024
1 parent 811a284 commit 3cccf7d
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions broker/providers/ansible_tower.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,15 +444,22 @@ def _resolve_labels(self, labels, target):
label_ids = []
for label in labels:
label_expanded = f"{label}={labels[label]}" if labels[label] else label
if result := self.v2.labels.get(name=label_expanded).results:
label_ids.append(result[0].id)
else:
# label does not exist yet, creating
result = self.v2.labels.post(
{"name": label_expanded, "organization": target.summary_fields.organization.id}
)
if result:
label_ids.append(result.id)
try:
if result := self.v2.labels.get(name=label_expanded).results:
label_ids.append(result[0].id)
else:
# label does not exist yet, creating
result = self.v2.labels.post(
{
"name": label_expanded,
"organization": target.summary_fields.organization.id,
}
)
if result:
label_ids.append(result.id)
except awxkit.exceptions.Forbidden:
raise exceptions.PermissionError

return label_ids

@cached_property
Expand Down

0 comments on commit 3cccf7d

Please sign in to comment.