Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F3942645
next-uid.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
763 B
Referenced Files
None
Subscribers
None
next-uid.py
View Options
#!/usr/bin/env python3
#
# Guesses a free sequential user ID for a new account.
#
# To do so, reads from pillar/core/users.sls (USERS_DATASOURCE) the last users
# uid # and offers the next one available.
#
# ID > 5000 (USERS_CUT) are ignored.
import
yaml
USERS_DATASOURCE
=
'pillar/core/users.sls'
USERS_DATASOURCE_KEY
=
'shellusers'
USERS_CUT
=
5000
def
get_shellusers
(
filename
,
key
):
with
open
(
filename
)
as
stream
:
data
=
yaml
.
safe_load
(
stream
)
return
data
[
key
]
def
get_uids
(
users
,
threshold
):
return
[
users
[
username
][
'uid'
]
for
username
in
users
if
users
[
username
][
'uid'
]
<
threshold
]
users
=
get_shellusers
(
USERS_DATASOURCE
,
USERS_DATASOURCE_KEY
)
uids
=
get_uids
(
users
,
USERS_CUT
)
print
(
max
(
uids
)
+
1
)
File Metadata
Details
Attached
Mime Type
text/x-python
Expires
Thu, Dec 26, 17:53 (22 h, 51 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2261836
Default Alt Text
next-uid.py (763 B)
Attached To
Mode
rOPS Nasqueron Operations
Attached
Detach File
Event Timeline
Log In to Comment