Skip to content

Commit

Permalink
reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
KiLLuuuhh committed Apr 16, 2024
1 parent 2e0e6a2 commit 81f33a5
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions plugins/module_utils/system_access_users_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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. "
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -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:
"""
Expand All @@ -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
]

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 81f33a5

Please sign in to comment.