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 33529139089 for ; Fri, 23 Dec 2016 08:37:19 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 8B926E0DDF; Fri, 23 Dec 2016 08:37:17 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (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 5932EE0DD7 for ; Fri, 23 Dec 2016 08:37:17 +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 B57A3340FC1 for ; Fri, 23 Dec 2016 08:37:15 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id CD9B024E8 for ; Fri, 23 Dec 2016 08:37:13 +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: <1482478547.ac39930fac28cf13b709389e1ad6bc0f3e4b591f.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: ac39930fac28cf13b709389e1ad6bc0f3e4b591f X-VCS-Branch: gsoc-2016 Date: Fri, 23 Dec 2016 08:37:13 +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: 6822f0b4-6d3f-4bf2-9d02-3dd4f3ab0726 X-Archives-Hash: da0c51cf78f161ddbdef6d876baa7cca commit: ac39930fac28cf13b709389e1ad6bc0f3e4b591f Author: aeroniero33 gmail com> AuthorDate: Sat Aug 27 14:23:38 2016 +0000 Commit: Brian Dolbec gentoo org> CommitDate: Fri Dec 23 07:35:47 2016 +0000 URL: https://gitweb.gentoo.org/proj/gentoo-keys.git/commit/?id=ac39930f 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 1b27605..4bd0e86 100644 --- a/gkeys/gkeys/actions.py +++ b/gkeys/gkeys/actions.py @@ -29,6 +29,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 @@ -239,7 +240,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) @@ -380,6 +381,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)) @@ -393,9 +405,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, @@ -474,7 +487,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']: @@ -514,7 +545,6 @@ class Actions(ActionBase): 'SPEC Approved..........: %d' % len(set(failed['spec-approved'])), ]) - def removekey(self, args): '''Remove an installed key''' if not args.nick: