* [gentoo-commits] proj/gentoo-keys:gsoc-2016 commit in: gkeys/gkeys/
@ 2016-12-23 8:37 Brian Dolbec
0 siblings, 0 replies; 40+ messages in thread
From: Brian Dolbec @ 2016-12-23 8:37 UTC (permalink / raw
To: gentoo-commits
commit: 5c5767151c58d5f6b45a1251b21533df7b8487b5
Author: aeroniero33 <justthisthing <AT> gmail <DOT> com>
AuthorDate: Tue Jun 21 01:40:28 2016 +0000
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Fri Dec 23 07:36:41 2016 +0000
URL: https://gitweb.gentoo.org/proj/gentoo-keys.git/commit/?id=5c576715
Created the send-key function
gkeys/gkeys/action_map.py | 11 ++++++++++-
gkeys/gkeys/actions.py | 27 +++++++++++++++++++++++++++
gkeys/gkeys/lib.py | 16 ++++++++++++++++
3 files changed, 53 insertions(+), 1 deletion(-)
diff --git a/gkeys/gkeys/action_map.py b/gkeys/gkeys/action_map.py
index e4ea412..f372a5c 100644
--- a/gkeys/gkeys/action_map.py
+++ b/gkeys/gkeys/action_map.py
@@ -18,7 +18,7 @@ Seed_Actions = ['----seeds----', 'add-seed', 'fetch-seed',
'list-seed', 'list-seedfiles', 'move-seed', 'remove-seed']
Key_Actions = ['----keys-----', 'check-key', 'installed',
- 'install-key', 'list-key', 'refresh-key', 'remove-key',
+ 'install-key', 'list-key', 'send-key', 'refresh-key', 'remove-key',
'search-key', 'spec-check']
General_Actions = ['---general---', 'list-cats', 'sign','verify']
@@ -174,6 +174,15 @@ Gpg info.: pub 4096R/825533CBF6CD6C97 2014-10-03 [expires: 2017-09-17]
Gkey task results:
Done.''',
}),
+ ('send-key', {
+ 'func': 'sendkey',
+ 'options': ['category', 'nick', 'name', 'fingerprint', 'keyid', 'keys',
+ 'keydir', 'keyring'],
+ 'desc': '''Uploads the selected gpg key''',
+ 'long_desc': '''Uploads the selected gpg key''',
+ 'example': '''gkeys send-key -C gentoo -n gkeys''',
+ }),
+
('move-key', {
'func': 'movekey',
'options': ['category', 'nick', 'name', 'fingerprint', 'keys',
diff --git a/gkeys/gkeys/actions.py b/gkeys/gkeys/actions.py
index 4bd0e86..849568d 100644
--- a/gkeys/gkeys/actions.py
+++ b/gkeys/gkeys/actions.py
@@ -192,6 +192,33 @@ class Actions(ActionBase):
return (False, messages)
+ def sendkey(self, args):
+ '''Send selected key(s) to the server'''
+ if not args.category:
+ return (False, ["Please specify seeds type."])
+ self.logger.debug(_unicode("ACTIONS: sendkey; args: %s")
+ % _unicode(args))
+ seeds = self.seedhandler.load_category(args.category, refresh=True)
+ self.category = args.category
+ results = {}
+ kwargs = self.seedhandler.build_gkeydict(args)
+ keyresults = seeds.list(**kwargs)
+ if keyresults:
+ self.output('', '\n sending keys...')
+ else:
+ return (False, ["Key(s) not found"])
+ for gkey in sorted(keyresults):
+ self.logger.info(_unicode("Sending key %s, %s")
+ % (gkey.nick, gkey.pub_keyid))
+ self.output('', _unicode(" %s: %s")
+ % (gkey.name, ', '.join(gkey.pub_keyid)))
+ self.logger.debug(_unicode("ACTIONS: sendkey; gkey = %s")
+ % _unicode(gkey))
+ results[gkey.keydir] = self.gpg.send_keys(gkey)
+ return (True, ['Completed'])
+
+
+
def listkey(self, args):
'''Pretty-print the selected gpg key'''
# get confirmation
diff --git a/gkeys/gkeys/lib.py b/gkeys/gkeys/lib.py
index 5ad1aab..a8529f4 100644
--- a/gkeys/gkeys/lib.py
+++ b/gkeys/gkeys/lib.py
@@ -273,6 +273,22 @@ class GkeysGPG(GPG):
self.logger.info('GPG return code: ' + str(result.returncode))
return result
+ def send_keys(self, gkey):
+ '''Send gkey to keyserver
+ @param gkey: the gkey to be sent to the server
+ @return: GKEY_CHECK instance
+ '''
+ self.config.defaults['gpg_defaults'].append('--no-permission-warning')
+ self.set_keyserver()
+ self.set_keydir(gkey.keydir, 'send-keys', reset=True)
+ self.set_keyring('pubring.gpg', 'send-keys', reset=False)
+ self.set_keyseedfile(refresh=True)
+ self.logger.debug("LIB: send-keys, gkey: %s" % str(gkey))
+ self.logger.debug("** Calling runGPG with Running 'gpg %s --send-keys' for: %s"
+ % (' '.join(self.config.get_key('tasks', 'send-keys')), str(gkey)))
+ result = self.runGPG(task='send-keys', inputfile='')
+ self.logger.info('GPG return code: ' + str(result.returncode))
+ return result
def check_keys(self, keydir, keyid, result=None):
'''Check specified or all keys based on the seed type
^ permalink raw reply related [flat|nested] 40+ messages in thread
* [gentoo-commits] proj/gentoo-keys:gsoc-2016 commit in: gkeys/gkeys/
@ 2016-12-23 8:37 Brian Dolbec
0 siblings, 0 replies; 40+ messages in thread
From: Brian Dolbec @ 2016-12-23 8:37 UTC (permalink / raw
To: gentoo-commits
commit: 8fea35a1e65ebab3e11245d88c58e08cb84c57a2
Author: aeroniero33 <justthisthing <AT> gmail <DOT> com>
AuthorDate: Sat Aug 27 14:07:07 2016 +0000
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Sat Aug 27 19:42:50 2016 +0000
URL: https://gitweb.gentoo.org/proj/gentoo-keys.git/commit/?id=8fea35a1
Added a mail script that handles the emailing proccess
I created a new file called `mail.py` that handles the email login and the email sending.
gkeys/gkeys/mail.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 51 insertions(+)
diff --git a/gkeys/gkeys/mail.py b/gkeys/gkeys/mail.py
new file mode 100644
index 0000000..df86d11
--- /dev/null
+++ b/gkeys/gkeys/mail.py
@@ -0,0 +1,51 @@
+from __future__ import print_function
+
+import os
+import smtplib
+import sys
+import email.utils
+
+from email.mime.text import MIMEText
+from snakeoil.demandload import demandload
+
+if sys.version_info[0] >= 3:
+ py_input = input
+ _unicode = str
+else:
+ py_input = raw_input
+ _unicode = unicode
+
+demandload(
+ "gkeys.base:Args",
+ "json:load",
+)
+
+class Emailer(object):
+ '''Send an email reminder about the status of the user's GPG key'''
+
+ def __init__(self, login, logger):
+ self.logger = logger
+ self.email_from = _unicode(login['login_email'])
+ self.sender_full_name = _unicode(login['full_name'])
+ login_passwd = login['passwd']
+ server = login['server']
+ self.mail = smtplib.SMTP(server, 587)
+ self.mail.ehlo()
+ self.mail.starttls()
+ self.mail.login(self.email_from, login_passwd)
+ self.logger.debug(_unicode("Login successfull"))
+
+ def send_email(self, uid, message):
+ self.logger.debug(_unicode('Sending email with message %s') % _unicode(message))
+ subject = "Expiring Key"
+ email_to = uid
+ msg = MIMEText(message, 'plain')
+ msg['Subject'] = subject
+ msg['From'] = email.utils.formataddr((self.sender_full_name, self.email_from))
+ msg['To'] = email_to
+ self.logger.info(_unicode('Sending the email reminder from %s to %s') \
+ % (self.email_from, email_to))
+ self.mail.sendmail(self.email_from, email_to, msg.as_string())
+
+ def email_quit(self):
+ self.mail.quit()
^ permalink raw reply related [flat|nested] 40+ messages in thread
* [gentoo-commits] proj/gentoo-keys:gsoc-2016 commit in: gkeys/gkeys/
@ 2016-12-23 8:37 Brian Dolbec
0 siblings, 0 replies; 40+ messages in thread
From: Brian Dolbec @ 2016-12-23 8:37 UTC (permalink / raw
To: gentoo-commits
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:
^ permalink raw reply related [flat|nested] 40+ messages in thread
* [gentoo-commits] proj/gentoo-keys:gsoc-2016 commit in: gkeys/gkeys/
@ 2016-12-23 8:37 Brian Dolbec
0 siblings, 0 replies; 40+ messages in thread
From: Brian Dolbec @ 2016-12-23 8:37 UTC (permalink / raw
To: gentoo-commits
commit: 28641132a19e2870944d74fb5ecb183cfe562387
Author: aeroniero33 <justthisthing <AT> gmail <DOT> com>
AuthorDate: Sat Aug 27 14:05:41 2016 +0000
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Sat Aug 27 19:42:22 2016 +0000
URL: https://gitweb.gentoo.org/proj/gentoo-keys.git/commit/?id=28641132
Added --user and --email args parameters for spec-check
I added 2 `args` parameters called `--email` and `--user` in `base.py`
to be given to spec-check in order for the script to run.
(The `--user` is optional for the user to select with which account to login)
gkeys/gkeys/action_map.py | 2 +-
gkeys/gkeys/base.py | 9 +++++++++
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/gkeys/gkeys/action_map.py b/gkeys/gkeys/action_map.py
index 80c59fe..e4ea412 100644
--- a/gkeys/gkeys/action_map.py
+++ b/gkeys/gkeys/action_map.py
@@ -275,7 +275,7 @@ Do you really want to remove dolsen?[y/n]: y
('spec-check', {
'func': 'speccheck',
'options': ['category', 'nick', 'name', 'fingerprint', 'keyid', 'keys',
- 'keydir', 'keyring'],
+ 'keydir', 'keyring', 'email', 'user'],
'desc': '''Check if keys meet specifications requirements''',
'long_desc': '''Check if keys meet specifications requirements''',
'example': '''$ gkeys spec-check -C gentoo -n gkeys
diff --git a/gkeys/gkeys/base.py b/gkeys/gkeys/base.py
index 9b285e4..a0224c0 100644
--- a/gkeys/gkeys/base.py
+++ b/gkeys/gkeys/base.py
@@ -222,6 +222,15 @@ class CliBase(object):
parser.add_argument('-u', '--uid', dest='uid', nargs='+', default=None,
help='The user ID, gpg key uid')
+ @staticmethod
+ def _option_email(parser=None):
+ parser.add_argument('-E', '--email', dest='email', default=None,
+ help='Email parameter for sending email reminders')
+
+ @staticmethod
+ def _option_user(parser=None):
+ parser.add_argument('-U', '--user', dest='user', default=None,
+ help='User parameter for service login')
def parse_args(self, argv):
'''Parse a list of aruments
^ permalink raw reply related [flat|nested] 40+ messages in thread
* [gentoo-commits] proj/gentoo-keys:gsoc-2016 commit in: gkeys/gkeys/
@ 2016-12-23 8:37 Brian Dolbec
0 siblings, 0 replies; 40+ messages in thread
From: Brian Dolbec @ 2016-12-23 8:37 UTC (permalink / raw
To: gentoo-commits
commit: a537deef9c974b52cec402fc7f0f7cc9401814a2
Author: aeroniero33 <justthisthing <AT> gmail <DOT> com>
AuthorDate: Sat Jun 18 16:59:58 2016 +0000
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Fri Dec 23 07:36:42 2016 +0000
URL: https://gitweb.gentoo.org/proj/gentoo-keys.git/commit/?id=a537deef
Fixed a bug in the verify function
gkeys/gkeys/actions.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/gkeys/gkeys/actions.py b/gkeys/gkeys/actions.py
index 849568d..6ce4199 100644
--- a/gkeys/gkeys/actions.py
+++ b/gkeys/gkeys/actions.py
@@ -746,7 +746,6 @@ class Actions(ActionBase):
messages.append(_unicode("Using config defaults..: %s %s")
% (args.category, args.nick))
return self.verify(args, messages)
-
return self._verify(args, key, messages)
@@ -833,6 +832,8 @@ class Actions(ActionBase):
break
else:
sig_path = None
+ elif signature:
+ sig_path = os.path.abspath(signature)
self.logger.info("Verifying file...")
verified = False
results = self.gpg.verify_file(key, sig_path, filepath)
^ permalink raw reply related [flat|nested] 40+ messages in thread
* [gentoo-commits] proj/gentoo-keys:gsoc-2016 commit in: gkeys/gkeys/
@ 2016-12-23 8:37 Brian Dolbec
0 siblings, 0 replies; 40+ messages in thread
From: Brian Dolbec @ 2016-12-23 8:37 UTC (permalink / raw
To: gentoo-commits
commit: 693f78919985b86620bc76ba80926edeeae0b91b
Author: aeroniero33 <justthisthing <AT> gmail <DOT> com>
AuthorDate: Sat Aug 27 14:22:28 2016 +0000
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Sat Aug 27 19:43:12 2016 +0000
URL: https://gitweb.gentoo.org/proj/gentoo-keys.git/commit/?id=693f7891
Added some util methods in keyhandler
The methods are:
is_expiring that checks if a key is expiring or has recently expired
set_template that reads the template file and returns it as a string
generate_template that substitutes the key prints in the template
find_email that extracts the correct email address from the key uid
gkeys/gkeys/keyhandler.py | 42 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/gkeys/gkeys/keyhandler.py b/gkeys/gkeys/keyhandler.py
index 9043fcd..0a02c22 100644
--- a/gkeys/gkeys/keyhandler.py
+++ b/gkeys/gkeys/keyhandler.py
@@ -11,6 +11,9 @@
"""
import os
import sys
+import re
+
+from string import Template
from snakeoil.demandload import demandload
@@ -108,3 +111,42 @@ class KeyHandler(object):
self.logger.debug(_unicode("KeyHandler: key_search; keys = %s") % str(keys))
return keys
+
+ @staticmethod
+ def is_expiring(keys, days_limit=30):
+ '''Check if any of the keys is within the days_limit'''
+ is_exp = False
+ for key in keys:
+ for specs in keys[key]:
+ if specs.days > days_limit*(-1) and specs.days < days_limit:
+ is_exp = True
+ break
+ return is_exp
+
+ @staticmethod
+ def set_template(template_path):
+ '''Read the template file and returns the template message'''
+ with open(template_path, 'r') as file_contents:
+ content = file_contents.read()
+ message_template = Template(content)
+ return message_template
+
+ @staticmethod
+ def generate_template(message_template, keyprints, specprint):
+ '''Substitute the print variables in the template'''
+ message = message_template.substitute(key_print=keyprints, spec_print=specprint)
+ return message
+
+ @staticmethod
+ def find_email(uids, prefered_address=None):
+ '''Find the email address from the uid by prioritizing the prefered address'''
+ if type(prefered_address) is not str:
+ uids = [uids[0]]
+ for uid in uids:
+ match = re.findall(r'[\w\.-]+@[\w\.-]+', uid)
+ uid = ''
+ if match:
+ uid = match[0]
+ if prefered_address and uid.endswith(prefered_address):
+ return uid
+ return uid
^ permalink raw reply related [flat|nested] 40+ messages in thread
* [gentoo-commits] proj/gentoo-keys:gsoc-2016 commit in: gkeys/gkeys/
@ 2016-12-23 8:37 Brian Dolbec
0 siblings, 0 replies; 40+ messages in thread
From: Brian Dolbec @ 2016-12-23 8:37 UTC (permalink / raw
To: gentoo-commits
commit: 7a71c6c119bd628316685cbe1705be4e5fbf08d1
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Thu Oct 27 21:48:07 2016 +0000
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Fri Dec 23 08:36:24 2016 +0000
URL: https://gitweb.gentoo.org/proj/gentoo-keys.git/commit/?id=7a71c6c1
Actions._verify: support --signature path argument
If the --signature argument refers to an existing file path,
use it. This fixes an issue where signature verification would
fail because the sig_path variable referred to None.
gkeys/gkeys/actions.py | 2 ++
1 file changed, 2 insertions(+)
diff --git a/gkeys/gkeys/actions.py b/gkeys/gkeys/actions.py
index 8ed126e..60cfd6d 100644
--- a/gkeys/gkeys/actions.py
+++ b/gkeys/gkeys/actions.py
@@ -862,6 +862,8 @@ class Actions(ActionBase):
break
else:
signature = None
+ elif signature is not None and os.path.exists(signature):
+ sig_path = signature
else:
filepath = os.path.abspath(filepath)
self.logger.debug(
^ permalink raw reply related [flat|nested] 40+ messages in thread
* [gentoo-commits] proj/gentoo-keys:gsoc-2016 commit in: gkeys/gkeys/
@ 2016-12-23 8:37 Brian Dolbec
0 siblings, 0 replies; 40+ messages in thread
From: Brian Dolbec @ 2016-12-23 8:37 UTC (permalink / raw
To: gentoo-commits
commit: 62dddedd384f5251b36636ff12927784b7cdf5b3
Author: aeroniero33 <justthisthing <AT> gmail <DOT> com>
AuthorDate: Thu Jun 9 22:44:16 2016 +0000
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Fri Dec 23 07:42:27 2016 +0000
URL: https://gitweb.gentoo.org/proj/gentoo-keys.git/commit/?id=62dddedd
Created the update-seed function
gkeys/gkeys/action_map.py | 19 ++++++++++++++++++-
gkeys/gkeys/actions.py | 14 +++++++++++++-
2 files changed, 31 insertions(+), 2 deletions(-)
diff --git a/gkeys/gkeys/action_map.py b/gkeys/gkeys/action_map.py
index f372a5c..1bd0625 100644
--- a/gkeys/gkeys/action_map.py
+++ b/gkeys/gkeys/action_map.py
@@ -15,7 +15,8 @@ from collections import OrderedDict
Seed_Actions = ['----seeds----', 'add-seed', 'fetch-seed',
- 'list-seed', 'list-seedfiles', 'move-seed', 'remove-seed']
+ 'update-seed', 'list-seed', 'list-seedfiles', 'move-seed',
+ 'remove-seed']
Key_Actions = ['----keys-----', 'check-key', 'installed',
'install-key', 'list-key', 'send-key', 'refresh-key', 'remove-key',
@@ -380,6 +381,22 @@ Found Failures:
Fetch operation completed
''',
}),
+ ('update-seed', {
+ 'func': 'updateseed',
+ 'options': ['category', 'nick', '1file', 'dest', 'signature',
+ 'timestamp'],
+ 'desc': '''Update the selected seed file(s)''',
+ 'long_desc': '''Update the selected seed file(s)''',
+ 'example': '''$ gkeys update-seed -C gentoo-devs
+
+ Gkey task results:
+ Verification succeeded.: /home/brian/gpg-test/seeds/gentoo-devs.seeds
+ Key info...............: Gentoo-Linux Gentoo-keys Project Signing Key <gkeys>, 0xA41DBBD9151C3FC7
+ category, nick.....: gentoo gkeys
+
+ Update operation completed
+''',
+ }),
('list-seed', {
'func': 'listseed',
'options': ['category', 'nick', 'name', 'fingerprint', 'keys',
diff --git a/gkeys/gkeys/actions.py b/gkeys/gkeys/actions.py
index 6ce4199..0720079 100644
--- a/gkeys/gkeys/actions.py
+++ b/gkeys/gkeys/actions.py
@@ -95,7 +95,19 @@ class Actions(ActionBase):
messages.append("")
messages.append("Fetch operation completed")
return (False not in success, messages)
-
+
+ def updateseed(self, args):
+ '''Updates seeds of a selected file'''
+ self.logger.debug(_unicode("ACTIONS: updateseed; args: %s")
+ % _unicode(args))
+ fetch_success, fetch_messages = self.fetchseed(args)
+ if fetch_success is not True:
+ return (False, fetch_messages)
+ install_success, install_messages = self.installkey(args)
+ if install_success is not True:
+ return (False, install_messages)
+ messages = fetch_messages + [install_messages]
+ return (True, messages)
def addseed(self, args):
'''Add or replace a key in the selected seed file'''
^ permalink raw reply related [flat|nested] 40+ messages in thread
* [gentoo-commits] proj/gentoo-keys:gsoc-2016 commit in: gkeys/gkeys/
@ 2016-12-23 8:37 Brian Dolbec
0 siblings, 0 replies; 40+ messages in thread
From: Brian Dolbec @ 2016-12-23 8:37 UTC (permalink / raw
To: gentoo-commits
commit: 575b6441a5554c977534a41242be0b552fef0a85
Author: aeroniero33 <justthisthing <AT> gmail <DOT> com>
AuthorDate: Sun Jun 12 14:19:35 2016 +0000
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Fri Dec 23 07:50:05 2016 +0000
URL: https://gitweb.gentoo.org/proj/gentoo-keys.git/commit/?id=575b6441
gkeys/actions: Update the update-seed function
Update descriptions.
Update operations to current library code usage.
<rebase edit>
Replace print() use with self.output(). Expand commit message
</edit Brian Dolbec>
gkeys/gkeys/action_map.py | 7 ++++---
gkeys/gkeys/actions.py | 41 +++++++++++++++++++++++++++++++----------
2 files changed, 35 insertions(+), 13 deletions(-)
diff --git a/gkeys/gkeys/action_map.py b/gkeys/gkeys/action_map.py
index 1bd0625..5433297 100644
--- a/gkeys/gkeys/action_map.py
+++ b/gkeys/gkeys/action_map.py
@@ -385,8 +385,8 @@ Found Failures:
'func': 'updateseed',
'options': ['category', 'nick', '1file', 'dest', 'signature',
'timestamp'],
- 'desc': '''Update the selected seed file(s)''',
- 'long_desc': '''Update the selected seed file(s)''',
+ 'desc': '''Update the selected seed file(s) or all categories if no arguments are given''',
+ 'long_desc': '''Update the selected seed file(s) or all categories if no arguments are given''',
'example': '''$ gkeys update-seed -C gentoo-devs
Gkey task results:
@@ -394,7 +394,8 @@ Found Failures:
Key info...............: Gentoo-Linux Gentoo-keys Project Signing Key <gkeys>, 0xA41DBBD9151C3FC7
category, nick.....: gentoo gkeys
- Update operation completed
+ Fetch operation completed
+ Completed
''',
}),
('list-seed', {
diff --git a/gkeys/gkeys/actions.py b/gkeys/gkeys/actions.py
index 0720079..3ff8d8e 100644
--- a/gkeys/gkeys/actions.py
+++ b/gkeys/gkeys/actions.py
@@ -1,4 +1,4 @@
-#
+
#-*- coding:utf-8 -*-
"""
@@ -95,19 +95,41 @@ class Actions(ActionBase):
messages.append("")
messages.append("Fetch operation completed")
return (False not in success, messages)
-
+
def updateseed(self, args):
- '''Updates seeds of a selected file'''
+ '''Updates seeds of a selected file or all categories if no args are given'''
self.logger.debug(_unicode("ACTIONS: updateseed; args: %s")
% _unicode(args))
+ messages = []
+ success = True
+ if not args.category:
+ '''Update all available categories'''
+ seed_categories = list(self.config.defaults['seeds'])
+ category_msgs = []
+ for seed_category in seed_categories:
+ self.seeds = None
+ custom_args = args
+ custom_args.category = seed_category
+ category_success, messages = self.updateseed(custom_args)
+ category_msgs.extend(messages)
+ return (True, category_msgs)
+ self.output('', "Fetching seeds for %s category.\n" %args.category)
fetch_success, fetch_messages = self.fetchseed(args)
if fetch_success is not True:
- return (False, fetch_messages)
- install_success, install_messages = self.installkey(args)
- if install_success is not True:
- return (False, install_messages)
- messages = fetch_messages + [install_messages]
- return (True, messages)
+ success = False
+ messages = fetch_messages
+ self.output('', "Fetch failed.\n")
+ else:
+ self.output('', "Fetch succeeded.\n")
+ self.output('', "Installing or Refreshing keys for %s category." %args.category)
+ install_success, install_messages = self.installkey(args)
+ if install_success is not True:
+ self.output('', "Update failed.\n")
+ success = False
+ else:
+ self.output('', "Update succeeded.\n")
+ messages = fetch_messages + ["Update operation:"] + [install_messages]
+ return (success, messages)
def addseed(self, args):
'''Add or replace a key in the selected seed file'''
@@ -311,7 +333,6 @@ class Actions(ActionBase):
self.gpg.set_keydir(gkey.keydir, "recv-keys")
self.gpg.set_keyseedfile()
seeds = self.gpg.seedfile.seeds
- #print(seeds)
if seeds:
self.logger.debug("ACTIONS: installkey; found installed seeds:"
"\n %s" % seeds)
^ permalink raw reply related [flat|nested] 40+ messages in thread
* [gentoo-commits] proj/gentoo-keys:gsoc-2016 commit in: gkeys/gkeys/
@ 2016-12-23 8:37 Brian Dolbec
0 siblings, 0 replies; 40+ messages in thread
From: Brian Dolbec @ 2016-12-23 8:37 UTC (permalink / raw
To: gentoo-commits
commit: e2676812145dea4cf8b0e7bb33238b92340045d2
Author: aeroniero33 <justthisthing <AT> gmail <DOT> com>
AuthorDate: Fri Jun 17 17:40:01 2016 +0000
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Fri Dec 23 08:36:16 2016 +0000
URL: https://gitweb.gentoo.org/proj/gentoo-keys.git/commit/?id=e2676812
gkeys actions: Added automatic seeds,keys update capability
Add more detailed update reporting including the keys removed,
revoked/changed, added.
<rebase edit>
Convert print() to proper self.output()
Whitespace cleanup
Commit message improvements
</edit Brian Dolbec>
gkeys/gkeys/actions.py | 20 +++++++-------
gkeys/gkeys/base.py | 68 +++++++++++++++++++++++++++++++++++++++++++++-
gkeys/gkeys/seedhandler.py | 9 +++++-
3 files changed, 85 insertions(+), 12 deletions(-)
diff --git a/gkeys/gkeys/actions.py b/gkeys/gkeys/actions.py
index 45f9a96..003a4e3 100644
--- a/gkeys/gkeys/actions.py
+++ b/gkeys/gkeys/actions.py
@@ -132,19 +132,19 @@ class Actions(ActionBase):
self.output('', "Update succeeded.\n")
messages = fetch_messages + [" Update operation:"] + [install_messages]
success, new_gkeys = self.listseed(args)
- added_gkeys, changed_gkeys = self.seedhandler.compare_seeds(old_gkeys, new_gkeys)
- self.output('', "Updated revoked GKeys:")
- if changed_gkeys:
- for gkey in changed_gkeys:
- self.output(['', changed_gkeys])
+ added_gkeys, changed_gkeys, removed_gkeys = self.seedhandler.compare_seeds(old_gkeys, new_gkeys)
+ for gkey in changed_gkeys:
+ self.output([changed_gkeys], "Updated or revoked GKeys:")
else:
- self.output('', "No GKeys were revoked")
- self.output('', "Added GKeys:")
- if added_gkeys:
- for gkey in added_gkeys:
- self.output(['', added_gkeys])
+ self.output('', "No GKeys were updated or revoked")
+ for gkey in added_gkeys:
+ self.output([added_gkeys], "Added GKeys:")
else:
self.output('', "No GKeys were added")
+ for gkey in removed_gkeys:
+ self.output([removed_gkeys], "Removed GKeys:")
+ else:
+ self.output('', "No GKeys were removed")
return (success, messages)
def addseed(self, args):
diff --git a/gkeys/gkeys/base.py b/gkeys/gkeys/base.py
index a0224c0..28dd0b2 100644
--- a/gkeys/gkeys/base.py
+++ b/gkeys/gkeys/base.py
@@ -17,10 +17,20 @@ from __future__ import print_function
import argparse
import os
import sys
+import copy
from gkeys.fileops import ensure_dirs
from gkeys.log import log_levels, set_logger
+from gkeys.gkey import GKEY
+if sys.version_info[0] >= 3:
+ from urllib.request import urlopen
+ py_input = input
+ _unicode = str
+else:
+ from urllib2 import urlopen
+ py_input = raw_input
+ _unicode = unicode
if sys.version_info[0] >= 3:
unicode = str
@@ -291,6 +301,10 @@ class CliBase(object):
for opt in options:
getattr(self, '_option_%s' % opt)(parser)
+ def warning_output(self, info):
+ ''' We don't want this message to be spammed 4 times everytime gkeys is run'''
+ if "Re-fetch cycle timeout of" not in info:
+ print(info)
def setup(self, args, configs):
'''Set up the args and configs passed in
@@ -352,7 +366,59 @@ class CliBase(object):
'''
# establish our actions instance
self.actions = self.cli_config['Actions'](self.config, self.output_results, self.logger)
-
+ # check for seed update
+ from sslfetch.connections import Connector
+ connector_output = {
+ 'info': self.logger.info,
+ 'debug': self.logger.debug,
+ 'error': self.logger.error,
+ 'exception': self.logger.exception,
+ 'warning': self.warning_output,
+ 'kwargs-info': {},
+ 'kwargs-debug': {},
+ 'kwargs-error': {},
+ 'kwargs-exception': {},
+ 'kwargs-warning': {},
+ }
+ fetcher = Connector(connector_output, None, "Gentoo Keys")
+ successes = []
+ up_to_date = True
+ categories = list(self.config.defaults['seeds'])
+ '''Attemp to download seed and seed.sig files for each available category'''
+ for category in categories:
+ filepath = self.config.defaults['seedsdir'] + "/" + category + ".seeds"
+ timestamp_path = filepath + ".timestamp"
+ url = self.config.defaults['seedurls'][category]
+ success, signedfile, timestamp = fetcher.fetch_file(
+ url, filepath, timestamp_path)
+ if timestamp != "":
+ up_to_date = False
+ successes.append(success)
+ url += ".sig"
+ filepath += ".sig"
+ success, signedfile, timestamp = fetcher.fetch_file(
+ url, filepath, timestamp_path)
+ if timestamp != "":
+ up_to_date = False
+ successes.append(success)
+ if False not in successes and not up_to_date:
+ print("Seeds need to be updated")
+ ack = None
+ while ack not in ("y", "yes", "n", "no"):
+ ack = py_input("Would you like to update the seeds now? (y/n) ").lower()
+ if ack in ("y", "yes"):
+ custom_args = copy.copy(args)
+ for attr in GKEY._fields:
+ if attr != "debug":
+ custom_args.attr = None
+ custom_args.category = None
+ custom_args.action = "update-seed"
+ print("Updating seeds")
+ self.run(custom_args)
+ elif False not in successes:
+ print("Seeds are up to date")
+ else:
+ print("Seed update check failed, check your internet connection.")
# run the action
func = getattr(self.actions, '%s'
% self.cli_config['Action_Map'][args.action]['func'])
diff --git a/gkeys/gkeys/seedhandler.py b/gkeys/gkeys/seedhandler.py
index c7dad2e..90ce583 100644
--- a/gkeys/gkeys/seedhandler.py
+++ b/gkeys/gkeys/seedhandler.py
@@ -78,21 +78,28 @@ class SeedHandler(object):
@param seeds2: set of seeds to be compared
@return added_gkeys: list of keys that are included in seed2 but not seed1
@return changed_gkeys: list of keys that are included in seed1 and seed2 but have been altered
+ @return removed_gkeys: list of keys that are included in seed1 but not in seed2
'''
old_gkeys = seeds1[1]
new_gkeys = seeds2[1]
changed_gkeys = []
+ old_changed_gkeys = []
+ removed_gkeys = []
added_gkeys = []
if old_gkeys:
for new_gkey in new_gkeys:
for old_gkey in old_gkeys:
if new_gkey.nick == old_gkey.nick and new_gkey != old_gkey:
changed_gkeys.append(new_gkey)
+ old_changed_gkeys.append(old_gkey)
if new_gkey not in old_gkeys and new_gkey not in changed_gkeys:
added_gkeys.append(new_gkey)
+ for old_gkey in old_gkeys:
+ if old_gkey not in new_gkeys and old_gkey not in old_changed_gkeys:
+ removed_gkeys.append(old_gkey)
else:
added_gkeys = new_gkeys
- return(added_gkeys, changed_gkeys)
+ return(added_gkeys, changed_gkeys, removed_gkeys)
def load_seeds(self, seedfile=None, filepath=None, refresh=False):
'''Load seed file
^ permalink raw reply related [flat|nested] 40+ messages in thread
* [gentoo-commits] proj/gentoo-keys:gsoc-2016 commit in: gkeys/gkeys/
@ 2016-12-23 8:37 Brian Dolbec
0 siblings, 0 replies; 40+ messages in thread
From: Brian Dolbec @ 2016-12-23 8:37 UTC (permalink / raw
To: gentoo-commits
commit: 1415f748cd720d83c2dc91de6f542390bd1ebb1e
Author: Pavlos Ratis <dastergon <AT> dastergon <DOT> gr>
AuthorDate: Sun Aug 28 18:02:54 2016 +0000
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Fri Dec 23 08:36:24 2016 +0000
URL: https://gitweb.gentoo.org/proj/gentoo-keys.git/commit/?id=1415f748
remove debug print
gkeys/gkeys/actions.py | 1 -
1 file changed, 1 deletion(-)
diff --git a/gkeys/gkeys/actions.py b/gkeys/gkeys/actions.py
index 003a4e3..1533786 100644
--- a/gkeys/gkeys/actions.py
+++ b/gkeys/gkeys/actions.py
@@ -644,7 +644,6 @@ class Actions(ActionBase):
keyresults = seeds.list(**kwargs)
self.output('', '\n Removing keys...')
success = True
- #print(keyresults)
for gkey in sorted(keyresults):
if kwargs['nick'] != '*' and kwargs['nick'] not in gkey.nick:
messages.append(_unicode("%s does not seem to be a valid key.")
^ permalink raw reply related [flat|nested] 40+ messages in thread
* [gentoo-commits] proj/gentoo-keys:gsoc-2016 commit in: gkeys/gkeys/
@ 2016-12-23 8:37 Brian Dolbec
0 siblings, 0 replies; 40+ messages in thread
From: Brian Dolbec @ 2016-12-23 8:37 UTC (permalink / raw
To: gentoo-commits
commit: 70cbc642f07bb8ed08c851ba2749606a8e0e604a
Author: aeroniero33 <justthisthing <AT> gmail <DOT> com>
AuthorDate: Tue Jun 14 20:24:08 2016 +0000
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Fri Dec 23 08:02:12 2016 +0000
URL: https://gitweb.gentoo.org/proj/gentoo-keys.git/commit/?id=70cbc642
gkeys actions: Add keys updated reporting
Report the updated/revoked keys during the update.
<rebase edit>
Replace print() with self.output()
Whitespace cleanup
Create a meaningful commit message
</edit Brian Dolbec>
gkeys/gkeys/actions.py | 18 +++++++++++++++++-
gkeys/gkeys/seedhandler.py | 23 +++++++++++++++++++++++
2 files changed, 40 insertions(+), 1 deletion(-)
diff --git a/gkeys/gkeys/actions.py b/gkeys/gkeys/actions.py
index 3ff8d8e..45f9a96 100644
--- a/gkeys/gkeys/actions.py
+++ b/gkeys/gkeys/actions.py
@@ -114,7 +114,9 @@ class Actions(ActionBase):
category_msgs.extend(messages)
return (True, category_msgs)
self.output('', "Fetching seeds for %s category.\n" %args.category)
+ success, old_gkeys = self.listseed(args)
fetch_success, fetch_messages = self.fetchseed(args)
+ self.seeds = None
if fetch_success is not True:
success = False
messages = fetch_messages
@@ -128,7 +130,21 @@ class Actions(ActionBase):
success = False
else:
self.output('', "Update succeeded.\n")
- messages = fetch_messages + ["Update operation:"] + [install_messages]
+ messages = fetch_messages + [" Update operation:"] + [install_messages]
+ success, new_gkeys = self.listseed(args)
+ added_gkeys, changed_gkeys = self.seedhandler.compare_seeds(old_gkeys, new_gkeys)
+ self.output('', "Updated revoked GKeys:")
+ if changed_gkeys:
+ for gkey in changed_gkeys:
+ self.output(['', changed_gkeys])
+ else:
+ self.output('', "No GKeys were revoked")
+ self.output('', "Added GKeys:")
+ if added_gkeys:
+ for gkey in added_gkeys:
+ self.output(['', added_gkeys])
+ else:
+ self.output('', "No GKeys were added")
return (success, messages)
def addseed(self, args):
diff --git a/gkeys/gkeys/seedhandler.py b/gkeys/gkeys/seedhandler.py
index de2a6ad..c7dad2e 100644
--- a/gkeys/gkeys/seedhandler.py
+++ b/gkeys/gkeys/seedhandler.py
@@ -71,6 +71,29 @@ class SeedHandler(object):
keyinfo[attr] = None
return keyinfo
+ def compare_seeds(self, seeds1, seeds2) :
+ '''Compares two seed lists and returns the differences
+
+ @param seeds1: set of seeds to be compared
+ @param seeds2: set of seeds to be compared
+ @return added_gkeys: list of keys that are included in seed2 but not seed1
+ @return changed_gkeys: list of keys that are included in seed1 and seed2 but have been altered
+ '''
+ old_gkeys = seeds1[1]
+ new_gkeys = seeds2[1]
+ changed_gkeys = []
+ added_gkeys = []
+ if old_gkeys:
+ for new_gkey in new_gkeys:
+ for old_gkey in old_gkeys:
+ if new_gkey.nick == old_gkey.nick and new_gkey != old_gkey:
+ changed_gkeys.append(new_gkey)
+ if new_gkey not in old_gkeys and new_gkey not in changed_gkeys:
+ added_gkeys.append(new_gkey)
+ else:
+ added_gkeys = new_gkeys
+ return(added_gkeys, changed_gkeys)
+
def load_seeds(self, seedfile=None, filepath=None, refresh=False):
'''Load seed file
^ permalink raw reply related [flat|nested] 40+ messages in thread
* [gentoo-commits] proj/gentoo-keys:gsoc-2016 commit in: gkeys/gkeys/
@ 2016-12-23 8:37 Brian Dolbec
0 siblings, 0 replies; 40+ messages in thread
From: Brian Dolbec @ 2016-12-23 8:37 UTC (permalink / raw
To: gentoo-commits
commit: 9fdac1a9270a9d63ef76557c56006abacc45ce28
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Mon Oct 24 05:45:59 2016 +0000
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Fri Dec 23 08:36:24 2016 +0000
URL: https://gitweb.gentoo.org/proj/gentoo-keys.git/commit/?id=9fdac1a9
Actions.checkkey: fix success returncode
The failed dictionary contains lists for each type of failure,
so return success if all of those lists are emtpy.
gkeys/gkeys/actions.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/gkeys/gkeys/actions.py b/gkeys/gkeys/actions.py
index 1533786..8ed126e 100644
--- a/gkeys/gkeys/actions.py
+++ b/gkeys/gkeys/actions.py
@@ -13,6 +13,7 @@
from __future__ import print_function
+import itertools
import os
import sys
@@ -437,7 +438,7 @@ class Actions(ActionBase):
self.output([failed['invalid']], '\n Invalid keys:\n')
if failed['sign']:
self.output([failed['sign']], '\n No signing capable subkeys:\n')
- return (len(failed) <1,
+ return (not any(itertools.chain.from_iterable(failed.values())),
['\nFound:\n-------', 'Expired: %d' % len(failed['expired']),
'Revoked: %d' % len(failed['revoked']),
'Invalid: %d' % len(failed['invalid']),
^ permalink raw reply related [flat|nested] 40+ messages in thread
* [gentoo-commits] proj/gentoo-keys:gsoc-2016 commit in: gkeys/gkeys/
@ 2016-12-24 9:13 Brian Dolbec
0 siblings, 0 replies; 40+ messages in thread
From: Brian Dolbec @ 2016-12-24 9:13 UTC (permalink / raw
To: gentoo-commits
commit: cc14fb9350cbfea5d07564bee963d9dc60b94239
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Thu Oct 27 21:48:07 2016 +0000
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Thu Oct 27 21:49:01 2016 +0000
URL: https://gitweb.gentoo.org/proj/gentoo-keys.git/commit/?id=cc14fb93
Actions._verify: support --signature path argument
If the --signature argument refers to an existing file path,
use it. This fixes an issue where signature verification would
fail because the sig_path variable referred to None.
gkeys/gkeys/actions.py | 2 ++
1 file changed, 2 insertions(+)
diff --git a/gkeys/gkeys/actions.py b/gkeys/gkeys/actions.py
index d51fb3f..b38db19 100644
--- a/gkeys/gkeys/actions.py
+++ b/gkeys/gkeys/actions.py
@@ -758,6 +758,8 @@ class Actions(ActionBase):
break
else:
signature = None
+ elif signature is not None and os.path.exists(signature):
+ sig_path = signature
else:
filepath = os.path.abspath(filepath)
self.logger.debug(
^ permalink raw reply related [flat|nested] 40+ messages in thread
* [gentoo-commits] proj/gentoo-keys:gsoc-2016 commit in: gkeys/gkeys/
@ 2016-12-24 9:13 Brian Dolbec
0 siblings, 0 replies; 40+ messages in thread
From: Brian Dolbec @ 2016-12-24 9:13 UTC (permalink / raw
To: gentoo-commits
commit: db9c5818bdf1623bdb96a2656e9f2d7d3985eed3
Author: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Sat Dec 24 00:35:11 2016 +0000
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Sat Dec 24 00:35:11 2016 +0000
URL: https://gitweb.gentoo.org/proj/gentoo-keys.git/commit/?id=db9c5818
gkeys actions: Fix missing category errors for sign action
gkeys/gkeys/actions.py | 2 ++
1 file changed, 2 insertions(+)
diff --git a/gkeys/gkeys/actions.py b/gkeys/gkeys/actions.py
index b38db19..07dba7a 100644
--- a/gkeys/gkeys/actions.py
+++ b/gkeys/gkeys/actions.py
@@ -830,8 +830,10 @@ class Actions(ActionBase):
nicks = [args.nick]
else:
nicks = args.nick
+ args.category = 'sign'
# load our installed signing keys db
self.seeds = self.seedhandler.load_category('sign', nicks)
+ self.category = args.category
if not self.seeds.seeds:
return (False, ['No installed keys, try installkey action.', ''])
keydir = self.config.get_key("sign", "keydir")
^ permalink raw reply related [flat|nested] 40+ messages in thread
* [gentoo-commits] proj/gentoo-keys:gsoc-2016 commit in: gkeys/gkeys/
@ 2016-12-24 9:13 Brian Dolbec
0 siblings, 0 replies; 40+ messages in thread
From: Brian Dolbec @ 2016-12-24 9:13 UTC (permalink / raw
To: gentoo-commits
commit: 961f66af2d741386bc917de569153863e086732a
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Mon Oct 24 05:45:59 2016 +0000
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Mon Oct 24 05:58:34 2016 +0000
URL: https://gitweb.gentoo.org/proj/gentoo-keys.git/commit/?id=961f66af
Actions.checkkey: fix success returncode
The failed dictionary contains lists for each type of failure,
so return success if all of those lists are emtpy.
gkeys/gkeys/actions.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/gkeys/gkeys/actions.py b/gkeys/gkeys/actions.py
index 1b27605..d51fb3f 100644
--- a/gkeys/gkeys/actions.py
+++ b/gkeys/gkeys/actions.py
@@ -13,6 +13,7 @@
from __future__ import print_function
+import itertools
import os
import sys
@@ -360,7 +361,7 @@ class Actions(ActionBase):
self.output([failed['invalid']], '\n Invalid keys:\n')
if failed['sign']:
self.output([failed['sign']], '\n No signing capable subkeys:\n')
- return (len(failed) <1,
+ return (not any(itertools.chain.from_iterable(failed.values())),
['\nFound:\n-------', 'Expired: %d' % len(failed['expired']),
'Revoked: %d' % len(failed['revoked']),
'Invalid: %d' % len(failed['invalid']),
^ permalink raw reply related [flat|nested] 40+ messages in thread
* [gentoo-commits] proj/gentoo-keys:gsoc-2016 commit in: gkeys/gkeys/
@ 2016-12-24 9:13 Brian Dolbec
0 siblings, 0 replies; 40+ messages in thread
From: Brian Dolbec @ 2016-12-24 9:13 UTC (permalink / raw
To: gentoo-commits
commit: e8ce76d53d90ae04589270b37a1a1a19517c2448
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: 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.
<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 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:
^ permalink raw reply related [flat|nested] 40+ messages in thread
* [gentoo-commits] proj/gentoo-keys:gsoc-2016 commit in: gkeys/gkeys/
@ 2016-12-24 9:13 Brian Dolbec
0 siblings, 0 replies; 40+ messages in thread
From: Brian Dolbec @ 2016-12-24 9:13 UTC (permalink / raw
To: gentoo-commits
commit: 22e10d7e51ca47ad4808f9998c2bf70410557bb3
Author: aeroniero33 <justthisthing <AT> gmail <DOT> com>
AuthorDate: Sat Jun 18 16:59:58 2016 +0000
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Sat Dec 24 04:54:15 2016 +0000
URL: https://gitweb.gentoo.org/proj/gentoo-keys.git/commit/?id=22e10d7e
Fixed a bug in the verify function
gkeys/gkeys/actions.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/gkeys/gkeys/actions.py b/gkeys/gkeys/actions.py
index 9dc69f0..3070eb3 100644
--- a/gkeys/gkeys/actions.py
+++ b/gkeys/gkeys/actions.py
@@ -749,7 +749,6 @@ class Actions(ActionBase):
messages.append(_unicode("Using config defaults..: %s %s")
% (args.category, args.nick))
return self.verify(args, messages)
-
return self._verify(args, key, messages)
@@ -838,6 +837,8 @@ class Actions(ActionBase):
break
else:
sig_path = None
+ elif signature:
+ sig_path = os.path.abspath(signature)
self.logger.info("Verifying file...")
verified = False
results = self.gpg.verify_file(key, sig_path, filepath)
^ permalink raw reply related [flat|nested] 40+ messages in thread
* [gentoo-commits] proj/gentoo-keys:gsoc-2016 commit in: gkeys/gkeys/
@ 2016-12-24 9:13 Brian Dolbec
0 siblings, 0 replies; 40+ messages in thread
From: Brian Dolbec @ 2016-12-24 9:13 UTC (permalink / raw
To: gentoo-commits
commit: 70cb948e5d68bfe0cb0c05b5e5518b2815e68d3f
Author: aeroniero33 <justthisthing <AT> gmail <DOT> com>
AuthorDate: Sun Jun 12 14:19:35 2016 +0000
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Sat Dec 24 04:54:15 2016 +0000
URL: https://gitweb.gentoo.org/proj/gentoo-keys.git/commit/?id=70cb948e
gkeys/actions: Update the update-seed function
Update descriptions.
Update operations to current library code usage.
<rebase edit>
Replace print() use with self.output(). Expand commit message
</edit Brian Dolbec>
gkeys/gkeys/action_map.py | 7 ++++---
gkeys/gkeys/actions.py | 41 +++++++++++++++++++++++++++++++----------
2 files changed, 35 insertions(+), 13 deletions(-)
diff --git a/gkeys/gkeys/action_map.py b/gkeys/gkeys/action_map.py
index 1bd0625..5433297 100644
--- a/gkeys/gkeys/action_map.py
+++ b/gkeys/gkeys/action_map.py
@@ -385,8 +385,8 @@ Found Failures:
'func': 'updateseed',
'options': ['category', 'nick', '1file', 'dest', 'signature',
'timestamp'],
- 'desc': '''Update the selected seed file(s)''',
- 'long_desc': '''Update the selected seed file(s)''',
+ 'desc': '''Update the selected seed file(s) or all categories if no arguments are given''',
+ 'long_desc': '''Update the selected seed file(s) or all categories if no arguments are given''',
'example': '''$ gkeys update-seed -C gentoo-devs
Gkey task results:
@@ -394,7 +394,8 @@ Found Failures:
Key info...............: Gentoo-Linux Gentoo-keys Project Signing Key <gkeys>, 0xA41DBBD9151C3FC7
category, nick.....: gentoo gkeys
- Update operation completed
+ Fetch operation completed
+ Completed
''',
}),
('list-seed', {
diff --git a/gkeys/gkeys/actions.py b/gkeys/gkeys/actions.py
index c218d8d..3d0399a 100644
--- a/gkeys/gkeys/actions.py
+++ b/gkeys/gkeys/actions.py
@@ -1,4 +1,4 @@
-#
+
#-*- coding:utf-8 -*-
"""
@@ -96,19 +96,41 @@ class Actions(ActionBase):
messages.append("")
messages.append("Fetch operation completed")
return (False not in success, messages)
-
+
def updateseed(self, args):
- '''Updates seeds of a selected file'''
+ '''Updates seeds of a selected file or all categories if no args are given'''
self.logger.debug(_unicode("ACTIONS: updateseed; args: %s")
% _unicode(args))
+ messages = []
+ success = True
+ if not args.category:
+ '''Update all available categories'''
+ seed_categories = list(self.config.defaults['seeds'])
+ category_msgs = []
+ for seed_category in seed_categories:
+ self.seeds = None
+ custom_args = args
+ custom_args.category = seed_category
+ category_success, messages = self.updateseed(custom_args)
+ category_msgs.extend(messages)
+ return (True, category_msgs)
+ self.output('', "Fetching seeds for %s category.\n" %args.category)
fetch_success, fetch_messages = self.fetchseed(args)
if fetch_success is not True:
- return (False, fetch_messages)
- install_success, install_messages = self.installkey(args)
- if install_success is not True:
- return (False, install_messages)
- messages = fetch_messages + [install_messages]
- return (True, messages)
+ success = False
+ messages = fetch_messages
+ self.output('', "Fetch failed.\n")
+ else:
+ self.output('', "Fetch succeeded.\n")
+ self.output('', "Installing or Refreshing keys for %s category." %args.category)
+ install_success, install_messages = self.installkey(args)
+ if install_success is not True:
+ self.output('', "Update failed.\n")
+ success = False
+ else:
+ self.output('', "Update succeeded.\n")
+ messages = fetch_messages + ["Update operation:"] + [install_messages]
+ return (success, messages)
def addseed(self, args):
'''Add or replace a key in the selected seed file'''
@@ -313,7 +335,6 @@ class Actions(ActionBase):
self.gpg.set_keydir(gkey.keydir, "recv-keys")
self.gpg.set_keyseedfile()
seeds = self.gpg.seedfile.seeds
- #print(seeds)
if seeds:
self.logger.debug("ACTIONS: installkey; found installed seeds:"
"\n %s" % seeds)
^ permalink raw reply related [flat|nested] 40+ messages in thread
* [gentoo-commits] proj/gentoo-keys:gsoc-2016 commit in: gkeys/gkeys/
@ 2016-12-24 9:13 Brian Dolbec
0 siblings, 0 replies; 40+ messages in thread
From: Brian Dolbec @ 2016-12-24 9:13 UTC (permalink / raw
To: gentoo-commits
commit: 93c87f84c607819b8b544705f2b50d6721911bd3
Author: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Sat Dec 24 00:36:55 2016 +0000
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Sat Dec 24 00:36:55 2016 +0000
URL: https://gitweb.gentoo.org/proj/gentoo-keys.git/commit/?id=93c87f84
gkeys actionbase: Fix trust model detection & setting in _set_trust()
gkeys/gkeys/actionbase.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/gkeys/gkeys/actionbase.py b/gkeys/gkeys/actionbase.py
index 67d3520..3993be4 100644
--- a/gkeys/gkeys/actionbase.py
+++ b/gkeys/gkeys/actionbase.py
@@ -95,8 +95,8 @@ class ActionBase(object):
trust = self.config.get_key('trust-model', cat)
if trust in [None]:
trust = 'auto'
- if 'trust-model' in self.config.defaults['gpg_defaults']:
- index = self.config.defaults['gpg_defaults'].index('trust-model')
+ if '--trust-model' in self.config.defaults['gpg_defaults']:
+ index = self.config.defaults['gpg_defaults'].index('--trust-model')
self.config.defaults['gpg_defaults'][index+1] = trust
else:
self.config.defaults['gpg_defaults'].extend(['--trust-model', trust])
^ permalink raw reply related [flat|nested] 40+ messages in thread
* [gentoo-commits] proj/gentoo-keys:gsoc-2016 commit in: gkeys/gkeys/
@ 2016-12-24 9:13 Brian Dolbec
0 siblings, 0 replies; 40+ messages in thread
From: Brian Dolbec @ 2016-12-24 9:13 UTC (permalink / raw
To: gentoo-commits
commit: 78c83d8030ad8628887e2705bdc95b485a8e42be
Author: aeroniero33 <justthisthing <AT> gmail <DOT> com>
AuthorDate: Sat Aug 27 14:07:07 2016 +0000
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Sat Dec 24 04:54:14 2016 +0000
URL: https://gitweb.gentoo.org/proj/gentoo-keys.git/commit/?id=78c83d80
Added a mail script that handles the emailing proccess
I created a new file called `mail.py` that handles the email login and the email sending.
gkeys/gkeys/mail.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 51 insertions(+)
diff --git a/gkeys/gkeys/mail.py b/gkeys/gkeys/mail.py
new file mode 100644
index 0000000..df86d11
--- /dev/null
+++ b/gkeys/gkeys/mail.py
@@ -0,0 +1,51 @@
+from __future__ import print_function
+
+import os
+import smtplib
+import sys
+import email.utils
+
+from email.mime.text import MIMEText
+from snakeoil.demandload import demandload
+
+if sys.version_info[0] >= 3:
+ py_input = input
+ _unicode = str
+else:
+ py_input = raw_input
+ _unicode = unicode
+
+demandload(
+ "gkeys.base:Args",
+ "json:load",
+)
+
+class Emailer(object):
+ '''Send an email reminder about the status of the user's GPG key'''
+
+ def __init__(self, login, logger):
+ self.logger = logger
+ self.email_from = _unicode(login['login_email'])
+ self.sender_full_name = _unicode(login['full_name'])
+ login_passwd = login['passwd']
+ server = login['server']
+ self.mail = smtplib.SMTP(server, 587)
+ self.mail.ehlo()
+ self.mail.starttls()
+ self.mail.login(self.email_from, login_passwd)
+ self.logger.debug(_unicode("Login successfull"))
+
+ def send_email(self, uid, message):
+ self.logger.debug(_unicode('Sending email with message %s') % _unicode(message))
+ subject = "Expiring Key"
+ email_to = uid
+ msg = MIMEText(message, 'plain')
+ msg['Subject'] = subject
+ msg['From'] = email.utils.formataddr((self.sender_full_name, self.email_from))
+ msg['To'] = email_to
+ self.logger.info(_unicode('Sending the email reminder from %s to %s') \
+ % (self.email_from, email_to))
+ self.mail.sendmail(self.email_from, email_to, msg.as_string())
+
+ def email_quit(self):
+ self.mail.quit()
^ permalink raw reply related [flat|nested] 40+ messages in thread
* [gentoo-commits] proj/gentoo-keys:gsoc-2016 commit in: gkeys/gkeys/
@ 2016-12-24 9:13 Brian Dolbec
0 siblings, 0 replies; 40+ messages in thread
From: Brian Dolbec @ 2016-12-24 9:13 UTC (permalink / raw
To: gentoo-commits
commit: c84d91bf6e3301b89b1e5c1216e69aa28fe7514b
Author: aeroniero33 <justthisthing <AT> gmail <DOT> com>
AuthorDate: Tue Jun 21 01:40:28 2016 +0000
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Sat Dec 24 04:54:15 2016 +0000
URL: https://gitweb.gentoo.org/proj/gentoo-keys.git/commit/?id=c84d91bf
Created the send-key function
gkeys/gkeys/action_map.py | 11 ++++++++++-
gkeys/gkeys/actions.py | 27 +++++++++++++++++++++++++++
gkeys/gkeys/lib.py | 16 ++++++++++++++++
3 files changed, 53 insertions(+), 1 deletion(-)
diff --git a/gkeys/gkeys/action_map.py b/gkeys/gkeys/action_map.py
index e4ea412..f372a5c 100644
--- a/gkeys/gkeys/action_map.py
+++ b/gkeys/gkeys/action_map.py
@@ -18,7 +18,7 @@ Seed_Actions = ['----seeds----', 'add-seed', 'fetch-seed',
'list-seed', 'list-seedfiles', 'move-seed', 'remove-seed']
Key_Actions = ['----keys-----', 'check-key', 'installed',
- 'install-key', 'list-key', 'refresh-key', 'remove-key',
+ 'install-key', 'list-key', 'send-key', 'refresh-key', 'remove-key',
'search-key', 'spec-check']
General_Actions = ['---general---', 'list-cats', 'sign','verify']
@@ -174,6 +174,15 @@ Gpg info.: pub 4096R/825533CBF6CD6C97 2014-10-03 [expires: 2017-09-17]
Gkey task results:
Done.''',
}),
+ ('send-key', {
+ 'func': 'sendkey',
+ 'options': ['category', 'nick', 'name', 'fingerprint', 'keyid', 'keys',
+ 'keydir', 'keyring'],
+ 'desc': '''Uploads the selected gpg key''',
+ 'long_desc': '''Uploads the selected gpg key''',
+ 'example': '''gkeys send-key -C gentoo -n gkeys''',
+ }),
+
('move-key', {
'func': 'movekey',
'options': ['category', 'nick', 'name', 'fingerprint', 'keys',
diff --git a/gkeys/gkeys/actions.py b/gkeys/gkeys/actions.py
index aaa3f02..9dc69f0 100644
--- a/gkeys/gkeys/actions.py
+++ b/gkeys/gkeys/actions.py
@@ -194,6 +194,33 @@ class Actions(ActionBase):
return (False, messages)
+ def sendkey(self, args):
+ '''Send selected key(s) to the server'''
+ if not args.category:
+ return (False, ["Please specify seeds type."])
+ self.logger.debug(_unicode("ACTIONS: sendkey; args: %s")
+ % _unicode(args))
+ seeds = self.seedhandler.load_category(args.category, refresh=True)
+ self.category = args.category
+ results = {}
+ kwargs = self.seedhandler.build_gkeydict(args)
+ keyresults = seeds.list(**kwargs)
+ if keyresults:
+ self.output('', '\n sending keys...')
+ else:
+ return (False, ["Key(s) not found"])
+ for gkey in sorted(keyresults):
+ self.logger.info(_unicode("Sending key %s, %s")
+ % (gkey.nick, gkey.pub_keyid))
+ self.output('', _unicode(" %s: %s")
+ % (gkey.name, ', '.join(gkey.pub_keyid)))
+ self.logger.debug(_unicode("ACTIONS: sendkey; gkey = %s")
+ % _unicode(gkey))
+ results[gkey.keydir] = self.gpg.send_keys(gkey)
+ return (True, ['Completed'])
+
+
+
def listkey(self, args):
'''Pretty-print the selected gpg key'''
# get confirmation
diff --git a/gkeys/gkeys/lib.py b/gkeys/gkeys/lib.py
index 5ad1aab..a8529f4 100644
--- a/gkeys/gkeys/lib.py
+++ b/gkeys/gkeys/lib.py
@@ -273,6 +273,22 @@ class GkeysGPG(GPG):
self.logger.info('GPG return code: ' + str(result.returncode))
return result
+ def send_keys(self, gkey):
+ '''Send gkey to keyserver
+ @param gkey: the gkey to be sent to the server
+ @return: GKEY_CHECK instance
+ '''
+ self.config.defaults['gpg_defaults'].append('--no-permission-warning')
+ self.set_keyserver()
+ self.set_keydir(gkey.keydir, 'send-keys', reset=True)
+ self.set_keyring('pubring.gpg', 'send-keys', reset=False)
+ self.set_keyseedfile(refresh=True)
+ self.logger.debug("LIB: send-keys, gkey: %s" % str(gkey))
+ self.logger.debug("** Calling runGPG with Running 'gpg %s --send-keys' for: %s"
+ % (' '.join(self.config.get_key('tasks', 'send-keys')), str(gkey)))
+ result = self.runGPG(task='send-keys', inputfile='')
+ self.logger.info('GPG return code: ' + str(result.returncode))
+ return result
def check_keys(self, keydir, keyid, result=None):
'''Check specified or all keys based on the seed type
^ permalink raw reply related [flat|nested] 40+ messages in thread
* [gentoo-commits] proj/gentoo-keys:gsoc-2016 commit in: gkeys/gkeys/
@ 2016-12-24 9:13 Brian Dolbec
0 siblings, 0 replies; 40+ messages in thread
From: Brian Dolbec @ 2016-12-24 9:13 UTC (permalink / raw
To: gentoo-commits
commit: e92ddf9481339c1d302ca3a19ef051d355461c46
Author: aeroniero33 <justthisthing <AT> gmail <DOT> com>
AuthorDate: Fri Jun 17 17:40:01 2016 +0000
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Sat Dec 24 04:54:16 2016 +0000
URL: https://gitweb.gentoo.org/proj/gentoo-keys.git/commit/?id=e92ddf94
gkeys actions: Added automatic seeds,keys update capability
Add more detailed update reporting including the keys removed,
revoked/changed, added.
<rebase edit>
Convert print() to proper self.output()
Whitespace cleanup
Commit message improvements
</edit Brian Dolbec>
gkeys/gkeys/actions.py | 20 +++++++-------
gkeys/gkeys/base.py | 68 +++++++++++++++++++++++++++++++++++++++++++++-
gkeys/gkeys/seedhandler.py | 9 +++++-
3 files changed, 85 insertions(+), 12 deletions(-)
diff --git a/gkeys/gkeys/actions.py b/gkeys/gkeys/actions.py
index 77d39b1..825f2d9 100644
--- a/gkeys/gkeys/actions.py
+++ b/gkeys/gkeys/actions.py
@@ -133,19 +133,19 @@ class Actions(ActionBase):
self.output('', "Update succeeded.\n")
messages = fetch_messages + [" Update operation:"] + [install_messages]
success, new_gkeys = self.listseed(args)
- added_gkeys, changed_gkeys = self.seedhandler.compare_seeds(old_gkeys, new_gkeys)
- self.output('', "Updated revoked GKeys:")
- if changed_gkeys:
- for gkey in changed_gkeys:
- self.output(['', changed_gkeys])
+ added_gkeys, changed_gkeys, removed_gkeys = self.seedhandler.compare_seeds(old_gkeys, new_gkeys)
+ for gkey in changed_gkeys:
+ self.output([changed_gkeys], "Updated or revoked GKeys:")
else:
- self.output('', "No GKeys were revoked")
- self.output('', "Added GKeys:")
- if added_gkeys:
- for gkey in added_gkeys:
- self.output(['', added_gkeys])
+ self.output('', "No GKeys were updated or revoked")
+ for gkey in added_gkeys:
+ self.output([added_gkeys], "Added GKeys:")
else:
self.output('', "No GKeys were added")
+ for gkey in removed_gkeys:
+ self.output([removed_gkeys], "Removed GKeys:")
+ else:
+ self.output('', "No GKeys were removed")
return (success, messages)
def addseed(self, args):
diff --git a/gkeys/gkeys/base.py b/gkeys/gkeys/base.py
index a0224c0..28dd0b2 100644
--- a/gkeys/gkeys/base.py
+++ b/gkeys/gkeys/base.py
@@ -17,10 +17,20 @@ from __future__ import print_function
import argparse
import os
import sys
+import copy
from gkeys.fileops import ensure_dirs
from gkeys.log import log_levels, set_logger
+from gkeys.gkey import GKEY
+if sys.version_info[0] >= 3:
+ from urllib.request import urlopen
+ py_input = input
+ _unicode = str
+else:
+ from urllib2 import urlopen
+ py_input = raw_input
+ _unicode = unicode
if sys.version_info[0] >= 3:
unicode = str
@@ -291,6 +301,10 @@ class CliBase(object):
for opt in options:
getattr(self, '_option_%s' % opt)(parser)
+ def warning_output(self, info):
+ ''' We don't want this message to be spammed 4 times everytime gkeys is run'''
+ if "Re-fetch cycle timeout of" not in info:
+ print(info)
def setup(self, args, configs):
'''Set up the args and configs passed in
@@ -352,7 +366,59 @@ class CliBase(object):
'''
# establish our actions instance
self.actions = self.cli_config['Actions'](self.config, self.output_results, self.logger)
-
+ # check for seed update
+ from sslfetch.connections import Connector
+ connector_output = {
+ 'info': self.logger.info,
+ 'debug': self.logger.debug,
+ 'error': self.logger.error,
+ 'exception': self.logger.exception,
+ 'warning': self.warning_output,
+ 'kwargs-info': {},
+ 'kwargs-debug': {},
+ 'kwargs-error': {},
+ 'kwargs-exception': {},
+ 'kwargs-warning': {},
+ }
+ fetcher = Connector(connector_output, None, "Gentoo Keys")
+ successes = []
+ up_to_date = True
+ categories = list(self.config.defaults['seeds'])
+ '''Attemp to download seed and seed.sig files for each available category'''
+ for category in categories:
+ filepath = self.config.defaults['seedsdir'] + "/" + category + ".seeds"
+ timestamp_path = filepath + ".timestamp"
+ url = self.config.defaults['seedurls'][category]
+ success, signedfile, timestamp = fetcher.fetch_file(
+ url, filepath, timestamp_path)
+ if timestamp != "":
+ up_to_date = False
+ successes.append(success)
+ url += ".sig"
+ filepath += ".sig"
+ success, signedfile, timestamp = fetcher.fetch_file(
+ url, filepath, timestamp_path)
+ if timestamp != "":
+ up_to_date = False
+ successes.append(success)
+ if False not in successes and not up_to_date:
+ print("Seeds need to be updated")
+ ack = None
+ while ack not in ("y", "yes", "n", "no"):
+ ack = py_input("Would you like to update the seeds now? (y/n) ").lower()
+ if ack in ("y", "yes"):
+ custom_args = copy.copy(args)
+ for attr in GKEY._fields:
+ if attr != "debug":
+ custom_args.attr = None
+ custom_args.category = None
+ custom_args.action = "update-seed"
+ print("Updating seeds")
+ self.run(custom_args)
+ elif False not in successes:
+ print("Seeds are up to date")
+ else:
+ print("Seed update check failed, check your internet connection.")
# run the action
func = getattr(self.actions, '%s'
% self.cli_config['Action_Map'][args.action]['func'])
diff --git a/gkeys/gkeys/seedhandler.py b/gkeys/gkeys/seedhandler.py
index c7dad2e..90ce583 100644
--- a/gkeys/gkeys/seedhandler.py
+++ b/gkeys/gkeys/seedhandler.py
@@ -78,21 +78,28 @@ class SeedHandler(object):
@param seeds2: set of seeds to be compared
@return added_gkeys: list of keys that are included in seed2 but not seed1
@return changed_gkeys: list of keys that are included in seed1 and seed2 but have been altered
+ @return removed_gkeys: list of keys that are included in seed1 but not in seed2
'''
old_gkeys = seeds1[1]
new_gkeys = seeds2[1]
changed_gkeys = []
+ old_changed_gkeys = []
+ removed_gkeys = []
added_gkeys = []
if old_gkeys:
for new_gkey in new_gkeys:
for old_gkey in old_gkeys:
if new_gkey.nick == old_gkey.nick and new_gkey != old_gkey:
changed_gkeys.append(new_gkey)
+ old_changed_gkeys.append(old_gkey)
if new_gkey not in old_gkeys and new_gkey not in changed_gkeys:
added_gkeys.append(new_gkey)
+ for old_gkey in old_gkeys:
+ if old_gkey not in new_gkeys and old_gkey not in old_changed_gkeys:
+ removed_gkeys.append(old_gkey)
else:
added_gkeys = new_gkeys
- return(added_gkeys, changed_gkeys)
+ return(added_gkeys, changed_gkeys, removed_gkeys)
def load_seeds(self, seedfile=None, filepath=None, refresh=False):
'''Load seed file
^ permalink raw reply related [flat|nested] 40+ messages in thread
* [gentoo-commits] proj/gentoo-keys:gsoc-2016 commit in: gkeys/gkeys/
@ 2016-12-24 9:13 Brian Dolbec
0 siblings, 0 replies; 40+ messages in thread
From: Brian Dolbec @ 2016-12-24 9:13 UTC (permalink / raw
To: gentoo-commits
commit: 5a6dac0bcbcdda558b8b828ceb1e6f3d04d95ada
Author: aeroniero33 <justthisthing <AT> gmail <DOT> com>
AuthorDate: Sat Aug 27 14:05:41 2016 +0000
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Sat Dec 24 04:54:14 2016 +0000
URL: https://gitweb.gentoo.org/proj/gentoo-keys.git/commit/?id=5a6dac0b
Added --user and --email args parameters for spec-check
I added 2 `args` parameters called `--email` and `--user` in `base.py`
to be given to spec-check in order for the script to run.
(The `--user` is optional for the user to select with which account to login)
gkeys/gkeys/action_map.py | 2 +-
gkeys/gkeys/base.py | 9 +++++++++
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/gkeys/gkeys/action_map.py b/gkeys/gkeys/action_map.py
index 80c59fe..e4ea412 100644
--- a/gkeys/gkeys/action_map.py
+++ b/gkeys/gkeys/action_map.py
@@ -275,7 +275,7 @@ Do you really want to remove dolsen?[y/n]: y
('spec-check', {
'func': 'speccheck',
'options': ['category', 'nick', 'name', 'fingerprint', 'keyid', 'keys',
- 'keydir', 'keyring'],
+ 'keydir', 'keyring', 'email', 'user'],
'desc': '''Check if keys meet specifications requirements''',
'long_desc': '''Check if keys meet specifications requirements''',
'example': '''$ gkeys spec-check -C gentoo -n gkeys
diff --git a/gkeys/gkeys/base.py b/gkeys/gkeys/base.py
index 9b285e4..a0224c0 100644
--- a/gkeys/gkeys/base.py
+++ b/gkeys/gkeys/base.py
@@ -222,6 +222,15 @@ class CliBase(object):
parser.add_argument('-u', '--uid', dest='uid', nargs='+', default=None,
help='The user ID, gpg key uid')
+ @staticmethod
+ def _option_email(parser=None):
+ parser.add_argument('-E', '--email', dest='email', default=None,
+ help='Email parameter for sending email reminders')
+
+ @staticmethod
+ def _option_user(parser=None):
+ parser.add_argument('-U', '--user', dest='user', default=None,
+ help='User parameter for service login')
def parse_args(self, argv):
'''Parse a list of aruments
^ permalink raw reply related [flat|nested] 40+ messages in thread
* [gentoo-commits] proj/gentoo-keys:gsoc-2016 commit in: gkeys/gkeys/
@ 2016-12-24 9:13 Brian Dolbec
0 siblings, 0 replies; 40+ messages in thread
From: Brian Dolbec @ 2016-12-24 9:13 UTC (permalink / raw
To: gentoo-commits
commit: 7db7af132887952418cf2ea0fdcf4513e6f69adf
Author: aeroniero33 <justthisthing <AT> gmail <DOT> com>
AuthorDate: Sat Aug 27 14:22:28 2016 +0000
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Sat Dec 24 04:54:14 2016 +0000
URL: https://gitweb.gentoo.org/proj/gentoo-keys.git/commit/?id=7db7af13
Added some util methods in keyhandler
The methods are:
is_expiring that checks if a key is expiring or has recently expired
set_template that reads the template file and returns it as a string
generate_template that substitutes the key prints in the template
find_email that extracts the correct email address from the key uid
gkeys/gkeys/keyhandler.py | 42 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/gkeys/gkeys/keyhandler.py b/gkeys/gkeys/keyhandler.py
index 9043fcd..0a02c22 100644
--- a/gkeys/gkeys/keyhandler.py
+++ b/gkeys/gkeys/keyhandler.py
@@ -11,6 +11,9 @@
"""
import os
import sys
+import re
+
+from string import Template
from snakeoil.demandload import demandload
@@ -108,3 +111,42 @@ class KeyHandler(object):
self.logger.debug(_unicode("KeyHandler: key_search; keys = %s") % str(keys))
return keys
+
+ @staticmethod
+ def is_expiring(keys, days_limit=30):
+ '''Check if any of the keys is within the days_limit'''
+ is_exp = False
+ for key in keys:
+ for specs in keys[key]:
+ if specs.days > days_limit*(-1) and specs.days < days_limit:
+ is_exp = True
+ break
+ return is_exp
+
+ @staticmethod
+ def set_template(template_path):
+ '''Read the template file and returns the template message'''
+ with open(template_path, 'r') as file_contents:
+ content = file_contents.read()
+ message_template = Template(content)
+ return message_template
+
+ @staticmethod
+ def generate_template(message_template, keyprints, specprint):
+ '''Substitute the print variables in the template'''
+ message = message_template.substitute(key_print=keyprints, spec_print=specprint)
+ return message
+
+ @staticmethod
+ def find_email(uids, prefered_address=None):
+ '''Find the email address from the uid by prioritizing the prefered address'''
+ if type(prefered_address) is not str:
+ uids = [uids[0]]
+ for uid in uids:
+ match = re.findall(r'[\w\.-]+@[\w\.-]+', uid)
+ uid = ''
+ if match:
+ uid = match[0]
+ if prefered_address and uid.endswith(prefered_address):
+ return uid
+ return uid
^ permalink raw reply related [flat|nested] 40+ messages in thread
* [gentoo-commits] proj/gentoo-keys:gsoc-2016 commit in: gkeys/gkeys/
2016-12-24 4:52 [gentoo-commits] proj/gentoo-keys:master " Brian Dolbec
@ 2016-12-24 9:13 ` Brian Dolbec
0 siblings, 0 replies; 40+ messages in thread
From: Brian Dolbec @ 2016-12-24 9:13 UTC (permalink / raw
To: gentoo-commits
commit: c1cf82a2f2f651da4749065be050154f23e07469
Author: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Sat Dec 24 04:51:55 2016 +0000
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Sat Dec 24 04:51:55 2016 +0000
URL: https://gitweb.gentoo.org/proj/gentoo-keys.git/commit/?id=c1cf82a2
gkeys actions: Migrate self.category setting to _set_category()
gkeys/gkeys/actions.py | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/gkeys/gkeys/actions.py b/gkeys/gkeys/actions.py
index 07dba7a..a9d2b69 100644
--- a/gkeys/gkeys/actions.py
+++ b/gkeys/gkeys/actions.py
@@ -108,6 +108,7 @@ class Actions(ActionBase):
if args.uid is None:
args.uid = []
gkey = self.seedhandler.new(args, checkgkey=True)
+ self._set_category(args.category)
if not gkey:
return (False, ["Failed to create a valid GKEY instance.",
"Check for invalid data entries"])
@@ -198,7 +199,7 @@ class Actions(ActionBase):
# fill in code here
if not args.category:
args.category = 'gentoo'
- self.category = args.category
+ self._set_category(args.category)
if args.keydir:
self.gpg.set_keydir(args.keydir, "list-keys")
self.gpg.set_keyseedfile()
@@ -267,7 +268,7 @@ class Actions(ActionBase):
return (False, ["Search failed for search term"])
# get confirmation
# fill in code here
- self.category = args.category
+ self._set_category(args.category)
for gkey in gkeys:
self.gpg.set_keydir(gkey.keydir, "recv-keys")
self.gpg.set_keyseedfile()
@@ -325,7 +326,7 @@ class Actions(ActionBase):
return (False, [_unicode("Please specify seeds category.")])
self.logger.debug(_unicode("ACTIONS: checkkey; args: %s") % _unicode(args))
seeds = self.seedhandler.load_category(args.category)
- self.category = args.category
+ self._set_category(args.category)
results = {}
failed = defaultdict(list)
kwargs = self.seedhandler.build_gkeydict(args)
@@ -375,7 +376,7 @@ class Actions(ActionBase):
return (False, ["Please specify seeds category."])
self.logger.debug(_unicode("ACTIONS: speccheck; args: %s")
% _unicode(args))
- self.category = args.category
+ self._set_category(args.category)
catdir, keyresults = self.keyhandler.determine_keys(args)
self.logger.debug(_unicode("ACTIONS: speccheck; catdir = %s") % catdir)
results = {}
@@ -524,6 +525,7 @@ class Actions(ActionBase):
self.logger.debug(_unicode("ACTIONS: removekey; kwargs: %s")
% _unicode(kwargs))
seeds = self.seedhandler.load_category(args.category)
+ self._set_category(args.category)
messages = []
if args.nick == '*':
self.output([''],_unicode('Remove All keys in category: %s')
@@ -620,9 +622,9 @@ class Actions(ActionBase):
'''Lists the installed key directories'''
if args.category:
keyring = self.config.get_key('keyring')
- catdir = os.path.join(keyring, args.category)
else:
return (False, ["Please specify a category."])
+ catdir = self._set_category(args.category)
self.logger.debug("ACTIONS: installed; catdir = %s" % catdir)
installed_keys = []
try:
@@ -697,7 +699,7 @@ class Actions(ActionBase):
def _verify(self, args, key, messages=None):
if messages == None:
messages = []
- self.category = args.category
+ self._set_category(args.category)
filepath, signature = args.filename, args.signature
timestamp_path = None
isurl = success = verified = False
@@ -831,9 +833,9 @@ class Actions(ActionBase):
else:
nicks = args.nick
args.category = 'sign'
+ self._set_category(args.category)
# load our installed signing keys db
self.seeds = self.seedhandler.load_category('sign', nicks)
- self.category = args.category
if not self.seeds.seeds:
return (False, ['No installed keys, try installkey action.', ''])
keydir = self.config.get_key("sign", "keydir")
@@ -877,7 +879,7 @@ class Actions(ActionBase):
self.logger.debug(_unicode("ACTIONS: refreshkey; args: %s")
% _unicode(args))
seeds = self.seedhandler.load_category(args.category, refresh=True)
- self.category = args.category
+ self._set_category(args.category)
results = {}
kwargs = self.seedhandler.build_gkeydict(args)
keyresults = seeds.list(**kwargs)
^ permalink raw reply related [flat|nested] 40+ messages in thread
* [gentoo-commits] proj/gentoo-keys:gsoc-2016 commit in: gkeys/gkeys/
@ 2016-12-24 9:13 Brian Dolbec
0 siblings, 0 replies; 40+ messages in thread
From: Brian Dolbec @ 2016-12-24 9:13 UTC (permalink / raw
To: gentoo-commits
commit: 33aa21ef6e619c7776a4984370c7f01a15c0ec87
Author: aeroniero33 <justthisthing <AT> gmail <DOT> com>
AuthorDate: Tue Jun 14 20:24:08 2016 +0000
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Sat Dec 24 04:54:15 2016 +0000
URL: https://gitweb.gentoo.org/proj/gentoo-keys.git/commit/?id=33aa21ef
gkeys actions: Add keys updated reporting
Report the updated/revoked keys during the update.
<rebase edit>
Replace print() with self.output()
Whitespace cleanup
Create a meaningful commit message
</edit Brian Dolbec>
gkeys/gkeys/actions.py | 18 +++++++++++++++++-
gkeys/gkeys/seedhandler.py | 23 +++++++++++++++++++++++
2 files changed, 40 insertions(+), 1 deletion(-)
diff --git a/gkeys/gkeys/actions.py b/gkeys/gkeys/actions.py
index 3d0399a..77d39b1 100644
--- a/gkeys/gkeys/actions.py
+++ b/gkeys/gkeys/actions.py
@@ -115,7 +115,9 @@ class Actions(ActionBase):
category_msgs.extend(messages)
return (True, category_msgs)
self.output('', "Fetching seeds for %s category.\n" %args.category)
+ success, old_gkeys = self.listseed(args)
fetch_success, fetch_messages = self.fetchseed(args)
+ self.seeds = None
if fetch_success is not True:
success = False
messages = fetch_messages
@@ -129,7 +131,21 @@ class Actions(ActionBase):
success = False
else:
self.output('', "Update succeeded.\n")
- messages = fetch_messages + ["Update operation:"] + [install_messages]
+ messages = fetch_messages + [" Update operation:"] + [install_messages]
+ success, new_gkeys = self.listseed(args)
+ added_gkeys, changed_gkeys = self.seedhandler.compare_seeds(old_gkeys, new_gkeys)
+ self.output('', "Updated revoked GKeys:")
+ if changed_gkeys:
+ for gkey in changed_gkeys:
+ self.output(['', changed_gkeys])
+ else:
+ self.output('', "No GKeys were revoked")
+ self.output('', "Added GKeys:")
+ if added_gkeys:
+ for gkey in added_gkeys:
+ self.output(['', added_gkeys])
+ else:
+ self.output('', "No GKeys were added")
return (success, messages)
def addseed(self, args):
diff --git a/gkeys/gkeys/seedhandler.py b/gkeys/gkeys/seedhandler.py
index de2a6ad..c7dad2e 100644
--- a/gkeys/gkeys/seedhandler.py
+++ b/gkeys/gkeys/seedhandler.py
@@ -71,6 +71,29 @@ class SeedHandler(object):
keyinfo[attr] = None
return keyinfo
+ def compare_seeds(self, seeds1, seeds2) :
+ '''Compares two seed lists and returns the differences
+
+ @param seeds1: set of seeds to be compared
+ @param seeds2: set of seeds to be compared
+ @return added_gkeys: list of keys that are included in seed2 but not seed1
+ @return changed_gkeys: list of keys that are included in seed1 and seed2 but have been altered
+ '''
+ old_gkeys = seeds1[1]
+ new_gkeys = seeds2[1]
+ changed_gkeys = []
+ added_gkeys = []
+ if old_gkeys:
+ for new_gkey in new_gkeys:
+ for old_gkey in old_gkeys:
+ if new_gkey.nick == old_gkey.nick and new_gkey != old_gkey:
+ changed_gkeys.append(new_gkey)
+ if new_gkey not in old_gkeys and new_gkey not in changed_gkeys:
+ added_gkeys.append(new_gkey)
+ else:
+ added_gkeys = new_gkeys
+ return(added_gkeys, changed_gkeys)
+
def load_seeds(self, seedfile=None, filepath=None, refresh=False):
'''Load seed file
^ permalink raw reply related [flat|nested] 40+ messages in thread
* [gentoo-commits] proj/gentoo-keys:gsoc-2016 commit in: gkeys/gkeys/
@ 2016-12-24 9:13 Brian Dolbec
0 siblings, 0 replies; 40+ messages in thread
From: Brian Dolbec @ 2016-12-24 9:13 UTC (permalink / raw
To: gentoo-commits
commit: 05ec1dd9a237b624354bce496b93aa6b98f63ef2
Author: aeroniero33 <justthisthing <AT> gmail <DOT> com>
AuthorDate: Thu Jun 9 22:44:16 2016 +0000
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Sat Dec 24 04:54:15 2016 +0000
URL: https://gitweb.gentoo.org/proj/gentoo-keys.git/commit/?id=05ec1dd9
Created the update-seed function
gkeys/gkeys/action_map.py | 19 ++++++++++++++++++-
gkeys/gkeys/actions.py | 14 +++++++++++++-
2 files changed, 31 insertions(+), 2 deletions(-)
diff --git a/gkeys/gkeys/action_map.py b/gkeys/gkeys/action_map.py
index f372a5c..1bd0625 100644
--- a/gkeys/gkeys/action_map.py
+++ b/gkeys/gkeys/action_map.py
@@ -15,7 +15,8 @@ from collections import OrderedDict
Seed_Actions = ['----seeds----', 'add-seed', 'fetch-seed',
- 'list-seed', 'list-seedfiles', 'move-seed', 'remove-seed']
+ 'update-seed', 'list-seed', 'list-seedfiles', 'move-seed',
+ 'remove-seed']
Key_Actions = ['----keys-----', 'check-key', 'installed',
'install-key', 'list-key', 'send-key', 'refresh-key', 'remove-key',
@@ -380,6 +381,22 @@ Found Failures:
Fetch operation completed
''',
}),
+ ('update-seed', {
+ 'func': 'updateseed',
+ 'options': ['category', 'nick', '1file', 'dest', 'signature',
+ 'timestamp'],
+ 'desc': '''Update the selected seed file(s)''',
+ 'long_desc': '''Update the selected seed file(s)''',
+ 'example': '''$ gkeys update-seed -C gentoo-devs
+
+ Gkey task results:
+ Verification succeeded.: /home/brian/gpg-test/seeds/gentoo-devs.seeds
+ Key info...............: Gentoo-Linux Gentoo-keys Project Signing Key <gkeys>, 0xA41DBBD9151C3FC7
+ category, nick.....: gentoo gkeys
+
+ Update operation completed
+''',
+ }),
('list-seed', {
'func': 'listseed',
'options': ['category', 'nick', 'name', 'fingerprint', 'keys',
diff --git a/gkeys/gkeys/actions.py b/gkeys/gkeys/actions.py
index 3070eb3..c218d8d 100644
--- a/gkeys/gkeys/actions.py
+++ b/gkeys/gkeys/actions.py
@@ -96,7 +96,19 @@ class Actions(ActionBase):
messages.append("")
messages.append("Fetch operation completed")
return (False not in success, messages)
-
+
+ def updateseed(self, args):
+ '''Updates seeds of a selected file'''
+ self.logger.debug(_unicode("ACTIONS: updateseed; args: %s")
+ % _unicode(args))
+ fetch_success, fetch_messages = self.fetchseed(args)
+ if fetch_success is not True:
+ return (False, fetch_messages)
+ install_success, install_messages = self.installkey(args)
+ if install_success is not True:
+ return (False, install_messages)
+ messages = fetch_messages + [install_messages]
+ return (True, messages)
def addseed(self, args):
'''Add or replace a key in the selected seed file'''
^ permalink raw reply related [flat|nested] 40+ messages in thread
* [gentoo-commits] proj/gentoo-keys:gsoc-2016 commit in: gkeys/gkeys/
@ 2016-12-24 9:13 Brian Dolbec
0 siblings, 0 replies; 40+ messages in thread
From: Brian Dolbec @ 2016-12-24 9:13 UTC (permalink / raw
To: gentoo-commits
commit: b98bb5be852b3a5a5bcf52830a51a653c9ab20e5
Author: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Sat Dec 24 09:11:08 2016 +0000
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Sat Dec 24 09:11:08 2016 +0000
URL: https://gitweb.gentoo.org/proj/gentoo-keys.git/commit/?id=b98bb5be
gkeys base.py: Remove the auto-update code from run()
This code was causing the fetch-seed action to fail with empty urls to connect to.
This code should also not be running directly from the CliBase class.
I'll move this code to the actions or lib class, to be determined later.
gkeys/gkeys/base.py | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/gkeys/gkeys/base.py b/gkeys/gkeys/base.py
index 28dd0b2..fb4465f 100644
--- a/gkeys/gkeys/base.py
+++ b/gkeys/gkeys/base.py
@@ -358,14 +358,7 @@ class CliBase(object):
return False
return True
-
- def run(self, args):
- '''Run the action selected
-
- @param args: list of argumanets to parse
- '''
- # establish our actions instance
- self.actions = self.cli_config['Actions'](self.config, self.output_results, self.logger)
+ def _upadate_seeds(self):
# check for seed update
from sslfetch.connections import Connector
connector_output = {
@@ -390,14 +383,14 @@ class CliBase(object):
timestamp_path = filepath + ".timestamp"
url = self.config.defaults['seedurls'][category]
success, signedfile, timestamp = fetcher.fetch_file(
- url, filepath, timestamp_path)
+ url, filepath, timestamp_path, climit=0)
if timestamp != "":
up_to_date = False
successes.append(success)
url += ".sig"
filepath += ".sig"
success, signedfile, timestamp = fetcher.fetch_file(
- url, filepath, timestamp_path)
+ url, filepath, timestamp_path, climit=0)
if timestamp != "":
up_to_date = False
successes.append(success)
@@ -419,6 +412,15 @@ class CliBase(object):
print("Seeds are up to date")
else:
print("Seed update check failed, check your internet connection.")
+
+
+ def run(self, args):
+ '''Run the action selected
+
+ @param args: list of argumanets to parse
+ '''
+ # establish our actions instance
+ self.actions = self.cli_config['Actions'](self.config, self.output_results, self.logger)
# run the action
func = getattr(self.actions, '%s'
% self.cli_config['Action_Map'][args.action]['func'])
^ permalink raw reply related [flat|nested] 40+ messages in thread
* [gentoo-commits] proj/gentoo-keys:gsoc-2016 commit in: gkeys/gkeys/
@ 2016-12-24 9:13 Brian Dolbec
0 siblings, 0 replies; 40+ messages in thread
From: Brian Dolbec @ 2016-12-24 9:13 UTC (permalink / raw
To: gentoo-commits
commit: 76ed0539130e6ed22a385b8e6acf7fc588802f1a
Author: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Sat Dec 24 09:08:14 2016 +0000
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Sat Dec 24 09:08:14 2016 +0000
URL: https://gitweb.gentoo.org/proj/gentoo-keys.git/commit/?id=76ed0539
gkeys seedhandler.py: Add another debug log for the seedurl and seedpath
This is to aid in troubleshooting fetch-sedd url errors.
gkeys/gkeys/seedhandler.py | 1 +
1 file changed, 1 insertion(+)
diff --git a/gkeys/gkeys/seedhandler.py b/gkeys/gkeys/seedhandler.py
index 90ce583..f36d3e2 100644
--- a/gkeys/gkeys/seedhandler.py
+++ b/gkeys/gkeys/seedhandler.py
@@ -186,6 +186,7 @@ class SeedHandler(object):
for seed in [seeds]:
seedurl = self.config.get_key('seedurls', seed)
seedpath = self.config.get_key('seeds', seed)
+ self.logger.debug("Seed URL/seed path...: %s, %s" % (seedurl, seedpath))
if seedurl and seedpath and http_check.match(seedurl):
urls.extend([(seed, seedurl, seedpath)])
else:
^ permalink raw reply related [flat|nested] 40+ messages in thread
* [gentoo-commits] proj/gentoo-keys:gsoc-2016 commit in: gkeys/gkeys/
@ 2016-12-24 9:13 Brian Dolbec
0 siblings, 0 replies; 40+ messages in thread
From: Brian Dolbec @ 2016-12-24 9:13 UTC (permalink / raw
To: gentoo-commits
commit: 43bbe21ac8af1ec96564401acc8aef80ec80732d
Author: Pavlos Ratis <dastergon <AT> dastergon <DOT> gr>
AuthorDate: Sun Aug 28 18:02:54 2016 +0000
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Sat Dec 24 04:54:16 2016 +0000
URL: https://gitweb.gentoo.org/proj/gentoo-keys.git/commit/?id=43bbe21a
remove debug print
gkeys/gkeys/actions.py | 1 -
1 file changed, 1 deletion(-)
diff --git a/gkeys/gkeys/actions.py b/gkeys/gkeys/actions.py
index 825f2d9..05046e2 100644
--- a/gkeys/gkeys/actions.py
+++ b/gkeys/gkeys/actions.py
@@ -647,7 +647,6 @@ class Actions(ActionBase):
keyresults = seeds.list(**kwargs)
self.output('', '\n Removing keys...')
success = True
- #print(keyresults)
for gkey in sorted(keyresults):
if kwargs['nick'] != '*' and kwargs['nick'] not in gkey.nick:
messages.append(_unicode("%s does not seem to be a valid key.")
^ permalink raw reply related [flat|nested] 40+ messages in thread
* [gentoo-commits] proj/gentoo-keys:gsoc-2016 commit in: gkeys/gkeys/
@ 2016-12-24 9:41 Brian Dolbec
0 siblings, 0 replies; 40+ messages in thread
From: Brian Dolbec @ 2016-12-24 9:41 UTC (permalink / raw
To: gentoo-commits
commit: 3dc495ebdfd31acd52d378457934aa10e9dacf64
Author: aeroniero33 <justthisthing <AT> gmail <DOT> com>
AuthorDate: Sun Jun 12 14:19:35 2016 +0000
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Sat Dec 24 09:40:26 2016 +0000
URL: https://gitweb.gentoo.org/proj/gentoo-keys.git/commit/?id=3dc495eb
gkeys/actions: Update the update-seed function
Update descriptions.
Update operations to current library code usage.
<rebase edit>
Replace print() use with self.output(). Expand commit message
</edit Brian Dolbec>
gkeys/gkeys/action_map.py | 7 ++++---
gkeys/gkeys/actions.py | 41 +++++++++++++++++++++++++++++++----------
2 files changed, 35 insertions(+), 13 deletions(-)
diff --git a/gkeys/gkeys/action_map.py b/gkeys/gkeys/action_map.py
index 1bd0625..5433297 100644
--- a/gkeys/gkeys/action_map.py
+++ b/gkeys/gkeys/action_map.py
@@ -385,8 +385,8 @@ Found Failures:
'func': 'updateseed',
'options': ['category', 'nick', '1file', 'dest', 'signature',
'timestamp'],
- 'desc': '''Update the selected seed file(s)''',
- 'long_desc': '''Update the selected seed file(s)''',
+ 'desc': '''Update the selected seed file(s) or all categories if no arguments are given''',
+ 'long_desc': '''Update the selected seed file(s) or all categories if no arguments are given''',
'example': '''$ gkeys update-seed -C gentoo-devs
Gkey task results:
@@ -394,7 +394,8 @@ Found Failures:
Key info...............: Gentoo-Linux Gentoo-keys Project Signing Key <gkeys>, 0xA41DBBD9151C3FC7
category, nick.....: gentoo gkeys
- Update operation completed
+ Fetch operation completed
+ Completed
''',
}),
('list-seed', {
diff --git a/gkeys/gkeys/actions.py b/gkeys/gkeys/actions.py
index c75d766..b08c54c 100644
--- a/gkeys/gkeys/actions.py
+++ b/gkeys/gkeys/actions.py
@@ -1,4 +1,4 @@
-#
+
#-*- coding:utf-8 -*-
"""
@@ -96,19 +96,41 @@ class Actions(ActionBase):
messages.append("")
messages.append("Fetch operation completed")
return (False not in success, messages)
-
+
def updateseed(self, args):
- '''Updates seeds of a selected file'''
+ '''Updates seeds of a selected file or all categories if no args are given'''
self.logger.debug(_unicode("ACTIONS: updateseed; args: %s")
% _unicode(args))
+ messages = []
+ success = True
+ if not args.category:
+ '''Update all available categories'''
+ seed_categories = list(self.config.defaults['seeds'])
+ category_msgs = []
+ for seed_category in seed_categories:
+ self.seeds = None
+ custom_args = args
+ custom_args.category = seed_category
+ category_success, messages = self.updateseed(custom_args)
+ category_msgs.extend(messages)
+ return (True, category_msgs)
+ self.output('', "Fetching seeds for %s category.\n" %args.category)
fetch_success, fetch_messages = self.fetchseed(args)
if fetch_success is not True:
- return (False, fetch_messages)
- install_success, install_messages = self.installkey(args)
- if install_success is not True:
- return (False, install_messages)
- messages = fetch_messages + [install_messages]
- return (True, messages)
+ success = False
+ messages = fetch_messages
+ self.output('', "Fetch failed.\n")
+ else:
+ self.output('', "Fetch succeeded.\n")
+ self.output('', "Installing or Refreshing keys for %s category." %args.category)
+ install_success, install_messages = self.installkey(args)
+ if install_success is not True:
+ self.output('', "Update failed.\n")
+ success = False
+ else:
+ self.output('', "Update succeeded.\n")
+ messages = fetch_messages + ["Update operation:"] + [install_messages]
+ return (success, messages)
def addseed(self, args):
'''Add or replace a key in the selected seed file'''
@@ -313,7 +335,6 @@ class Actions(ActionBase):
self.gpg.set_keydir(gkey.keydir, "recv-keys")
self.gpg.set_keyseedfile()
seeds = self.gpg.seedfile.seeds
- #print(seeds)
if seeds:
self.logger.debug("ACTIONS: installkey; found installed seeds:"
"\n %s" % seeds)
^ permalink raw reply related [flat|nested] 40+ messages in thread
* [gentoo-commits] proj/gentoo-keys:gsoc-2016 commit in: gkeys/gkeys/
@ 2016-12-24 9:41 Brian Dolbec
0 siblings, 0 replies; 40+ messages in thread
From: Brian Dolbec @ 2016-12-24 9:41 UTC (permalink / raw
To: gentoo-commits
commit: ddc064ce55ba425ce91316aa2f898f511e6f2159
Author: aeroniero33 <justthisthing <AT> gmail <DOT> com>
AuthorDate: Tue Jun 14 20:24:08 2016 +0000
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Sat Dec 24 09:40:26 2016 +0000
URL: https://gitweb.gentoo.org/proj/gentoo-keys.git/commit/?id=ddc064ce
gkeys actions: Add keys updated reporting
Report the updated/revoked keys during the update.
<rebase edit>
Replace print() with self.output()
Whitespace cleanup
Create a meaningful commit message
</edit Brian Dolbec>
gkeys/gkeys/actions.py | 18 +++++++++++++++++-
gkeys/gkeys/seedhandler.py | 23 +++++++++++++++++++++++
2 files changed, 40 insertions(+), 1 deletion(-)
diff --git a/gkeys/gkeys/actions.py b/gkeys/gkeys/actions.py
index b08c54c..c06cd47 100644
--- a/gkeys/gkeys/actions.py
+++ b/gkeys/gkeys/actions.py
@@ -115,7 +115,9 @@ class Actions(ActionBase):
category_msgs.extend(messages)
return (True, category_msgs)
self.output('', "Fetching seeds for %s category.\n" %args.category)
+ success, old_gkeys = self.listseed(args)
fetch_success, fetch_messages = self.fetchseed(args)
+ self.seeds = None
if fetch_success is not True:
success = False
messages = fetch_messages
@@ -129,7 +131,21 @@ class Actions(ActionBase):
success = False
else:
self.output('', "Update succeeded.\n")
- messages = fetch_messages + ["Update operation:"] + [install_messages]
+ messages = fetch_messages + [" Update operation:"] + [install_messages]
+ success, new_gkeys = self.listseed(args)
+ added_gkeys, changed_gkeys = self.seedhandler.compare_seeds(old_gkeys, new_gkeys)
+ self.output('', "Updated revoked GKeys:")
+ if changed_gkeys:
+ for gkey in changed_gkeys:
+ self.output(['', changed_gkeys])
+ else:
+ self.output('', "No GKeys were revoked")
+ self.output('', "Added GKeys:")
+ if added_gkeys:
+ for gkey in added_gkeys:
+ self.output(['', added_gkeys])
+ else:
+ self.output('', "No GKeys were added")
return (success, messages)
def addseed(self, args):
diff --git a/gkeys/gkeys/seedhandler.py b/gkeys/gkeys/seedhandler.py
index de2a6ad..c7dad2e 100644
--- a/gkeys/gkeys/seedhandler.py
+++ b/gkeys/gkeys/seedhandler.py
@@ -71,6 +71,29 @@ class SeedHandler(object):
keyinfo[attr] = None
return keyinfo
+ def compare_seeds(self, seeds1, seeds2) :
+ '''Compares two seed lists and returns the differences
+
+ @param seeds1: set of seeds to be compared
+ @param seeds2: set of seeds to be compared
+ @return added_gkeys: list of keys that are included in seed2 but not seed1
+ @return changed_gkeys: list of keys that are included in seed1 and seed2 but have been altered
+ '''
+ old_gkeys = seeds1[1]
+ new_gkeys = seeds2[1]
+ changed_gkeys = []
+ added_gkeys = []
+ if old_gkeys:
+ for new_gkey in new_gkeys:
+ for old_gkey in old_gkeys:
+ if new_gkey.nick == old_gkey.nick and new_gkey != old_gkey:
+ changed_gkeys.append(new_gkey)
+ if new_gkey not in old_gkeys and new_gkey not in changed_gkeys:
+ added_gkeys.append(new_gkey)
+ else:
+ added_gkeys = new_gkeys
+ return(added_gkeys, changed_gkeys)
+
def load_seeds(self, seedfile=None, filepath=None, refresh=False):
'''Load seed file
^ permalink raw reply related [flat|nested] 40+ messages in thread
* [gentoo-commits] proj/gentoo-keys:gsoc-2016 commit in: gkeys/gkeys/
@ 2016-12-24 9:41 Brian Dolbec
0 siblings, 0 replies; 40+ messages in thread
From: Brian Dolbec @ 2016-12-24 9:41 UTC (permalink / raw
To: gentoo-commits
commit: 89d64ec041b3f4ce51d339e252073bf38bb77206
Author: aeroniero33 <justthisthing <AT> gmail <DOT> com>
AuthorDate: Tue Jun 21 01:40:28 2016 +0000
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Sat Dec 24 09:39:25 2016 +0000
URL: https://gitweb.gentoo.org/proj/gentoo-keys.git/commit/?id=89d64ec0
Created the send-key function
<rebase edit> use _set_category() for consistency </edit Brian Dolbec>
gkeys/gkeys/action_map.py | 11 ++++++++++-
gkeys/gkeys/actions.py | 27 +++++++++++++++++++++++++++
gkeys/gkeys/lib.py | 16 ++++++++++++++++
3 files changed, 53 insertions(+), 1 deletion(-)
diff --git a/gkeys/gkeys/action_map.py b/gkeys/gkeys/action_map.py
index e4ea412..f372a5c 100644
--- a/gkeys/gkeys/action_map.py
+++ b/gkeys/gkeys/action_map.py
@@ -18,7 +18,7 @@ Seed_Actions = ['----seeds----', 'add-seed', 'fetch-seed',
'list-seed', 'list-seedfiles', 'move-seed', 'remove-seed']
Key_Actions = ['----keys-----', 'check-key', 'installed',
- 'install-key', 'list-key', 'refresh-key', 'remove-key',
+ 'install-key', 'list-key', 'send-key', 'refresh-key', 'remove-key',
'search-key', 'spec-check']
General_Actions = ['---general---', 'list-cats', 'sign','verify']
@@ -174,6 +174,15 @@ Gpg info.: pub 4096R/825533CBF6CD6C97 2014-10-03 [expires: 2017-09-17]
Gkey task results:
Done.''',
}),
+ ('send-key', {
+ 'func': 'sendkey',
+ 'options': ['category', 'nick', 'name', 'fingerprint', 'keyid', 'keys',
+ 'keydir', 'keyring'],
+ 'desc': '''Uploads the selected gpg key''',
+ 'long_desc': '''Uploads the selected gpg key''',
+ 'example': '''gkeys send-key -C gentoo -n gkeys''',
+ }),
+
('move-key', {
'func': 'movekey',
'options': ['category', 'nick', 'name', 'fingerprint', 'keys',
diff --git a/gkeys/gkeys/actions.py b/gkeys/gkeys/actions.py
index aaa3f02..12b8efa 100644
--- a/gkeys/gkeys/actions.py
+++ b/gkeys/gkeys/actions.py
@@ -194,6 +194,33 @@ class Actions(ActionBase):
return (False, messages)
+ def sendkey(self, args):
+ '''Send selected key(s) to the server'''
+ if not args.category:
+ return (False, ["Please specify seeds type."])
+ self.logger.debug(_unicode("ACTIONS: sendkey; args: %s")
+ % _unicode(args))
+ seeds = self.seedhandler.load_category(args.category, refresh=True)
+ self._set_category(args.category)
+ results = {}
+ kwargs = self.seedhandler.build_gkeydict(args)
+ keyresults = seeds.list(**kwargs)
+ if keyresults:
+ self.output('', '\n sending keys...')
+ else:
+ return (False, ["Key(s) not found"])
+ for gkey in sorted(keyresults):
+ self.logger.info(_unicode("Sending key %s, %s")
+ % (gkey.nick, gkey.pub_keyid))
+ self.output('', _unicode(" %s: %s")
+ % (gkey.name, ', '.join(gkey.pub_keyid)))
+ self.logger.debug(_unicode("ACTIONS: sendkey; gkey = %s")
+ % _unicode(gkey))
+ results[gkey.keydir] = self.gpg.send_keys(gkey)
+ return (True, ['Completed'])
+
+
+
def listkey(self, args):
'''Pretty-print the selected gpg key'''
# get confirmation
diff --git a/gkeys/gkeys/lib.py b/gkeys/gkeys/lib.py
index 5ad1aab..a8529f4 100644
--- a/gkeys/gkeys/lib.py
+++ b/gkeys/gkeys/lib.py
@@ -273,6 +273,22 @@ class GkeysGPG(GPG):
self.logger.info('GPG return code: ' + str(result.returncode))
return result
+ def send_keys(self, gkey):
+ '''Send gkey to keyserver
+ @param gkey: the gkey to be sent to the server
+ @return: GKEY_CHECK instance
+ '''
+ self.config.defaults['gpg_defaults'].append('--no-permission-warning')
+ self.set_keyserver()
+ self.set_keydir(gkey.keydir, 'send-keys', reset=True)
+ self.set_keyring('pubring.gpg', 'send-keys', reset=False)
+ self.set_keyseedfile(refresh=True)
+ self.logger.debug("LIB: send-keys, gkey: %s" % str(gkey))
+ self.logger.debug("** Calling runGPG with Running 'gpg %s --send-keys' for: %s"
+ % (' '.join(self.config.get_key('tasks', 'send-keys')), str(gkey)))
+ result = self.runGPG(task='send-keys', inputfile='')
+ self.logger.info('GPG return code: ' + str(result.returncode))
+ return result
def check_keys(self, keydir, keyid, result=None):
'''Check specified or all keys based on the seed type
^ permalink raw reply related [flat|nested] 40+ messages in thread
* [gentoo-commits] proj/gentoo-keys:gsoc-2016 commit in: gkeys/gkeys/
@ 2016-12-24 9:41 Brian Dolbec
0 siblings, 0 replies; 40+ messages in thread
From: Brian Dolbec @ 2016-12-24 9:41 UTC (permalink / raw
To: gentoo-commits
commit: b9e64a989cbb143c63de7dc18cff2bec32ddcdd2
Author: aeroniero33 <justthisthing <AT> gmail <DOT> com>
AuthorDate: Fri Jun 17 17:40:01 2016 +0000
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Sat Dec 24 09:40:27 2016 +0000
URL: https://gitweb.gentoo.org/proj/gentoo-keys.git/commit/?id=b9e64a98
gkeys actions: Added automatic seeds,keys update capability
Add more detailed update reporting including the keys removed,
revoked/changed, added.
<rebase edit>
Convert print() to proper self.output()
Whitespace cleanup
Commit message improvements
</edit Brian Dolbec>
gkeys/gkeys/actions.py | 20 +++++++-------
gkeys/gkeys/base.py | 68 +++++++++++++++++++++++++++++++++++++++++++++-
gkeys/gkeys/seedhandler.py | 9 +++++-
3 files changed, 85 insertions(+), 12 deletions(-)
diff --git a/gkeys/gkeys/actions.py b/gkeys/gkeys/actions.py
index c06cd47..bb71496 100644
--- a/gkeys/gkeys/actions.py
+++ b/gkeys/gkeys/actions.py
@@ -133,19 +133,19 @@ class Actions(ActionBase):
self.output('', "Update succeeded.\n")
messages = fetch_messages + [" Update operation:"] + [install_messages]
success, new_gkeys = self.listseed(args)
- added_gkeys, changed_gkeys = self.seedhandler.compare_seeds(old_gkeys, new_gkeys)
- self.output('', "Updated revoked GKeys:")
- if changed_gkeys:
- for gkey in changed_gkeys:
- self.output(['', changed_gkeys])
+ added_gkeys, changed_gkeys, removed_gkeys = self.seedhandler.compare_seeds(old_gkeys, new_gkeys)
+ for gkey in changed_gkeys:
+ self.output([changed_gkeys], "Updated or revoked GKeys:")
else:
- self.output('', "No GKeys were revoked")
- self.output('', "Added GKeys:")
- if added_gkeys:
- for gkey in added_gkeys:
- self.output(['', added_gkeys])
+ self.output('', "No GKeys were updated or revoked")
+ for gkey in added_gkeys:
+ self.output([added_gkeys], "Added GKeys:")
else:
self.output('', "No GKeys were added")
+ for gkey in removed_gkeys:
+ self.output([removed_gkeys], "Removed GKeys:")
+ else:
+ self.output('', "No GKeys were removed")
return (success, messages)
def addseed(self, args):
diff --git a/gkeys/gkeys/base.py b/gkeys/gkeys/base.py
index a0224c0..28dd0b2 100644
--- a/gkeys/gkeys/base.py
+++ b/gkeys/gkeys/base.py
@@ -17,10 +17,20 @@ from __future__ import print_function
import argparse
import os
import sys
+import copy
from gkeys.fileops import ensure_dirs
from gkeys.log import log_levels, set_logger
+from gkeys.gkey import GKEY
+if sys.version_info[0] >= 3:
+ from urllib.request import urlopen
+ py_input = input
+ _unicode = str
+else:
+ from urllib2 import urlopen
+ py_input = raw_input
+ _unicode = unicode
if sys.version_info[0] >= 3:
unicode = str
@@ -291,6 +301,10 @@ class CliBase(object):
for opt in options:
getattr(self, '_option_%s' % opt)(parser)
+ def warning_output(self, info):
+ ''' We don't want this message to be spammed 4 times everytime gkeys is run'''
+ if "Re-fetch cycle timeout of" not in info:
+ print(info)
def setup(self, args, configs):
'''Set up the args and configs passed in
@@ -352,7 +366,59 @@ class CliBase(object):
'''
# establish our actions instance
self.actions = self.cli_config['Actions'](self.config, self.output_results, self.logger)
-
+ # check for seed update
+ from sslfetch.connections import Connector
+ connector_output = {
+ 'info': self.logger.info,
+ 'debug': self.logger.debug,
+ 'error': self.logger.error,
+ 'exception': self.logger.exception,
+ 'warning': self.warning_output,
+ 'kwargs-info': {},
+ 'kwargs-debug': {},
+ 'kwargs-error': {},
+ 'kwargs-exception': {},
+ 'kwargs-warning': {},
+ }
+ fetcher = Connector(connector_output, None, "Gentoo Keys")
+ successes = []
+ up_to_date = True
+ categories = list(self.config.defaults['seeds'])
+ '''Attemp to download seed and seed.sig files for each available category'''
+ for category in categories:
+ filepath = self.config.defaults['seedsdir'] + "/" + category + ".seeds"
+ timestamp_path = filepath + ".timestamp"
+ url = self.config.defaults['seedurls'][category]
+ success, signedfile, timestamp = fetcher.fetch_file(
+ url, filepath, timestamp_path)
+ if timestamp != "":
+ up_to_date = False
+ successes.append(success)
+ url += ".sig"
+ filepath += ".sig"
+ success, signedfile, timestamp = fetcher.fetch_file(
+ url, filepath, timestamp_path)
+ if timestamp != "":
+ up_to_date = False
+ successes.append(success)
+ if False not in successes and not up_to_date:
+ print("Seeds need to be updated")
+ ack = None
+ while ack not in ("y", "yes", "n", "no"):
+ ack = py_input("Would you like to update the seeds now? (y/n) ").lower()
+ if ack in ("y", "yes"):
+ custom_args = copy.copy(args)
+ for attr in GKEY._fields:
+ if attr != "debug":
+ custom_args.attr = None
+ custom_args.category = None
+ custom_args.action = "update-seed"
+ print("Updating seeds")
+ self.run(custom_args)
+ elif False not in successes:
+ print("Seeds are up to date")
+ else:
+ print("Seed update check failed, check your internet connection.")
# run the action
func = getattr(self.actions, '%s'
% self.cli_config['Action_Map'][args.action]['func'])
diff --git a/gkeys/gkeys/seedhandler.py b/gkeys/gkeys/seedhandler.py
index c7dad2e..90ce583 100644
--- a/gkeys/gkeys/seedhandler.py
+++ b/gkeys/gkeys/seedhandler.py
@@ -78,21 +78,28 @@ class SeedHandler(object):
@param seeds2: set of seeds to be compared
@return added_gkeys: list of keys that are included in seed2 but not seed1
@return changed_gkeys: list of keys that are included in seed1 and seed2 but have been altered
+ @return removed_gkeys: list of keys that are included in seed1 but not in seed2
'''
old_gkeys = seeds1[1]
new_gkeys = seeds2[1]
changed_gkeys = []
+ old_changed_gkeys = []
+ removed_gkeys = []
added_gkeys = []
if old_gkeys:
for new_gkey in new_gkeys:
for old_gkey in old_gkeys:
if new_gkey.nick == old_gkey.nick and new_gkey != old_gkey:
changed_gkeys.append(new_gkey)
+ old_changed_gkeys.append(old_gkey)
if new_gkey not in old_gkeys and new_gkey not in changed_gkeys:
added_gkeys.append(new_gkey)
+ for old_gkey in old_gkeys:
+ if old_gkey not in new_gkeys and old_gkey not in old_changed_gkeys:
+ removed_gkeys.append(old_gkey)
else:
added_gkeys = new_gkeys
- return(added_gkeys, changed_gkeys)
+ return(added_gkeys, changed_gkeys, removed_gkeys)
def load_seeds(self, seedfile=None, filepath=None, refresh=False):
'''Load seed file
^ permalink raw reply related [flat|nested] 40+ messages in thread
* [gentoo-commits] proj/gentoo-keys:gsoc-2016 commit in: gkeys/gkeys/
@ 2016-12-24 9:41 Brian Dolbec
0 siblings, 0 replies; 40+ messages in thread
From: Brian Dolbec @ 2016-12-24 9:41 UTC (permalink / raw
To: gentoo-commits
commit: 59baf2fa65964e2cc8134f414d9536e7dcde5d9f
Author: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Sat Dec 24 09:11:08 2016 +0000
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Sat Dec 24 09:40:27 2016 +0000
URL: https://gitweb.gentoo.org/proj/gentoo-keys.git/commit/?id=59baf2fa
gkeys base.py: Remove the auto-update code from run()
This code was causing the fetch-seed action to fail with empty urls to connect to.
This code should also not be running directly from the CliBase class.
I'll move this code to the actions or lib class, to be determined later.
gkeys/gkeys/base.py | 54 -----------------------------------------------------
1 file changed, 54 deletions(-)
diff --git a/gkeys/gkeys/base.py b/gkeys/gkeys/base.py
index 28dd0b2..a67b330 100644
--- a/gkeys/gkeys/base.py
+++ b/gkeys/gkeys/base.py
@@ -358,7 +358,6 @@ class CliBase(object):
return False
return True
-
def run(self, args):
'''Run the action selected
@@ -366,59 +365,6 @@ class CliBase(object):
'''
# establish our actions instance
self.actions = self.cli_config['Actions'](self.config, self.output_results, self.logger)
- # check for seed update
- from sslfetch.connections import Connector
- connector_output = {
- 'info': self.logger.info,
- 'debug': self.logger.debug,
- 'error': self.logger.error,
- 'exception': self.logger.exception,
- 'warning': self.warning_output,
- 'kwargs-info': {},
- 'kwargs-debug': {},
- 'kwargs-error': {},
- 'kwargs-exception': {},
- 'kwargs-warning': {},
- }
- fetcher = Connector(connector_output, None, "Gentoo Keys")
- successes = []
- up_to_date = True
- categories = list(self.config.defaults['seeds'])
- '''Attemp to download seed and seed.sig files for each available category'''
- for category in categories:
- filepath = self.config.defaults['seedsdir'] + "/" + category + ".seeds"
- timestamp_path = filepath + ".timestamp"
- url = self.config.defaults['seedurls'][category]
- success, signedfile, timestamp = fetcher.fetch_file(
- url, filepath, timestamp_path)
- if timestamp != "":
- up_to_date = False
- successes.append(success)
- url += ".sig"
- filepath += ".sig"
- success, signedfile, timestamp = fetcher.fetch_file(
- url, filepath, timestamp_path)
- if timestamp != "":
- up_to_date = False
- successes.append(success)
- if False not in successes and not up_to_date:
- print("Seeds need to be updated")
- ack = None
- while ack not in ("y", "yes", "n", "no"):
- ack = py_input("Would you like to update the seeds now? (y/n) ").lower()
- if ack in ("y", "yes"):
- custom_args = copy.copy(args)
- for attr in GKEY._fields:
- if attr != "debug":
- custom_args.attr = None
- custom_args.category = None
- custom_args.action = "update-seed"
- print("Updating seeds")
- self.run(custom_args)
- elif False not in successes:
- print("Seeds are up to date")
- else:
- print("Seed update check failed, check your internet connection.")
# run the action
func = getattr(self.actions, '%s'
% self.cli_config['Action_Map'][args.action]['func'])
^ permalink raw reply related [flat|nested] 40+ messages in thread
* [gentoo-commits] proj/gentoo-keys:gsoc-2016 commit in: gkeys/gkeys/
@ 2016-12-24 9:41 Brian Dolbec
0 siblings, 0 replies; 40+ messages in thread
From: Brian Dolbec @ 2016-12-24 9:41 UTC (permalink / raw
To: gentoo-commits
commit: bc02e8df0f04fe6546e01a4defda9bd4b7597716
Author: aeroniero33 <justthisthing <AT> gmail <DOT> com>
AuthorDate: Thu Jun 9 22:44:16 2016 +0000
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Sat Dec 24 09:40:26 2016 +0000
URL: https://gitweb.gentoo.org/proj/gentoo-keys.git/commit/?id=bc02e8df
Created the update-seed function
gkeys/gkeys/action_map.py | 19 ++++++++++++++++++-
gkeys/gkeys/actions.py | 14 +++++++++++++-
2 files changed, 31 insertions(+), 2 deletions(-)
diff --git a/gkeys/gkeys/action_map.py b/gkeys/gkeys/action_map.py
index f372a5c..1bd0625 100644
--- a/gkeys/gkeys/action_map.py
+++ b/gkeys/gkeys/action_map.py
@@ -15,7 +15,8 @@ from collections import OrderedDict
Seed_Actions = ['----seeds----', 'add-seed', 'fetch-seed',
- 'list-seed', 'list-seedfiles', 'move-seed', 'remove-seed']
+ 'update-seed', 'list-seed', 'list-seedfiles', 'move-seed',
+ 'remove-seed']
Key_Actions = ['----keys-----', 'check-key', 'installed',
'install-key', 'list-key', 'send-key', 'refresh-key', 'remove-key',
@@ -380,6 +381,22 @@ Found Failures:
Fetch operation completed
''',
}),
+ ('update-seed', {
+ 'func': 'updateseed',
+ 'options': ['category', 'nick', '1file', 'dest', 'signature',
+ 'timestamp'],
+ 'desc': '''Update the selected seed file(s)''',
+ 'long_desc': '''Update the selected seed file(s)''',
+ 'example': '''$ gkeys update-seed -C gentoo-devs
+
+ Gkey task results:
+ Verification succeeded.: /home/brian/gpg-test/seeds/gentoo-devs.seeds
+ Key info...............: Gentoo-Linux Gentoo-keys Project Signing Key <gkeys>, 0xA41DBBD9151C3FC7
+ category, nick.....: gentoo gkeys
+
+ Update operation completed
+''',
+ }),
('list-seed', {
'func': 'listseed',
'options': ['category', 'nick', 'name', 'fingerprint', 'keys',
diff --git a/gkeys/gkeys/actions.py b/gkeys/gkeys/actions.py
index 49fa68b..c75d766 100644
--- a/gkeys/gkeys/actions.py
+++ b/gkeys/gkeys/actions.py
@@ -96,7 +96,19 @@ class Actions(ActionBase):
messages.append("")
messages.append("Fetch operation completed")
return (False not in success, messages)
-
+
+ def updateseed(self, args):
+ '''Updates seeds of a selected file'''
+ self.logger.debug(_unicode("ACTIONS: updateseed; args: %s")
+ % _unicode(args))
+ fetch_success, fetch_messages = self.fetchseed(args)
+ if fetch_success is not True:
+ return (False, fetch_messages)
+ install_success, install_messages = self.installkey(args)
+ if install_success is not True:
+ return (False, install_messages)
+ messages = fetch_messages + [install_messages]
+ return (True, messages)
def addseed(self, args):
'''Add or replace a key in the selected seed file'''
^ permalink raw reply related [flat|nested] 40+ messages in thread
* [gentoo-commits] proj/gentoo-keys:gsoc-2016 commit in: gkeys/gkeys/
@ 2016-12-24 9:41 Brian Dolbec
0 siblings, 0 replies; 40+ messages in thread
From: Brian Dolbec @ 2016-12-24 9:41 UTC (permalink / raw
To: gentoo-commits
commit: 6a438b21c7a16d851da1189cd6a522cb1b3cd2c4
Author: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Sat Dec 24 09:08:14 2016 +0000
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Sat Dec 24 09:40:27 2016 +0000
URL: https://gitweb.gentoo.org/proj/gentoo-keys.git/commit/?id=6a438b21
gkeys seedhandler.py: Add another debug log for the seedurl and seedpath
This is to aid in troubleshooting fetch-sedd url errors.
gkeys/gkeys/seedhandler.py | 1 +
1 file changed, 1 insertion(+)
diff --git a/gkeys/gkeys/seedhandler.py b/gkeys/gkeys/seedhandler.py
index 90ce583..f36d3e2 100644
--- a/gkeys/gkeys/seedhandler.py
+++ b/gkeys/gkeys/seedhandler.py
@@ -186,6 +186,7 @@ class SeedHandler(object):
for seed in [seeds]:
seedurl = self.config.get_key('seedurls', seed)
seedpath = self.config.get_key('seeds', seed)
+ self.logger.debug("Seed URL/seed path...: %s, %s" % (seedurl, seedpath))
if seedurl and seedpath and http_check.match(seedurl):
urls.extend([(seed, seedurl, seedpath)])
else:
^ permalink raw reply related [flat|nested] 40+ messages in thread
* [gentoo-commits] proj/gentoo-keys:gsoc-2016 commit in: gkeys/gkeys/
@ 2016-12-24 9:41 Brian Dolbec
0 siblings, 0 replies; 40+ messages in thread
From: Brian Dolbec @ 2016-12-24 9:41 UTC (permalink / raw
To: gentoo-commits
commit: 82fb94f1ab462d303c150de52f93945b77599c95
Author: aeroniero33 <justthisthing <AT> gmail <DOT> com>
AuthorDate: Sat Jun 18 16:59:58 2016 +0000
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Sat Dec 24 09:40:26 2016 +0000
URL: https://gitweb.gentoo.org/proj/gentoo-keys.git/commit/?id=82fb94f1
Fixed a bug in the verify function
gkeys/gkeys/actions.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/gkeys/gkeys/actions.py b/gkeys/gkeys/actions.py
index 12b8efa..49fa68b 100644
--- a/gkeys/gkeys/actions.py
+++ b/gkeys/gkeys/actions.py
@@ -749,7 +749,6 @@ class Actions(ActionBase):
messages.append(_unicode("Using config defaults..: %s %s")
% (args.category, args.nick))
return self.verify(args, messages)
-
return self._verify(args, key, messages)
@@ -838,6 +837,8 @@ class Actions(ActionBase):
break
else:
sig_path = None
+ elif signature:
+ sig_path = os.path.abspath(signature)
self.logger.info("Verifying file...")
verified = False
results = self.gpg.verify_file(key, sig_path, filepath)
^ permalink raw reply related [flat|nested] 40+ messages in thread
* [gentoo-commits] proj/gentoo-keys:gsoc-2016 commit in: gkeys/gkeys/
@ 2016-12-24 9:41 Brian Dolbec
0 siblings, 0 replies; 40+ messages in thread
From: Brian Dolbec @ 2016-12-24 9:41 UTC (permalink / raw
To: gentoo-commits
commit: 25078b804c7c176fc79631ec5cab9fd1f4cc2e25
Author: Pavlos Ratis <dastergon <AT> dastergon <DOT> gr>
AuthorDate: Sun Aug 28 18:02:54 2016 +0000
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Sat Dec 24 09:40:27 2016 +0000
URL: https://gitweb.gentoo.org/proj/gentoo-keys.git/commit/?id=25078b80
remove debug print
gkeys/gkeys/actions.py | 1 -
1 file changed, 1 deletion(-)
diff --git a/gkeys/gkeys/actions.py b/gkeys/gkeys/actions.py
index bb71496..71ed081 100644
--- a/gkeys/gkeys/actions.py
+++ b/gkeys/gkeys/actions.py
@@ -647,7 +647,6 @@ class Actions(ActionBase):
keyresults = seeds.list(**kwargs)
self.output('', '\n Removing keys...')
success = True
- #print(keyresults)
for gkey in sorted(keyresults):
if kwargs['nick'] != '*' and kwargs['nick'] not in gkey.nick:
messages.append(_unicode("%s does not seem to be a valid key.")
^ permalink raw reply related [flat|nested] 40+ messages in thread
end of thread, other threads:[~2016-12-24 9:41 UTC | newest]
Thread overview: 40+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-12-23 8:37 [gentoo-commits] proj/gentoo-keys:gsoc-2016 commit in: gkeys/gkeys/ Brian Dolbec
-- strict thread matches above, loose matches on Subject: below --
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: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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox