[sysadmin-bin] Don't remove accounts that were created recently enough to have made no contribution/commit
- From: Andrea Veri <averi src gnome org>
- To: gnome-sysadmin gnome org,commits-list gnome org
- Subject: [sysadmin-bin] Don't remove accounts that were created recently enough to have made no contribution/commit
- Date: Tue, 1 Feb 2022 14:58:40 +0000 (UTC)
commit a240d78e6830c3b8a7e6897419960fa119b8bc7b
Author: Andrea Veri <averi redhat com>
Date: Tue Feb 1 15:58:26 2022 +0100
Don't remove accounts that were created recently enough to have made no contribution/commit
cleanup-inactive-ldap-accounts.py | 26 ++++++++++++++++++--------
1 file changed, 18 insertions(+), 8 deletions(-)
---
diff --git a/cleanup-inactive-ldap-accounts.py b/cleanup-inactive-ldap-accounts.py
index 85c29d4..7555213 100755
--- a/cleanup-inactive-ldap-accounts.py
+++ b/cleanup-inactive-ldap-accounts.py
@@ -76,6 +76,14 @@ for user, last_pushed in last_pushed_times.items():
def user_is_current(username):
return username in last_pushed_times and last_pushed_times[username] >= now - 2 * 365 * 24 * 60 * 60
+def user_is_recent(username):
+ createTimestamp = time.strptime(glu.get_attributes_from_ldap(username,
'createTimestamp').decode('utf-8'), '%Y%m%d%H%M%SZ')
+ delta = datetime.timedelta(seconds=now-time.mktime(createTimestamp)).days
+
+ if delta < 180:
+ return 1
+ else:
+ return 0
def add_remove_comment_to_user(username, group):
new_comment = f"Removed from group { group } by cleanup-inactive-ldap-accounts at {
datetime.date.today() }."
@@ -127,16 +135,18 @@ ftpadmin_users = (glu.get_uids_from_group('ftpadmin', excludes))
for gnomecvs_user in gnomecvs_users:
if not user_is_current(gnomecvs_user):
- if options.verbose:
- print(f"Removing user { gnomecvs_user } from gnomecvs", end='\n')
+ if not user_is_recent:
+ if options.verbose:
+ print(f"Removing user { gnomecvs_user } from gnomecvs", end='\n')
- glu.remove_user_from_ldap_group(gnomecvs_user, 'gnomecvs')
- add_remove_comment_to_user(gnomecvs_user, 'gnomecvs')
+ glu.remove_user_from_ldap_group(gnomecvs_user, 'gnomecvs')
+ add_remove_comment_to_user(gnomecvs_user, 'gnomecvs')
for ftpadmin_user in ftpadmin_users:
if not user_is_current(ftpadmin_user):
- if options.verbose:
- print(f"Removing user { ftpadmin_user } from ftpadmin", end='\n')
+ if not user_is_recent:
+ if options.verbose:
+ print(f"Removing user { ftpadmin_user } from ftpadmin", end='\n')
- glu.remove_user_from_ldap_group(ftpadmin_user, 'ftpadmin')
- add_remove_comment_to_user(gnomecvs_user, 'ftpadmin')
+ glu.remove_user_from_ldap_group(ftpadmin_user, 'ftpadmin')
+ add_remove_comment_to_user(gnomecvs_user, 'ftpadmin')
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]