From 852e8a51e88d4260e3099968c7e22ef6e056dfa6 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Tue, 14 Aug 2018 14:51:48 -0400 Subject: [PATCH] ucsAccounts: Add groups for certifications, door access, membership level, and volunteer type --- ucsAccounts.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/ucsAccounts.py b/ucsAccounts.py index 62b62c9..f3a2876 100755 --- a/ucsAccounts.py +++ b/ucsAccounts.py @@ -1,20 +1,40 @@ #!/usr/bin/env python3 import random +import re import subprocess import string from common import * LDAP_BASE = "cn=users,dc=sawtooth,dc=claremontmakerspace,dc=org" +GROUP_BASE = "cn=groups,dc=sawtooth,dc=claremontmakerspace,dc=org" +GROUPS_REGEX = "|".join(['Certified: .*', 'Access .*\?', 'CMS .*', 'Volunteer: .*']) RAND_PW_LEN = 20 +def makeGroups(members): + groups = [key.replace(':', '.').replace('?', '') + for key in members[0].keys() + if re.match(GROUPS_REGEX, key) is not None] + for group in groups: + subprocess.call(["udm", "groups/group", "create", + "--position", GROUP_BASE, + "--set", "name=" + group]) + def makeSets(props): return sum([["--set", key + "=" + value] for key, value in props.items()], []) +def makeAppendGroups(member): + groups = [key.replace(':', '.').replace('?', '') + for key, value in member.items() + if re.match(GROUPS_REGEX, key) is not None and value != ''] + return sum([["--append", "groups=cn=" + group + ',' + GROUP_BASE] + for group in groups], []) + def main(): members = getMembershipworksData(['members', 'staff'], "lvl,phn,eml,lbl,nam,end,_id") + makeGroups(members) for member in members: randomPass = ''.join(random.choice(string.ascii_letters + string.digits) @@ -36,8 +56,6 @@ def main(): "employeeNumber": member["Account ID"], #"employeeType": "", # Employee type - #"groups": "", # Groups - "homedrive": "H:", # Windows home drive "sambahome": "\\\\ucs\\" + username, # Windows home path "profilepath": "%LOGONSERVER%\\%USERNAME%\\windows-profiles\\default", # Windows profile directory @@ -64,7 +82,8 @@ def main(): subprocess.call(["udm", "users/user", "modify", "--dn", "uid=" + username + "," + LDAP_BASE] - + makeSets(props)) + + makeSets(props) + + makeAppendGroups(member)) if __name__ == "__main__": main()