Browse Source

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 <pingou@pingoured.fr>
Pierre-Yves Chibon 5 years ago
parent
commit
57975ef306
1 changed files with 16 additions and 4 deletions
  1. 16 4
      files/api_key_expire_mail.py

+ 16 - 4
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: