[sysadmin-bin] Decode happens directly on glu now
- From: Andrea Veri <averi src gnome org>
- To: gnome-sysadmin gnome org,commits-list gnome org
- Subject: [sysadmin-bin] Decode happens directly on glu now
- Date: Fri, 25 Feb 2022 12:11:30 +0000 (UTC)
commit 018b8519c283bb60f374ef7fdcdce7f8d889d1f9
Author: Andrea Veri <averi redhat com>
Date: Fri Feb 25 13:06:14 2022 +0100
Decode happens directly on glu now
cleanup-inactive-ldap-accounts.py | 15 ++++----
membership/foundation-operations.py | 72 +++++++++++++++----------------------
2 files changed, 35 insertions(+), 52 deletions(-)
---
diff --git a/cleanup-inactive-ldap-accounts.py b/cleanup-inactive-ldap-accounts.py
index 7555213..6ce14cd 100755
--- a/cleanup-inactive-ldap-accounts.py
+++ b/cleanup-inactive-ldap-accounts.py
@@ -77,7 +77,7 @@ 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')
+ createTimestamp = time.strptime(glu.get_attributes_from_ldap(username, 'createTimestamp'),
'%Y%m%d%H%M%SZ')
delta = datetime.timedelta(seconds=now-time.mktime(createTimestamp)).days
if delta < 180:
@@ -88,22 +88,19 @@ def user_is_recent(username):
def add_remove_comment_to_user(username, group):
new_comment = f"Removed from group { group } by cleanup-inactive-ldap-accounts at {
datetime.date.today() }."
- ldap_fields = glu.get_attributes_from_ldap(username, 'cn', 'description', 'mail')
- current_comment = ldap_fields[2].decode('utf-8')
- name = ldap_fields[1].decode('utf-8')
- mail = ldap_fields[3].decode('utf-8')
+ ldap_vars = glu.get_attributes_from_ldap(username, 'cn', 'description', 'mail')
- if current_comment is None:
+ if ldap_vars[2] is None:
comment = new_comment
glu.add_or_update_description(username, comment, add=True)
else:
- comment = '%s. %s' % (current_comment, new_comment)
+ comment = '%s. %s' % (ldap_vars[2], new_comment)
glu.add_or_update_description(username, comment, update=True)
form_letter = f"""
-Hello { name }, your membership of the group { group } has been automatically removed, due to inactivity.
+Hello { ldap_vars[1] }, your membership of the group { group } has been automatically removed, due to
inactivity.
For more information, please see the following email:
https://mail.gnome.org/archives/foundation-list/2014-March/msg00063.html
@@ -116,7 +113,7 @@ the GNOME Accounts Team"""
msg = MIMEText(form_letter)
msg['Subject'] = "Your GNOME group membership expired"
msg['From'] = "noreply gnome org"
- msg['To'] = "%s" % (mail)
+ msg['To'] = "%s" % (ldap_vars[3])
msg['Reply-To']= "accounts gnome org"
server = smtplib.SMTP("localhost")
server.sendmail(msg['From'], msg['To'], msg.as_string())
diff --git a/membership/foundation-operations.py b/membership/foundation-operations.py
index 751d25d..7a5d866 100755
--- a/membership/foundation-operations.py
+++ b/membership/foundation-operations.py
@@ -59,67 +59,55 @@ def send_renewal_emails():
foundationmembers = glu.get_uids_from_group('foundation')
for member in foundationmembers:
- ldap_fields = glu.get_attributes_from_ldap(member, 'FirstAdded', 'LastRenewedOn', 'mail', 'cn')
+ ldap_vars = glu.get_attributes_from_ldap(member, 'FirstAdded', 'LastRenewedOn', 'mail', 'cn')
- first_added_attr = ldap_fields[1].decode()
- last_renewed_on_attr = ldap_fields[2].decode()
- mail_attr = ldap_fields[3].decode()
- common_name_attr = ldap_fields[4].decode()
- userid_attr = ldap_fields[0].decode()
+ if (ldap_vars[1] and ldap_vars[2]):
+ if (ldap_vars[2] == today) and (ldap_vars[1] == today):
+ send_form_letters(new_member_form_letter, ldap_vars[3], ldap_vars[4], ldap_vars[0])
+ elif ldap_vars[2] == today:
+ send_form_letters(renewal_form_letter, ldap_vars[3], ldap_vars[4])
+
+
+def rtdelta_wrap(t, a):
+ import dateutil.relativedelta as relativedelta
+ return relativedelta.relativedelta(t=a)
- if (first_added_attr and last_renewed_on_attr):
- if (last_renewed_on_attr == today) and (first_added_attr == today):
- send_form_letters(new_member_form_letter, mail_attr, common_name_attr, userid_attr)
- elif last_renewed_on_attr == today:
- send_form_letters(renewal_form_letter, mail_attr, common_name_attr)
def cleanup_mailgrace():
today = dt.date.today()
gracemails = glu.get_uids_from_group('mailgrace')
- import dateutil.relativedelta as relativedelta
- delta_2y = relativedelta.relativedelta(years=2)
- delta_3m = relativedelta.relativedelta(months=3)
-
for member in gracemails:
- ldap_fields = glu.get_attributes_from_ldap(member, 'LastRenewedOn', 'mail', 'cn')
- last_renewed_on_attr = ldap_fields[1].decode('utf-8')
- last_renewed_on = dt.date(int(last_renewed_on_attr.split('-')[0]),
int(last_renewed_on_attr.split('-')[1]), int(last_renewed_on_attr.split('-')[2]))
- mail_attr = ldap_fields[2].decode('utf-8')
- common_name_attr = ldap_fields[3].decode('utf-8')
- if today == (last_renewed_on + delta_2y + delta_3m):
- send_form_letters(alias_decomm, mail_attr, common_name_attr, last_renewed_on_attr)
+ ldap_vars = glu.get_attributes_from_ldap(member, 'LastRenewedOn', 'mail', 'cn')
+ last_renewed_on = dt.datetime.strptime(ldap_vars[1], '%Y-%m-%d')
+
+ if today == (last_renewed_on + rtdelta_wrap('years', 2) + rtdelta_wrap('months', 3)):
+ send_form_letters(alias_decomm, ldap_vars[2], ldap_vars[3], ldap_vars[1])
glu.remove_user_from_ldap_group(member, 'mailgrace')
+
def remove_expired_memberships_from_foundation():
today = dt.date.today()
- import dateutil.relativedelta as relativedelta
- delta_2y = relativedelta.relativedelta(years=2)
- delta_1m = relativedelta.relativedelta(months=1)
members_list = ''
foundationmembers = glu.get_uids_from_group('foundation')
for member in foundationmembers:
- ldap_fields = glu.get_attributes_from_ldap(member, 'LastRenewedOn', 'mail', 'cn')
+ ldap_vars = glu.get_attributes_from_ldap(member, 'LastRenewedOn', 'mail', 'cn')
+ last_renewed_on = dt.datetime.strptime(ldap_vars[1], '%Y-%m-%d')
- last_renewed_on_attr = ldap_fields[1].decode('utf-8')
- last_renewed_on = dt.date(int(last_renewed_on_attr.split('-')[0]),
int(last_renewed_on_attr.split('-')[1]), int(last_renewed_on_attr.split('-')[2]))
- mail_attr = ldap_fields[2].decode('utf-8')
- common_name_attr = ldap_fields[3].decode('utf-8')
-
- if today == (last_renewed_on + delta_2y - delta_1m):
- send_form_letters(close_to_expire_membership_form_letter, mail_attr, common_name_attr,
last_renewed_on_attr)
- elif (today - delta_2y) == last_renewed_on:
- print(f"Removing { member } from the foundation LDAP group as the membership expired on {
last_renewed_on_attr }")
+ if today == (last_renewed_on + rtdelta_wrap('years', 2) - rtdelta_wrap('months', 1)):
+ send_form_letters(close_to_expire_membership_form_letter, ldap_vars[2], ldap_vars[3],
ldap_vars[1])
+ elif (today - rtdelta_wrap('years', 2)) == last_renewed_on:
+ print(f"Removing { member } from the foundation LDAP group as the membership expired on {
ldap_vars[1] }")
glu.remove_user_from_ldap_group(member, 'foundation')
glu.add_user_to_ldap_group(member, 'mailgrace')
- send_form_letters(expired_membership_form_letter, mail_attr, common_name_attr,
last_renewed_on_attr)
+ send_form_letters(expired_membership_form_letter, ldap_vars[2], ldap_vars[3], ldap_vars[1]))
- if (last_renewed_on.year == (today - delta_2y).year) and (last_renewed_on.month == today.month) and
(today.day == 1):
- members_list += common_name_attr + ', ' + last_renewed_on_attr + '\n'
+ if (last_renewed_on.year == (today - rtdelta_wrap('years', 2)).year) and (last_renewed_on.month ==
today.month) and (today.day == 1):
+ members_list += ldap_vars[3] + ', ' + ldap_vars[1] + '\n'
if len(members_list) > 0:
send_form_letters(renewals_to_foundation_list, 'foundation-list gnome org', 'foundation-list',
members_list)
@@ -136,17 +124,15 @@ def generate_membership_list():
result = {}
for member in foundationmembers:
- ldap_fields = glu.get_attributes_from_ldap(member, "cn", "LastRenewedOn")
- common_name_attr = ldap_fields[1].decode("utf-8")
+ ldap_vars = glu.get_attributes_from_ldap(member, "cn", "LastRenewedOn")
- members_list.append(common_name_attr)
+ members_list.append(ldap_vars[1])
members_list.sort(key=str.casefold)
for member in emeritus:
ldap_fields = glu.get_attributes_from_ldap(member, "cn", "LastRenewedOn")
- common_name_attr = ldap_fields[1].decode("utf-8")
- emeritus_list.append(common_name_attr)
+ emeritus_list.append(ldap_vars[1])
emeritus_list.sort(key=str.casefold)
result['members'] = [{"name": name} for name in members_list]
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]