From 9905fb1e64341822366b6ab1d414d2baa230af0a Mon Sep 17 00:00:00 2001 From: Karsten Hopp Date: Feb 05 2019 15:21:25 +0000 Subject: Fix calculation of days until API key expires and short the API key in the emails API key reminder should not send the API key in clear text. Shorten displayed key to 5 chars. Calculation of remaining days until a API key expires was wrong as it took into account only the days part of the date and ignored month or year. fixes #4230 fixes #4231 Signed-off-by: Karsten Hopp --- diff --git a/files/api_key_expire_mail.py b/files/api_key_expire_mail.py index d7bf8d8..c399af1 100755 --- a/files/api_key_expire_mail.py +++ b/files/api_key_expire_mail.py @@ -41,7 +41,7 @@ def main(check=False, debug=False): username = user.fullname or user.username user_email = user.default_email api_key = token.id - days_left = token.expiration.day - datetime.utcnow().day + days_left = (token.expiration - datetime.utcnow()).days subject = 'Pagure API key expiration date is near!' if token.project: text = '''Hi %s, @@ -50,14 +50,14 @@ 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) +Your Pagure Admin. ''' % (username, api_key[:5], 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) +Your Pagure Admin. ''' % (username, api_key[:5], days_left) if not check: msg = pagure.lib.notify.send_email(text, subject, user_email) else: