From 57975ef30641907947038b608017a9b721eb33fe Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Dec 14 2018 16:10:15 +0000 Subject: Adjust the cron sending reminder about API key expirations Nowadays, not all API keys are linked to a project, so adjust the text according to this. In addition, include the API token itself. Signed-off-by: Pierre-Yves Chibon --- diff --git a/files/api_key_expire_mail.py b/files/api_key_expire_mail.py index f246e01..890f75f 100755 --- a/files/api_key_expire_mail.py +++ b/files/api_key_expire_mail.py @@ -39,12 +39,24 @@ def main(check=False, debug=False): user = token.user username = user.fullname or user.username user_email = user.default_email - project = token.project + api_key = token.id days_left = token.expiration.day - datetime.utcnow().day subject = 'Pagure API key expiration date is near!' - text = '''Hi %s, \nYour Pagure API key for the project %s will expire - in %s day(s). Please get a new key for non-interrupted service. \n - Thanks, \nYour Pagure Admin. ''' % (username, project.name, days_left) + if token.project: + text = '''Hi %s, +Your Pagure API key %s linked to the project %s +will expire in %s day(s). +Please get a new key for non-interrupted service. + +Thanks, +Your Pagure Admin. ''' % (username, api_key, token.project.fullname, days_left) + else: + text = '''Hi %s, +Your Pagure API key %s will expire in %s day(s). +Please get a new key for non-interrupted service. + +Thanks, +Your Pagure Admin. ''' % (username, api_key, days_left) if not check: msg = pagure.lib.notify.send_email(text, subject, user_email) else: