From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id B7609139085 for ; Sat, 24 Dec 2016 09:13:35 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id B669B2340E8; Sat, 24 Dec 2016 09:13:25 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 7E2222340E8 for ; Sat, 24 Dec 2016 09:13:25 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 235D6340C97 for ; Sat, 24 Dec 2016 09:13:19 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 7249524F1 for ; Sat, 24 Dec 2016 09:13:16 +0000 (UTC) From: "Brian Dolbec" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Brian Dolbec" Message-ID: <1482555255.e8ce76d53d90ae04589270b37a1a1a19517c2448.dolsen@gentoo> Subject: [gentoo-commits] proj/gentoo-keys:gsoc-2016 commit in: gkeys/gkeys/ X-VCS-Repository: proj/gentoo-keys X-VCS-Files: gkeys/gkeys/actions.py X-VCS-Directories: gkeys/gkeys/ X-VCS-Committer: dolsen X-VCS-Committer-Name: Brian Dolbec X-VCS-Revision: e8ce76d53d90ae04589270b37a1a1a19517c2448 X-VCS-Branch: gsoc-2016 Date: Sat, 24 Dec 2016 09:13:16 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 837b173d-c590-4911-a509-9d24e6d852e3 X-Archives-Hash: 87bdb5869c3da96f713faa85f1333f3e commit: e8ce76d53d90ae04589270b37a1a1a19517c2448 Author: aeroniero33 gmail com> AuthorDate: Sat Aug 27 14:23:38 2016 +0000 Commit: Brian Dolbec gentoo org> CommitDate: Sat Dec 24 04:54:15 2016 +0000 URL: https://gitweb.gentoo.org/proj/gentoo-keys.git/commit/?id=e8ce76d5 Implemented the email reminders in spec-check I added a few more lines of code in `actions.py` that if `args.email` == `expiry`, it logs in to the email server using the config credentials, checks every key if they pass the days limit, finds the user's email, compiles a message that includes all necessary information and sends the message to the user's email. Fix trailing whitespace gkeys/gkeys/actions.py | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/gkeys/gkeys/actions.py b/gkeys/gkeys/actions.py index a9d2b69..aaa3f02 100644 --- a/gkeys/gkeys/actions.py +++ b/gkeys/gkeys/actions.py @@ -30,6 +30,7 @@ from collections import defaultdict from gkeys.actionbase import ActionBase from gkeys.gkey import GKEY from gkeys.checks import SPECCHECK_SUMMARY, convert_pf, convert_yn +from gkeys.mail import Emailer from snakeoil.demandload import demandload @@ -241,7 +242,7 @@ class Actions(ActionBase): else: print(_unicode(" %s") % line) c += 1 - self.logger.debug(_unicode("data output:\n") + str(result)) + self.logger.debug(_unicode("data output:\n") + _unicode(result)) return (True, result) @@ -382,6 +383,17 @@ class Actions(ActionBase): results = {} failed = defaultdict(list) self.output('', '\n Checking keys...') + '''Login email''' + if args.email in ['expiry']: + if args.user: + email_user = self.config.get_key(args.user) + else: + email_user = self.config.get_key('login_gentoo') + emailer = Emailer(email_user, self.logger) + template_path = os.path.join(self.config.get_key('template_path'), "expiry_template") + message_template = self.keyhandler.set_template(template_path) + self.logger.debug(_unicode('Emailer started with login: %s') \ + % _unicode(email_user['login_email'])) for gkey in sorted(keyresults): self.logger.info(_unicode("Checking key %s, %s") % (gkey.nick, gkey.keys)) @@ -395,9 +407,10 @@ class Actions(ActionBase): results = self.gpg.speccheck(gkey.keydir, key) for g in results: pub_pass = {} + key_print = '' for key in results[g]: self.output('', key.pretty_print()) - + key_print += '\n\n' + key.pretty_print() if key.key is "PUB": pub_pass = { 'key': key, @@ -476,7 +489,25 @@ class Actions(ActionBase): sdata = convert_pf(pub_pass, ['pub', 'sign', 'final']) sdata = convert_yn(sdata, ['auth', 'encrypt']) self.output('', SPECCHECK_SUMMARY % sdata) - + '''Email reminder code''' + if args.email in ['expiry']: + uid = '' + if gkey.uid: + uids = gkey.uid + uid = self.keyhandler.find_email(uids, self.config.get_key('prefered_address')) + self.logger.debug(_unicode('The valid uid is: %s') % uid) + days_limit = int(self.config.get_key('days_limit')) + self.logger.debug(_unicode('Days_limit for expiry is: %s') \ + % _unicode(days_limit)) + is_exp = self.keyhandler.is_expiring(results, days_limit) + if is_exp and uid: + self.logger.debug(_unicode('Process for emailing started')) + message = self.keyhandler.generate_template(message_template, \ + key_print, SPECCHECK_SUMMARY % sdata) + emailer.send_email(uid, message) + if args.email in ['expiry']: + emailer.email_quit() + self.logger.debug(_unicode('Emailer quit')) if failed['revoked']: self.output([sorted(set(failed['revoked']))], '\n Revoked keys:') if failed['invalid']: @@ -516,7 +547,6 @@ class Actions(ActionBase): 'SPEC Approved..........: %d' % len(set(failed['spec-approved'])), ]) - def removekey(self, args): '''Remove an installed key''' if not args.nick: