1 |
commit: e8ce76d53d90ae04589270b37a1a1a19517c2448 |
2 |
Author: aeroniero33 <justthisthing <AT> gmail <DOT> com> |
3 |
AuthorDate: Sat Aug 27 14:23:38 2016 +0000 |
4 |
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org> |
5 |
CommitDate: Sat Dec 24 04:54:15 2016 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/gentoo-keys.git/commit/?id=e8ce76d5 |
7 |
|
8 |
Implemented the email reminders in spec-check |
9 |
|
10 |
I added a few more lines of code in `actions.py` that if `args.email` == `expiry`, |
11 |
it logs in to the email server using the config credentials, checks every key |
12 |
if they pass the days limit, finds the user's email, compiles a message |
13 |
that includes all necessary information and sends the message to the user's email. |
14 |
<rebase edit> Fix trailing whitespace </edit Brian Dolbec> |
15 |
|
16 |
gkeys/gkeys/actions.py | 38 ++++++++++++++++++++++++++++++++++---- |
17 |
1 file changed, 34 insertions(+), 4 deletions(-) |
18 |
|
19 |
diff --git a/gkeys/gkeys/actions.py b/gkeys/gkeys/actions.py |
20 |
index a9d2b69..aaa3f02 100644 |
21 |
--- a/gkeys/gkeys/actions.py |
22 |
+++ b/gkeys/gkeys/actions.py |
23 |
@@ -30,6 +30,7 @@ from collections import defaultdict |
24 |
from gkeys.actionbase import ActionBase |
25 |
from gkeys.gkey import GKEY |
26 |
from gkeys.checks import SPECCHECK_SUMMARY, convert_pf, convert_yn |
27 |
+from gkeys.mail import Emailer |
28 |
|
29 |
from snakeoil.demandload import demandload |
30 |
|
31 |
@@ -241,7 +242,7 @@ class Actions(ActionBase): |
32 |
else: |
33 |
print(_unicode(" %s") % line) |
34 |
c += 1 |
35 |
- self.logger.debug(_unicode("data output:\n") + str(result)) |
36 |
+ self.logger.debug(_unicode("data output:\n") + _unicode(result)) |
37 |
return (True, result) |
38 |
|
39 |
|
40 |
@@ -382,6 +383,17 @@ class Actions(ActionBase): |
41 |
results = {} |
42 |
failed = defaultdict(list) |
43 |
self.output('', '\n Checking keys...') |
44 |
+ '''Login email''' |
45 |
+ if args.email in ['expiry']: |
46 |
+ if args.user: |
47 |
+ email_user = self.config.get_key(args.user) |
48 |
+ else: |
49 |
+ email_user = self.config.get_key('login_gentoo') |
50 |
+ emailer = Emailer(email_user, self.logger) |
51 |
+ template_path = os.path.join(self.config.get_key('template_path'), "expiry_template") |
52 |
+ message_template = self.keyhandler.set_template(template_path) |
53 |
+ self.logger.debug(_unicode('Emailer started with login: %s') \ |
54 |
+ % _unicode(email_user['login_email'])) |
55 |
for gkey in sorted(keyresults): |
56 |
self.logger.info(_unicode("Checking key %s, %s") |
57 |
% (gkey.nick, gkey.keys)) |
58 |
@@ -395,9 +407,10 @@ class Actions(ActionBase): |
59 |
results = self.gpg.speccheck(gkey.keydir, key) |
60 |
for g in results: |
61 |
pub_pass = {} |
62 |
+ key_print = '' |
63 |
for key in results[g]: |
64 |
self.output('', key.pretty_print()) |
65 |
- |
66 |
+ key_print += '\n\n' + key.pretty_print() |
67 |
if key.key is "PUB": |
68 |
pub_pass = { |
69 |
'key': key, |
70 |
@@ -476,7 +489,25 @@ class Actions(ActionBase): |
71 |
sdata = convert_pf(pub_pass, ['pub', 'sign', 'final']) |
72 |
sdata = convert_yn(sdata, ['auth', 'encrypt']) |
73 |
self.output('', SPECCHECK_SUMMARY % sdata) |
74 |
- |
75 |
+ '''Email reminder code''' |
76 |
+ if args.email in ['expiry']: |
77 |
+ uid = '' |
78 |
+ if gkey.uid: |
79 |
+ uids = gkey.uid |
80 |
+ uid = self.keyhandler.find_email(uids, self.config.get_key('prefered_address')) |
81 |
+ self.logger.debug(_unicode('The valid uid is: %s') % uid) |
82 |
+ days_limit = int(self.config.get_key('days_limit')) |
83 |
+ self.logger.debug(_unicode('Days_limit for expiry is: %s') \ |
84 |
+ % _unicode(days_limit)) |
85 |
+ is_exp = self.keyhandler.is_expiring(results, days_limit) |
86 |
+ if is_exp and uid: |
87 |
+ self.logger.debug(_unicode('Process for emailing started')) |
88 |
+ message = self.keyhandler.generate_template(message_template, \ |
89 |
+ key_print, SPECCHECK_SUMMARY % sdata) |
90 |
+ emailer.send_email(uid, message) |
91 |
+ if args.email in ['expiry']: |
92 |
+ emailer.email_quit() |
93 |
+ self.logger.debug(_unicode('Emailer quit')) |
94 |
if failed['revoked']: |
95 |
self.output([sorted(set(failed['revoked']))], '\n Revoked keys:') |
96 |
if failed['invalid']: |
97 |
@@ -516,7 +547,6 @@ class Actions(ActionBase): |
98 |
'SPEC Approved..........: %d' % len(set(failed['spec-approved'])), |
99 |
]) |
100 |
|
101 |
- |
102 |
def removekey(self, args): |
103 |
'''Remove an installed key''' |
104 |
if not args.nick: |