diff --git a/lib/import_user.py b/lib/import_user.py index 9599cc051b8e68e8c8d088277c47f2864a6912ca..af8e7764c323b45cf03eded09b81be7213e37aee 100644 --- a/lib/import_user.py +++ b/lib/import_user.py @@ -25,26 +25,44 @@ class ImportUser: persons = pd.read_excel(self.input_file, engine='odf', skiprows=self.skip_rows) persons.rename(columns=self.columnnames_map, inplace=True) - logging.info(f"Going to process the following list:\n{persons.to_string()}") + logging.info(f"Cleaning up list") - # validate list + # cleanup list error_count = 0 - for _, person in persons.iterrows(): - if (person['email'] == 0): + for index, person in persons.iterrows(): + if person['email'] == 0: + persons.drop(index, inplace=True) continue - if (not isinstance(person['username'], str)): - logging.error(f"- missing username in '{person}'") + if not isinstance(person['username'], str): + logging.error(f"Missing username in '{person}'") error_count+=1 continue - if (not bool(re.match(r'^[\w\d\.-]+$', person['username'], flags=re.IGNORECASE))): - logging.error(f"- found invalid characters in username: '{person['username']}'") + if person['username'].strip() != person['username']: + logging.warning(f"Leading or trailing blank(s) found in username email: '{person['username']}'") + persons.at[index, 'username'] = person['username'].strip() + if person['email'].strip() != person['email']: + logging.warning(f"Leading or trailing blank(s) found in external email: '{person['email']}'") + persons.at[index, 'email'] = person['email'].strip() + if 'mailPrimaryAddress' in person and isinstance(person['mailPrimaryAddress'], str): + if person['mailPrimaryAddress'].strip() != person['mailPrimaryAddress']: + logging.warning(f"Leading or trailing blank(s) found in internal email: '{person['mailPrimaryAddress']}'") + persons.at[index, 'mailPrimaryAddress'] = person['mailPrimaryAddress'].strip() + + logging.info(f"Processing list with {len(persons.index)} lines.") + logging.debug(f"Going to process the following list:\n{persons.to_string()}") + + # validate list + for index, person in persons.iterrows(): + if not bool(re.match(r'^[\w\d\.-]+$', person['username'], flags=re.IGNORECASE)): + logging.error(f"Found invalid characters in username: '{person['username']}'") error_count+=1 - if (not bool(re.match(r'^[\w\d\.\-_]+@[\w\d\.\-_]+$', person['email'], flags=re.IGNORECASE))): + if not bool(re.match(r'^[\w\d\.\-_]+@[\w\d\.\-_]+$', person['email'], flags=re.IGNORECASE)): logging.error(f"Found invalid external email: '{person['email']}'") error_count+=1 - if ('mailPrimaryAddress' in person) and (isinstance(person['mailPrimaryAddress'], str)) and (not bool(re.match(r'^[\w\d\.\-_]+@[\w\d\.\-_]+$', person['mailPrimaryAddress'], flags=re.IGNORECASE))): - logging.error(f"Found invalid primary email: '{person['mailPrimaryAddress']}'") - error_count+=1 + if 'mailPrimaryAddress' in person and isinstance(person['mailPrimaryAddress'], str): + if not bool(re.match(r'^[\w\d\.\-_]+@[\w\d\.\-_]+$', person['mailPrimaryAddress'], flags=re.IGNORECASE)): + logging.error(f"Found invalid primary email: '{person['mailPrimaryAddress']}'") + error_count+=1 if (error_count > 0): sys.exit("! Found errors, please fix and rerun the script") diff --git a/lib/ucs.py b/lib/ucs.py index 0854004d2438b103cacc72e568d2ee1c3ec36830..6ecf658b17b2a7d09df102801cbae95f9030e0cf 100644 --- a/lib/ucs.py +++ b/lib/ucs.py @@ -243,7 +243,7 @@ class Ucs: logging.debug(f"Reconcile {username} groups to: {person['groups']}") self.update_user(current_json, person) else: - logging.warning(f"User {dn} already exists.") + logging.info(f"User {dn} already exists.") else: logging.info(f"Creating user {username}") self.create_user(person) diff --git a/template.ods b/template.ods index 524ff6ea9ac09d30f6d032bd80c843a07838bfd3..e39536532b95a0e8e4e6a716bf56fe2f242c0d04 100644 Binary files a/template.ods and b/template.ods differ