From 81f33a56dd16b27a4392c624b728473592340d73 Mon Sep 17 00:00:00 2001 From: KiLLuuuhh Date: Mon, 15 Apr 2024 14:17:14 +0200 Subject: [PATCH] reformat --- .../module_utils/system_access_users_utils.py | 38 ++++++++++++++----- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/plugins/module_utils/system_access_users_utils.py b/plugins/module_utils/system_access_users_utils.py index 7038a3c3..fc2c3c42 100644 --- a/plugins/module_utils/system_access_users_utils.py +++ b/plugins/module_utils/system_access_users_utils.py @@ -338,7 +338,9 @@ def set_apikeys(self, apikeys: list = None) -> list: salt = crypt.mksalt(crypt.METHOD_SHA512) try: base64.b64decode(api_key) - api_keys.append({"key": api_key, "secret": crypt.crypt(secret, salt)}) + api_keys.append( + {"key": api_key, "secret": crypt.crypt(secret, salt)} + ) except binascii.Error as binascii_error_message: raise OPNSenseNotValidBase64APIKeyError( f"The API key: {api_key} is not a valid base64 string. " @@ -470,7 +472,9 @@ def from_ansible_module_params(cls, params: dict) -> "User": ), } - user_dict = {key: value for key, value in user_dict.items() if value is not None} + user_dict = { + key: value for key, value in user_dict.items() if value is not None + } return cls(**user_dict) @@ -684,7 +688,9 @@ def _update_user_groups(self, user: User, existing_user: Optional[User] = None): return # Exit the method after removing the user from all groups. # Convert groupname to a list if it's not already. - group_names = user.groupname if isinstance(user.groupname, list) else [user.groupname] + group_names = ( + user.groupname if isinstance(user.groupname, list) else [user.groupname] + ) for group_name in group_names: group_found = False @@ -698,7 +704,9 @@ def _update_user_groups(self, user: User, existing_user: Optional[User] = None): if not group_found: # Group was not found, raise an exception - raise OPNSenseGroupNotFoundError(f"Group '{group_name}' not found on Instance") + raise OPNSenseGroupNotFoundError( + f"Group '{group_name}' not found on Instance" + ) def set_user_password(self, user: User) -> None: """ @@ -707,12 +715,20 @@ def set_user_password(self, user: User) -> None: # load requirements php_requirements = self._config_maps["password"]["php_requirements"] - configure_function = self._config_maps["password"]["configure_functions"]["name"] - configure_params = self._config_maps["password"]["configure_functions"]["configure_params"] + configure_function = self._config_maps["password"]["configure_functions"][ + "name" + ] + configure_params = self._config_maps["password"]["configure_functions"][ + "configure_params" + ] # format parameters formatted_params = [ - (param.replace("'password'", f"'{user.password}'") if "password" in param else param) + ( + param.replace("'password'", f"'{user.password}'") + if "password" in param + else param + ) for param in configure_params ] @@ -754,7 +770,9 @@ def add_or_update(self, user: User) -> None: modify the specified user's information. """ - existing_user: Optional[User] = next((u for u in self._users if u.name == user.name), None) + existing_user: Optional[User] = next( + (u for u in self._users if u.name == user.name), None + ) next_uid: Element = self.get("uid") # since the current password of an user cannot not be compared with the new one, @@ -830,7 +848,9 @@ def find(self, **kwargs) -> Optional[User]: """ for user in self._users: - match = all(getattr(user, key, None) == value for key, value in kwargs.items()) + match = all( + getattr(user, key, None) == value for key, value in kwargs.items() + ) if match: return user return None