mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-04-03 18:56:55 +00:00
fix(pritunl_user): improve resilience to null or missing user parameters (#10955)
* fix(pritunl_user): improve resilience to null or missing user parameters * added changelog fragment - 10955 * standardize 10955 changelog fragment content Co-authored-by: Felix Fontein <felix@fontein.de> * simplify user params comparison Co-authored-by: Felix Fontein <felix@fontein.de> * simplify list fetch Co-authored-by: Felix Fontein <felix@fontein.de> * simplify remote value retrieval Co-authored-by: Felix Fontein <felix@fontein.de> --------- Co-authored-by: djenkins <djenkins@twosix.net> Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
7e8e8948a3
commit
e84f59a62d
2 changed files with 7 additions and 3 deletions
|
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- "pritunl_user - improve resilience when comparing user parameters if remote fields are ``null`` or missing. List parameters (``groups``, ``mac_addresses``) now safely default to empty lists for comparison and avoids ``KeyError`` issues (https://github.com/ansible-collections/community.general/issues/10954, https://github.com/ansible-collections/community.general/pull/10955)."
|
||||
|
|
@ -208,16 +208,18 @@ def add_or_update_pritunl_user(module):
|
|||
for key in user_params.keys():
|
||||
# When a param is not specified grab existing ones to prevent from changing it with the PUT request
|
||||
if user_params[key] is None:
|
||||
user_params[key] = users[0][key]
|
||||
user_params[key] = users[0].get(key)
|
||||
|
||||
# 'groups' and 'mac_addresses' are list comparison
|
||||
if key == "groups" or key == "mac_addresses":
|
||||
if set(users[0][key]) != set(user_params[key]):
|
||||
remote_list = users[0].get(key) or []
|
||||
local_list = user_params[key] or []
|
||||
if set(remote_list) != set(local_list):
|
||||
user_params_changed = True
|
||||
|
||||
# otherwise it is either a boolean or a string
|
||||
else:
|
||||
if users[0][key] != user_params[key]:
|
||||
if users[0].get(key) != user_params[key]:
|
||||
user_params_changed = True
|
||||
|
||||
# Trigger a PUT on the API to update the current user if settings have changed
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue