Skip to content

Commit 90943a5

Browse files
Remove user shell attribute as enum (#117)
* Remove user shell attribute as enum * Add changelog fragment for #117
1 parent 04ff7c0 commit 90943a5

File tree

3 files changed

+10
-34
lines changed

3 files changed

+10
-34
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
bugfixes:
3+
- system_access_users - Remove the UserLoginEnum type to prevent strict validation.

plugins/module_utils/system_access_users_utils.py

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,6 @@ class OPNSenseCryptReturnError(Exception):
6363
"""
6464

6565

66-
# pylint: disable=too-few-public-methods
67-
class UserLoginShell(ListEnum):
68-
"""Represents the user login shell."""
69-
70-
NOLOGIN = "/sbin/nologin"
71-
CSH = "/bin/csh"
72-
SH = "/bin/sh"
73-
TCSH = "/bin/tcsh"
74-
75-
7666
@dataclass
7767
class Group:
7868
"""
@@ -190,7 +180,7 @@ class User:
190180
descr (Optional[str]): A description of the user, if available.
191181
ipsecpsk (Optional[str]): IPsec pre-shared key, if applicable.
192182
otp_seed (Optional[str]): OTP seed for two-factor authentication, if used.
193-
shell (Optional[UserLoginShell]): The user's login shell, if specified.
183+
shell (Optional[str]): The user's login shell, if specified.
194184
uid (Optional[str]): The user's unique identifier.
195185
disabled (bool): Whether the user is disabled (default is False).
196186
full_name (Optional[str]): The user's full name, if available.
@@ -225,7 +215,7 @@ class User:
225215
descr: Optional[str] = None
226216
ipsecpsk: Optional[str] = None
227217
otp_seed: Optional[str] = None
228-
shell: Optional[UserLoginShell] = UserLoginShell.NOLOGIN
218+
shell: str = "/sbin/nologin"
229219
uid: Optional[str] = None
230220
disabled: bool = False
231221
full_name: Optional[str] = None
@@ -245,8 +235,6 @@ def __init__(self, **kwargs):
245235
_extra_attrs: dict = {}
246236
for key, value in kwargs.items():
247237
if key in _attr_names:
248-
if key == "shell":
249-
value = UserLoginShell.from_string(value)
250238
setattr(self, key, value)
251239
continue
252240

@@ -264,20 +252,6 @@ def __eq__(self, other) -> bool:
264252

265253
return True
266254

267-
def __post_init__(self) -> None:
268-
# Manually define the fields and their expected types
269-
enum_fields = {
270-
"shell": UserLoginShell,
271-
}
272-
273-
for field_name, field_type in enum_fields.items():
274-
value = getattr(self, field_name)
275-
276-
# Check if the value is a string and the field_type is a subclass of ListEnum
277-
if isinstance(value, str) and issubclass(field_type, ListEnum):
278-
# Convert string to ListEnum
279-
setattr(self, field_name, field_type.from_string(value))
280-
281255
def set_otp_seed(self, otp_seed: str = None) -> str:
282256
"""
283257
Generates and returns a base32-encoded OTP seed.

tests/unit/plugins/module_utils/test_system_access_users_utils.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
Group,
1616
User,
1717
UserSet,
18-
UserLoginShell,
1918
OPNSenseGroupNotFoundError,
2019
OPNSenseCryptReturnError,
2120
)
@@ -157,7 +156,7 @@ def test_user_from_xml():
157156
assert test_user.authorizedkeys is None
158157
assert test_user.ipsecpsk is None
159158
assert test_user.otp_seed is None
160-
assert test_user.shell == UserLoginShell.SH
159+
assert test_user.shell == "/bin/sh"
161160
assert test_user.uid == "1000"
162161

163162

@@ -204,7 +203,7 @@ def test_user_with_api_key_from_xml():
204203
assert test_user.authorizedkeys is None
205204
assert test_user.ipsecpsk is None
206205
assert test_user.otp_seed is None
207-
assert test_user.shell == UserLoginShell.SH
206+
assert test_user.shell == "/bin/sh"
208207
assert test_user.uid == "1001"
209208

210209

@@ -227,7 +226,7 @@ def test_user_from_ansible_module_params_simple(sample_config_path):
227226
assert new_test_user.expires is None
228227
assert new_test_user.authorizedkeys is None
229228
assert new_test_user.ipsecpsk is None
230-
assert new_test_user.shell == UserLoginShell.SH
229+
assert new_test_user.shell == "/bin/sh"
231230
assert new_test_user.uid == "1000"
232231

233232

@@ -316,7 +315,7 @@ def test_user_from_ansible_module_params_with_group(sample_config_path):
316315
assert new_test_user.expires is None
317316
assert new_test_user.authorizedkeys is None
318317
assert new_test_user.ipsecpsk is None
319-
assert new_test_user.shell == UserLoginShell.SH
318+
assert new_test_user.shell == "/bin/sh"
320319
assert new_test_user.uid == "1000"
321320
assert new_test_user.groupname == ["admins"]
322321

@@ -504,7 +503,7 @@ def test_user_from_ansible_module_params_with_authorizedkeys(
504503
assert new_test_user.expires is None
505504
assert new_test_user.authorizedkeys == "3J35EY37QTNXFFEECJGZ32WVYQC5W4GZ"
506505
assert new_test_user.ipsecpsk is None
507-
assert new_test_user.shell == UserLoginShell.SH
506+
assert new_test_user.shell == "/bin/sh"
508507
assert new_test_user.uid == "1000"
509508

510509

0 commit comments

Comments
 (0)