Page MenuHomeDevCentral

D1290.diff
No OneTemporary

D1290.diff

diff --git a/requirements.txt b/requirements.txt
--- a/requirements.txt
+++ b/requirements.txt
@@ -3,7 +3,9 @@
autopep8>=1.3,<2.0
pycodestyle>=2.3.1,<3.0
-# Tests
+# Tests and utilities
PyYAML>=3.12,<4.0
+
+# Tests
mock>=2.0.0,<3.0
salt==2017.7.2
diff --git a/utils/next-uid.py b/utils/next-uid.py
new file mode 100755
--- /dev/null
+++ b/utils/next-uid.py
@@ -0,0 +1,32 @@
+#!/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.load(stream)
+ return data['shellusers']
+
+
+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

Mime Type
text/plain
Expires
Tue, Jun 10, 06:03 (15 h, 48 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2718817
Default Alt Text
D1290.diff (1 KB)

Event Timeline