public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Brian Dolbec" <dolsen@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/gentoo-keys:gsoc-2016 commit in: gkeys/gkeys/
Date: Fri, 23 Dec 2016 08:37:13 +0000 (UTC)	[thread overview]
Message-ID: <1482478547.ac39930fac28cf13b709389e1ad6bc0f3e4b591f.dolsen@gentoo> (raw)

commit:     ac39930fac28cf13b709389e1ad6bc0f3e4b591f
Author:     aeroniero33 <justthisthing <AT> gmail <DOT> com>
AuthorDate: Sat Aug 27 14:23:38 2016 +0000
Commit:     Brian Dolbec <dolsen <AT> gentoo <DOT> 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.
<rebase edit> Fix trailing whitespace </edit Brian Dolbec>

 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:


             reply	other threads:[~2016-12-23  8:37 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-23  8:37 Brian Dolbec [this message]
  -- strict thread matches above, loose matches on Subject: below --
2016-12-24  9:41 [gentoo-commits] proj/gentoo-keys:gsoc-2016 commit in: gkeys/gkeys/ Brian Dolbec
2016-12-24  9:41 Brian Dolbec
2016-12-24  9:41 Brian Dolbec
2016-12-24  9:41 Brian Dolbec
2016-12-24  9:41 Brian Dolbec
2016-12-24  9:41 Brian Dolbec
2016-12-24  9:41 Brian Dolbec
2016-12-24  9:41 Brian Dolbec
2016-12-24  9:41 Brian Dolbec
2016-12-24  9:13 Brian Dolbec
2016-12-24  9:13 Brian Dolbec
2016-12-24  9:13 Brian Dolbec
2016-12-24  9:13 Brian Dolbec
2016-12-24  9:13 Brian Dolbec
2016-12-24  9:13 Brian Dolbec
2016-12-24  9:13 Brian Dolbec
2016-12-24  9:13 Brian Dolbec
2016-12-24  9:13 Brian Dolbec
2016-12-24  9:13 Brian Dolbec
2016-12-24  9:13 Brian Dolbec
2016-12-24  9:13 Brian Dolbec
2016-12-24  9:13 Brian Dolbec
2016-12-24  9:13 Brian Dolbec
2016-12-24  9:13 Brian Dolbec
2016-12-24  9:13 Brian Dolbec
2016-12-24  9:13 Brian Dolbec
2016-12-24  4:52 [gentoo-commits] proj/gentoo-keys:master " Brian Dolbec
2016-12-24  9:13 ` [gentoo-commits] proj/gentoo-keys:gsoc-2016 " Brian Dolbec
2016-12-23  8:37 Brian Dolbec
2016-12-23  8:37 Brian Dolbec
2016-12-23  8:37 Brian Dolbec
2016-12-23  8:37 Brian Dolbec
2016-12-23  8:37 Brian Dolbec
2016-12-23  8:37 Brian Dolbec
2016-12-23  8:37 Brian Dolbec
2016-12-23  8:37 Brian Dolbec
2016-12-23  8:37 Brian Dolbec
2016-12-23  8:37 Brian Dolbec
2016-12-23  8:37 Brian Dolbec
2016-12-23  8:37 Brian Dolbec

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1482478547.ac39930fac28cf13b709389e1ad6bc0f3e4b591f.dolsen@gentoo \
    --to=dolsen@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox