1010SCRIPT = os .path .basename (__file__ )
1111ENDPOINT = "https://registry.cilogon.org/registry/"
1212OSG_CO_ID = 7
13- CMS_GROUP_ID = 4622
14- CMS_COU_ID = 1785
1513LDAP_TARGET_ID = 9
1614
1715_usage = f"""\
@@ -32,16 +30,18 @@ class Options:
3230 authstr = None
3331 input_file = None
3432 mapping_file = None
35- ssh_key_authenticator = 5
36- unix_cluster_id = 10
33+ ssh_key_authenticator = 5 # 1
34+ unix_cluster_id = 10 # 1
3735 provisioning_target = LDAP_TARGET_ID
36+ import_group_id = None
37+ import_cou_id = None
3838
3939
4040options = Options ()
4141
4242def parse_options (args ):
4343 try :
44- ops , args = getopt .getopt (args , 'u:c:d:f:e:i:m:h' )
44+ ops , args = getopt .getopt (args , 'u:c:d:f:e:i:m:g:o: h' )
4545 except getopt .GetoptError :
4646 usage ()
4747
@@ -60,6 +60,8 @@ def parse_options(args):
6060 if op == '-e' : options .endpoint = arg
6161 if op == '-i' : options .input_file = arg
6262 if op == '-m' : options .mapping_file = arg
63+ if op == '-g' : options .import_group_id = arg
64+ if op == '-o' : options .import_cou_id = arg
6365
6466 try :
6567 user , passwd = utils .getpw (options .user , passfd , passfile )
@@ -82,10 +84,10 @@ def read_data_dump():
8284 data_json [entry ]["public_keys" ][key_index ].update ({"authenticator" : key_sections [2 ]})
8385 with open (options .mapping_file , 'r' , encoding = 'utf-8' ) as mapping_file :
8486 mapping_json = json .load (mapping_file )
85- return data_json
87+ return data_json , mapping_json
8688
8789
88- def build_co_person_record (entry ):
90+ def build_co_person_record (entry , mapping_json : dict ):
8991 record = {}
9092 record .update ({"CoPerson" : schema_utils .co_person_schema (options .osg_co_id , status = "A" )})
9193
@@ -95,29 +97,37 @@ def build_co_person_record(entry):
9597
9698 identifiers = []
9799
98- # CMS Username
99- identifiers .append (schema_utils .co_person_identifier (entry ["username" ], "cmsuser " , status = "A" ))
100- # CMS UID
101- identifiers .append (schema_utils .co_person_identifier (entry ["uid" ], "cmsuid " , status = "A" ))
100+ # UC Connect Username
101+ identifiers .append (schema_utils .co_person_identifier (entry ["username" ], "ucconnectuser " , status = "A" ))
102+ # UC Connect UID
103+ identifiers .append (schema_utils .co_person_identifier (entry ["uid" ], "ucconnectuid " , status = "A" ))
102104 #globus id
103- identifiers .append (schema_utils .co_person_identifier (entry ["globus_id" ], "cmsglobusid " , status = "A" ))
105+ identifiers .append (schema_utils .co_person_identifier (entry ["globus_id" ], "ucconnectglobusid " , status = "A" ))
104106 #cilogon id
105- if not entry ["cilogon_id " ] is None :
106- identifiers .append (schema_utils .co_person_identifier (entry ["cilogon_id " ], "oidcsub" , status = "A" ))
107+ if not ( entry ["cilogon_oidc_sub " ] is None or entry [ "cilogon_oidc_sub" ] == "" ) :
108+ identifiers .append (schema_utils .co_person_identifier (entry ["cilogon_oidc_sub " ], "oidcsub" , status = "A" ))
107109 else :
108110 print (f"Warning: user { entry ['username' ]} lacks a cilogon id." )
111+ # With our current LDAP Provisioner configuration, the CO Person still needs an oidcsub identifier, even if it's junk
112+ identifiers .append (schema_utils .co_person_identifier (f"dummy-text-for-provisioning-{ entry ['username' ]} " , "oidcsub" , status = "A" , login = False ))
109113
110114 record .update ({"Identifier" : identifiers })
111115
112116 group_memberships = []
113- group_memberships .append (schema_utils .co_person_group_member (CMS_GROUP_ID ))
117+ group_memberships .append (schema_utils .co_person_group_member (options .import_group_id ))
118+
119+ for user_membership in entry ["groups" ]:
120+ if not mapping_json .get (user_membership ) is None :
121+ group_memberships .append (schema_utils .co_person_group_member (mapping_json .get (user_membership )))
122+ else :
123+ print (f"Warning: could not find group id for group { user_membership } , user { entry ['username' ]} ." )
114124
115125 # Group Memberships
116126 record .update ({"CoGroupMember" : group_memberships })
117127
118128 roles = []
119129
120- roles .append (schema_utils .co_person_role (CMS_COU_ID , "CMS User" , "member" , 1 ))
130+ roles .append (schema_utils .co_person_role (options . import_cou_id , "UC Connect User" , "member" , 1 ))
121131 record .update ({"CoPersonRole" : roles })
122132
123133 emails = []
@@ -144,6 +154,15 @@ def build_co_person_record(entry):
144154
145155 return record
146156
157+ def fix_username (co_person_record , new_username ):
158+ record = co_person_record
159+
160+ for identifier in co_person_record ["Identifier" ]:
161+ if identifier ["type" ] == "osguser" :
162+ identifier ["identifier" ] = new_username
163+
164+ return record
165+
147166
148167def create_unix_cluster_group (co_person_record ):
149168 identifiers_list = co_person_record ["Identifier" ]
@@ -193,9 +212,12 @@ def main(args):
193212
194213 co_person_records = dict ()
195214
196- data_dump_json = read_data_dump ()
215+ data_dump_json , mapping_json = read_data_dump ()
216+
217+ #data_dump_json = [data_dump_json[0], data_dump_json[1], data_dump_json[2], data_dump_json[3], data_dump_json[8], data_dump_json[9]]
218+
197219 for entry in data_dump_json :
198- co_person_records .update ({entry ["username" ] : build_co_person_record (entry )})
220+ co_person_records .update ({entry ["username" ] : build_co_person_record (entry , mapping_json )})
199221
200222 usernames = list (co_person_records .keys ())
201223
@@ -219,6 +241,9 @@ def main(args):
219241
220242 co_person_data = utils .core_api_co_person_read (user , options .osg_co_id , options .endpoint , options .authstr )
221243
244+ co_person_data = fix_username (co_person_data , user )
245+ utils .core_api_co_person_update (user , options .osg_co_id , co_person_data , options .endpoint , options .authstr )
246+
222247 co_person_data , gid = add_unix_cluster_account (co_person_data )
223248
224249 utils .core_api_co_person_update (user , options .osg_co_id , co_person_data , options .endpoint , options .authstr )
0 commit comments