From 2d98dc13c0aa1b8e1fe87c704763fd60cc179fcc Mon Sep 17 00:00:00 2001 From: Boomaa23 Date: Tue, 12 Jul 2022 17:49:09 -0700 Subject: [PATCH 1/2] Add base max-uid script --- staff/acct/max-uid | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 staff/acct/max-uid diff --git a/staff/acct/max-uid b/staff/acct/max-uid new file mode 100644 index 0000000..1fe31b2 --- /dev/null +++ b/staff/acct/max-uid @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 +"""Find the highest non-excluded OCF UID.""" +import sys + +from ocflib.infra.ldap import ldap_ocf +from ocflib.infra.ldap import OCF_LDAP_PEOPLE +from ocflib.account.creation import RESERVED_UID_RANGES +from ocflib.account.creation import IGNORED_UID_RANGES + + +def main(): + with ldap_ocf() as c: + c.search( + OCF_LDAP_PEOPLE, + '(uid=*)', + attributes=['uidNumber'] + ) + uids = [int(entry['attributes']['uidNumber']) for entry in c.response] + remove_ranges = RESERVED_UID_RANGES + IGNORED_UID_RANGES + uids = filter(lambda v: v not in remove_ranges, uids) + print(f"Max currently used UID is: {max(uids)}") + + +if __name__ == "__main__": + sys.exit(main()) From 941d0326644adc4a3d6010d09eeb011f30aec7de Mon Sep 17 00:00:00 2001 From: boomaa23 Date: Tue, 12 Jul 2022 18:32:13 -0700 Subject: [PATCH 2/2] Finish max-uid script --- staff/acct/max-uid | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) mode change 100644 => 100755 staff/acct/max-uid diff --git a/staff/acct/max-uid b/staff/acct/max-uid old mode 100644 new mode 100755 index 1fe31b2..f7d71c7 --- a/staff/acct/max-uid +++ b/staff/acct/max-uid @@ -2,24 +2,34 @@ """Find the highest non-excluded OCF UID.""" import sys +from ocflib.account.creation import IGNORED_UID_RANGES +from ocflib.account.creation import RESERVED_UID_RANGES from ocflib.infra.ldap import ldap_ocf from ocflib.infra.ldap import OCF_LDAP_PEOPLE -from ocflib.account.creation import RESERVED_UID_RANGES -from ocflib.account.creation import IGNORED_UID_RANGES + + +INVALID_UID_RANGES = sorted(RESERVED_UID_RANGES + IGNORED_UID_RANGES) + + +def is_valid_uid(uid): + for start, end in IGNORED_UID_RANGES: + if start <= uid <= end: + return False + return True def main(): + print('Searching for maximum currently used OCF UID') with ldap_ocf() as c: c.search( - OCF_LDAP_PEOPLE, - '(uid=*)', + OCF_LDAP_PEOPLE, + '(uid=*)', attributes=['uidNumber'] ) - uids = [int(entry['attributes']['uidNumber']) for entry in c.response] - remove_ranges = RESERVED_UID_RANGES + IGNORED_UID_RANGES - uids = filter(lambda v: v not in remove_ranges, uids) - print(f"Max currently used UID is: {max(uids)}") - + uids = [int(entry['attributes']['uidNumber']) for entry in c.response] + uids = filter(is_valid_uid, uids) + print('Max currently used OCF UID is: %s' % max(uids)) + -if __name__ == "__main__": +if __name__ == '__main__': sys.exit(main())