@@ -63,25 +63,41 @@ def parse_options(args):
6363 if op == '-g' : options .import_group_id = arg
6464 if op == '-o' : options .import_cou_id = arg
6565
66+ missing = []
67+ if options .input_file is None :
68+ missing .append ("-i <input_file>" )
69+ if options .mapping_file is None :
70+ missing .append ("-m <mapping_file>" )
71+ if options .import_group_id is None :
72+ missing .append ("-g <import_group_id>" )
73+ if options .import_cou_id is None :
74+ missing .append ("-o <import_cou_id>" )
75+ if missing :
76+ usage ("Missing required options: " + ", " .join (missing ))
77+
6678 try :
6779 user , passwd = utils .getpw (options .user , passfd , passfile )
6880 options .authstr = utils .mkauthstr (user , passwd )
6981 except PermissionError :
7082 usage ("PASS required" )
7183
72-
7384def read_data_dump ():
74- data_json = []
7585 with open (options .input_file , 'r' , encoding = 'utf-8' ) as input_file :
7686 data_json = json .load (input_file )
77- for entry in range (len (data_json )):
78- for key_index in range (len (data_json [entry ]["public_keys" ])):
79- key = data_json [entry ]["public_keys" ][key_index ]
80- key_sections = str (key ).split ()
81- if len (key_sections ) >= 2 :
82- data_json [entry ]["public_keys" ][key_index ] = {"type" : key_sections [0 ], "pkey" : key_sections [1 ]}
83- if len (key_sections ) >= 3 :
84- data_json [entry ]["public_keys" ][key_index ].update ({"authenticator" : key_sections [2 ]})
87+
88+ for entry in data_json :
89+ parsed_keys = []
90+ for key in entry .get ("public_keys" , []):
91+ key_sections = str (key ).split ()
92+ if len (key_sections ) < 2 :
93+ print (f"Warning: ignoring invalid SSH public key for user { entry .get ('username' , '<unknown>' )} : { key !r} " )
94+ continue
95+ key_obj = {"type" : key_sections [0 ], "pkey" : key_sections [1 ]}
96+ if len (key_sections ) >= 3 :
97+ key_obj ["authenticator" ] = " " .join (key_sections [2 :])
98+ parsed_keys .append (key_obj )
99+ entry ["public_keys" ] = parsed_keys
100+
85101 with open (options .mapping_file , 'r' , encoding = 'utf-8' ) as mapping_file :
86102 mapping_json = json .load (mapping_file )
87103 return data_json , mapping_json
@@ -166,8 +182,10 @@ def fix_username(co_person_record, new_username):
166182
167183def create_unix_cluster_group (co_person_record ):
168184 identifiers_list = co_person_record ["Identifier" ]
169- username = next ((item ["identifier" ] for item in identifiers_list if item ["type" ] == "osguser" ))
170- uid = next ((item ["identifier" ] for item in identifiers_list if item ["type" ] == "uid" ))
185+ username = next ((item ["identifier" ] for item in identifiers_list if item .get ("type" ) == "osguser" ), None )
186+ uid = next ((item ["identifier" ] for item in identifiers_list if item .get ("type" ) == "uid" ), None )
187+ if username is None or uid is None :
188+ raise ValueError (f"Missing required identifiers (osguser/uid) in CO Person record: { identifiers_list } " )
171189 description = f"Unix Cluster Group for { username } "
172190 result = utils .create_co_group (username , description , options .osg_co_id , options .endpoint , options .authstr )
173191 ucg = None
0 commit comments