Skip to content

Commit

Permalink
Fixed roles diff when the roles are provided as a list (#737)
Browse files Browse the repository at this point in the history
* Fixed roles diff when the roles are provided as a list, in a single entry

* Use clear to clean up memory usage

* Fix linting issue

---------

Co-authored-by: Leon Muresan,Bogdan,CH-Lausanne <bogdan.leonmuresan@nestle.com>
  • Loading branch information
bogdanmuresan and Leon Muresan,Bogdan,CH-Lausanne committed Dec 7, 2023
1 parent af03e78 commit 2a6f175
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/diff_roles_fix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
bugfixes:
- Fixed roles diff when the roles are provided as a list, in a single entry
15 changes: 15 additions & 0 deletions plugins/lookup/controller_object_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,21 @@ def run(self, terms, variables=None, **kwargs):
for item in list_to_remove:
compare_list_reduced.remove(item)
compare_list_reduced.extend(list_to_extend)
# Expand all compare list elements when roles is provided as list
list_to_extend.clear()
list_to_remove.clear()
for item in compare_list_reduced:
expanded = False
dupitems = ["roles", "role"]
if "roles" in item:
for role in item["roles"]:
list_to_extend.append(self.map_item(item, "role", role, dupitems))
expanded = True
if expanded:
list_to_remove.append(item)
for item in list_to_remove:
compare_list_reduced.remove(item)
compare_list_reduced.extend(list_to_extend)
elif (
api_list[0]["type"] != "organization"
and api_list[0]["type"] != "user"
Expand Down

0 comments on commit 2a6f175

Please sign in to comment.