* [gentoo-commits] proj/gentoo-keys:master commit in: gkeys-ldap/gkeyldap/, gkeys/gkeys/
@ 2015-01-05 23:12 Brian Dolbec
0 siblings, 0 replies; 2+ messages in thread
From: Brian Dolbec @ 2015-01-05 23:12 UTC (permalink / raw
To: gentoo-commits
commit: 1e10ed38ab63229a1dabb7d77ec386977e3a1ce5
Author: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Sun Jan 4 03:29:52 2015 +0000
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Mon Jan 5 22:14:36 2015 +0000
URL: http://sources.gentoo.org/gitweb/?p=proj/gentoo-keys.git;a=commit;h=1e10ed38
gkeys: Add pub_keyid property to GKEY
Actions like spec-check used keyid property which resulted in double processing and output since now all subkey fingerprints are in the fingerprint field.
Add keys field to remaining places for seedhandling
Fix add_key for the new GKEY.keys field
Add cross saving fingerprints to the new keys field
---
gkeys-ldap/gkeyldap/actions.py | 1 +
gkeys-ldap/gkeyldap/search.py | 2 ++
gkeys/gkeys/actions.py | 26 +++++++++++++++-----------
gkeys/gkeys/base.py | 2 +-
gkeys/gkeys/gkey.py | 6 ++++++
gkeys/gkeys/lib.py | 4 ++--
gkeys/gkeys/seed.py | 4 ++--
gkeys/gkeys/seedhandler.py | 27 ++++++++++++++++++---------
8 files changed, 47 insertions(+), 25 deletions(-)
diff --git a/gkeys-ldap/gkeyldap/actions.py b/gkeys-ldap/gkeyldap/actions.py
index 1c499aa..45fff09 100644
--- a/gkeys-ldap/gkeyldap/actions.py
+++ b/gkeys-ldap/gkeyldap/actions.py
@@ -181,6 +181,7 @@ class Actions(object):
# drop keyid and longkeyid
keyinfo.pop('keyid', None)
keyinfo.pop('longkeyid', None)
+ keyinfo['keys'] = keyinfo['fingerprint']
return keyinfo
return None
diff --git a/gkeys-ldap/gkeyldap/search.py b/gkeys-ldap/gkeyldap/search.py
index 1bce9e1..c13527f 100644
--- a/gkeys-ldap/gkeyldap/search.py
+++ b/gkeys-ldap/gkeyldap/search.py
@@ -64,5 +64,7 @@ class LdapSearch(object):
for entry in results:
info = entry[1]
key_value = info[key][0]
+ if key_value in ['fingerprint']:
+ _dict['keys'] = info
_dict[key_value] = info
return _dict
diff --git a/gkeys/gkeys/actions.py b/gkeys/gkeys/actions.py
index 6f8fa11..b63f3f1 100644
--- a/gkeys/gkeys/actions.py
+++ b/gkeys/gkeys/actions.py
@@ -272,13 +272,17 @@ class Actions(object):
'''Add or replace a key in the selected seed file'''
handler = SeedHandler(self.logger, self.config)
gkeys = self.listseed(args)[1]
- if not args.nick or not args.name or not args.fingerprint:
- return (False, ["Provide a nickname, a name and a fingerprint."])
+ if not args.nick or not args.name or not args.keys or not args.keydir:
+ return (False, ["Provide a nickname, a name and a public key fingerprint (-K, --keys)."])
+ if not args.fingerprint:
+ args.fingerprint = args.keys
+ if args.uid is None:
+ args.uid = []
gkey = handler.new(args, checkgkey=True)
if not gkey:
return (False, ["Failed to create a valid GKEY instance.",
"Check for invalid data entries"])
- if len(gkeys) == 0:
+ if len(gkeys[1]) == 0:
self.logger.debug("ACTIONS: installkey; now adding gkey: %s" % str(gkey))
success = self.seeds.add(getattr(gkey, 'nick'), gkey)
if success:
@@ -499,12 +503,12 @@ class Actions(object):
keyresults = seeds.list(**kwargs)
self.output('', '\n Checking keys...')
for gkey in sorted(keyresults):
- self.logger.info("Checking key %s, %s" % (gkey.nick, gkey.keyid))
+ self.logger.info("Checking key %s, %s" % (gkey.nick, gkey.pub_keyid))
self.output('',
- "\n %s, %s: %s" % (gkey.nick, gkey.name, ', '.join(gkey.keyid)) +
+ "\n %s, %s: %s" % (gkey.nick, gkey.name, ', '.join(gkey.pub_keyid)) +
"\n ==============================================")
self.logger.debug("ACTIONS: checkkey; gkey = %s" % str(gkey))
- for key in gkey.keyid:
+ for key in gkey.pub_keyid:
results[gkey.name] = self.gpg.check_keys(gkey.keydir, key)
if results[gkey.name].expired:
failed['expired'].append("%s <%s>: %s" % (gkey.name, gkey.nick, key))
@@ -547,12 +551,12 @@ class Actions(object):
keyresults = seeds.list(**kwargs)
self.output('', '\n Checking keys...')
for gkey in sorted(keyresults):
- self.logger.info("Checking key %s, %s" % (gkey.nick, gkey.keyid))
+ self.logger.info("Checking key %s, %s" % (gkey.nick, gkey.keys))
self.output('',
- "\n %s, %s: %s" % (gkey.nick, gkey.name, ', '.join(gkey.keyid)) +
+ "\n %s, %s: %s" % (gkey.nick, gkey.name, ', '.join(gkey.pub_keyid)) +
"\n ==============================================")
self.logger.debug("ACTIONS: speccheck; gkey = %s" % str(gkey))
- for key in gkey.keyid:
+ for key in gkey.keys:
results = self.gpg.speccheck(gkey.keydir, key)
for g in results:
pub_pass = {}
@@ -990,8 +994,8 @@ class Actions(object):
keyresults = seeds.list(**kwargs)
self.output('', '\n Refreshig keys...')
for gkey in sorted(keyresults):
- self.logger.info("Refreshig key %s, %s" % (gkey.nick, gkey.keyid))
- self.output('', " %s: %s" % (gkey.name, ', '.join(gkey.keyid)))
+ self.logger.info("Refreshig key %s, %s" % (gkey.nick, gkey.pub_keyid))
+ self.output('', " %s: %s" % (gkey.name, ', '.join(gkey.pub_keyid)))
#self.output('', " ===============")
self.logger.debug("ACTIONS: refreshkey; gkey = %s" % str(gkey))
results[gkey.keydir] = self.gpg.refresh_key(gkey)
diff --git a/gkeys/gkeys/base.py b/gkeys/gkeys/base.py
index 9d47fe0..05946c2 100644
--- a/gkeys/gkeys/base.py
+++ b/gkeys/gkeys/base.py
@@ -186,7 +186,7 @@ class CliBase(object):
@staticmethod
def _option_uid(parser=None):
- parser.add_argument('-u', '--uid', dest='uid', nargs='*', default=None,
+ parser.add_argument('-u', '--uid', dest='uid', nargs='+', default=None,
help='The user ID, gpg key uid')
diff --git a/gkeys/gkeys/gkey.py b/gkeys/gkeys/gkey.py
index 130a5d5..a305804 100644
--- a/gkeys/gkeys/gkey.py
+++ b/gkeys/gkeys/gkey.py
@@ -45,6 +45,12 @@ class GKEY(namedtuple('GKEY', ['nick', 'name', 'keydir', 'keys', 'fingerprint',
@property
+ def pub_keyid(self):
+ '''Keyid is a substring value of the keys fingerprints'''
+ return ['0x' + x[-16:] for x in self.keys]
+
+
+ @property
def pretty_print(self):
'''Pretty printing a GKEY'''
gkey = {
diff --git a/gkeys/gkeys/lib.py b/gkeys/gkeys/lib.py
index 6bb3d5b..6020322 100644
--- a/gkeys/gkeys/lib.py
+++ b/gkeys/gkeys/lib.py
@@ -136,14 +136,14 @@ class GkeysGPG(GPG):
ensure_dirs(str(self.keydir), mode=mode)
self.set_keyseedfile(trap_errors=False)
results = []
- for fingerprint in gkey.fingerprint:
+ for fingerprint in gkey.keys:
self.logger.debug("LIB: add_key; adding fingerprint " + fingerprint)
self.logger.debug("** Calling runGPG with Running 'gpg %s --recv-keys %s' for: %s"
% (' '.join(self.config.get_key('tasks', 'recv-keys')),
fingerprint, gkey.name))
result = self.runGPG(task='recv-keys', inputfile=fingerprint)
self.logger.info('GPG return code: ' + str(result.returncode))
- if result.fingerprint in gkey.fingerprint:
+ if result.fingerprint in gkey.keys:
result.failed = False
message = "Fingerprints match... Import successful: "
message += "%s, fingerprint: %s" % (gkey.nick, fingerprint)
diff --git a/gkeys/gkeys/seed.py b/gkeys/gkeys/seed.py
index 15c9e2c..7d9ae4e 100644
--- a/gkeys/gkeys/seed.py
+++ b/gkeys/gkeys/seed.py
@@ -139,9 +139,9 @@ class Seeds(object):
keys = kwargs
result = self.seeds
for key in keys:
- if key in ['fingerprint', 'keyid']:
+ if key in ['fingerprint', 'keys', 'keyid']:
kwargs[key] = [x.replace(' ', '').upper() for x in kwargs[key]]
- if key in ['fingerprint']:
+ if key in ['fingerprint', 'keys', 'uid']:
result = {dev: gkey for dev, gkey in list(result.items()) if kwargs[key][0] in getattr(gkey, key)}
elif key in ['keyid']:
searchids = [x.lstrip('0X') for x in kwargs[key]]
diff --git a/gkeys/gkeys/seedhandler.py b/gkeys/gkeys/seedhandler.py
index 9540ee0..600ac35 100644
--- a/gkeys/gkeys/seedhandler.py
+++ b/gkeys/gkeys/seedhandler.py
@@ -48,12 +48,12 @@ class SeedHandler(object):
@staticmethod
def build_gkeydict(args):
keyinfo = {}
- for attr in GKEY._fields + ('keyid',):
+ for attr in GKEY._fields:
try:
value = getattr(args, attr)
if attr == 'name' and value:
value = " ".join(value)
- if value:
+ if value is not None:
keyinfo[attr] = value
except AttributeError:
pass
@@ -171,21 +171,30 @@ class SeedHandler(object):
try:
args['keydir'] = args.get('keydir', args['nick'])
fprs = []
- if args['fingerprint']:
- for fpr in args['fingerprint']:
+ keys = []
+ if args['keys'] or args['fingerprint']:
+ for fpr in args['keys']:
is_good, fingerprint = self._check_fingerprint_integrity(fpr)
if is_good:
- fprs.append(fingerprint)
+ keys.append(fingerprint)
else:
- self.logger.error('Bad fingerprint from command line args: %s' % fpr)
+ self.logger.error('Bad key from command line args: %s' % fpr)
if is_good:
- args['fingerprint'] = fprs
+ args['keys'] = keys
+ for fpr in args['fingerprint']:
+ is_good, fingerprint = self._check_fingerprint_integrity(fpr)
+ if is_good:
+ fprs.append(fingerprint)
+ else:
+ self.logger.error('Bad fingerprint from command line args: %s' % fpr)
+ if is_good:
+ args['fingerprint'] = fprs
except KeyError:
self.logger.error('GPG fingerprint not found.')
is_good = False
if not is_good:
- self.logger.error('A valid fingerprint '
- 'was not found for %s' % args['name'])
+ self.logger.error('An invalid key or fingerprint '
+ 'was found for %s' % args['name'])
return args, is_good
def _check_fingerprint_integrity(self, fpr):
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [gentoo-commits] proj/gentoo-keys:master commit in: gkeys-ldap/gkeyldap/, gkeys/gkeys/
@ 2015-01-05 23:12 Brian Dolbec
0 siblings, 0 replies; 2+ messages in thread
From: Brian Dolbec @ 2015-01-05 23:12 UTC (permalink / raw
To: gentoo-commits
commit: ccb9e31c253a0f4ae9c096ce571a7c7109a33fd0
Author: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Mon Jan 5 08:56:12 2015 +0000
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Mon Jan 5 22:21:53 2015 +0000
URL: http://sources.gentoo.org/gitweb/?p=proj/gentoo-keys.git;a=commit;h=ccb9e31c
gkeys, gkeyldap: Update updatefiles() config handling
Add category and filename options, ensure 1 of them is passed in.
Fix logic error that did not report the failure to find the file to update.
---
gkeys-ldap/gkeyldap/actions.py | 2 +-
gkeys/gkeys/fileops.py | 55 ++++++++++++++++++++++++------------------
2 files changed, 32 insertions(+), 25 deletions(-)
diff --git a/gkeys-ldap/gkeyldap/actions.py b/gkeys-ldap/gkeyldap/actions.py
index dde2bc8..4a3db84 100644
--- a/gkeys-ldap/gkeyldap/actions.py
+++ b/gkeys-ldap/gkeyldap/actions.py
@@ -107,7 +107,7 @@ class Actions(object):
self.logger.error("Developer seed file update failure: "
"Original seed file is intact & untouched.")
self.output('', "Backing up existing file...")
- status = updatefiles(self.config, self.logger)
+ status = updatefiles(self.config, self.logger, args.category)
if not status:
self.output('', "Develope seed failed to update!")
return False
diff --git a/gkeys/gkeys/fileops.py b/gkeys/gkeys/fileops.py
index 7cb244f..5b89ea8 100644
--- a/gkeys/gkeys/fileops.py
+++ b/gkeys/gkeys/fileops.py
@@ -30,27 +30,34 @@ def ensure_dirs(path, gid=-1, uid=-1, mode=0o700, minimal=True, failback=None, f
return succeeded
-def updatefiles(config, logger):
- filename = config['dev-seedfile']
- old = filename + '.old'
- try:
- logger.info("Backing up existing file...")
- if os.path.exists(old):
- logger.debug(
- "MAIN: _action_updatefile; Removing 'old' seed file: %s"
- % old)
- os.unlink(old)
- if os.path.exists(filename):
- logger.debug(
- "MAIN: _action_updatefile; Renaming current seed file to: "
- "%s" % old)
- os.rename(filename, old)
- if os.path.exists(filename + '.new'):
- logger.debug(
- "MAIN: _action_updatefile; Renaming '.new' seed file to: %s"
- % filename)
- os.rename(filename + '.new', filename)
- except IOError:
- raise
- return False
- return True
+def updatefiles(config, logger, category=None, filename = None):
+ if category and not filename:
+ filename = config.get_key('seeds', category)
+ elif not filename:
+ logger.error("MAIN: updatefiles(); category or filename not supplied")
+ return False
+ old = filename + '.old'
+ try:
+ logger.info("Backing up existing file...")
+ if os.path.exists(old):
+ logger.debug(
+ "MAIN: updatefiles(); Removing 'old' seed file: %s"
+ % old)
+ os.unlink(old)
+ if os.path.exists(filename):
+ logger.debug(
+ "MAIN: updatefiles(); Renaming current seed file to: "
+ "%s" % old)
+ os.rename(filename, old)
+ if os.path.exists(filename + '.new'):
+ logger.debug(
+ "MAIN: updatefiles(); Renaming '.new' seed file to: %s"
+ % filename)
+ os.rename(filename + '.new', filename)
+ else:
+ logger.error("MAIN: updatefiles(); Renaming "
+ "'%s.new' seed DOES NOT EXIST!" % filename)
+ except IOError:
+ raise
+ return False
+ return True
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-01-05 23:12 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-05 23:12 [gentoo-commits] proj/gentoo-keys:master commit in: gkeys-ldap/gkeyldap/, gkeys/gkeys/ Brian Dolbec
-- strict thread matches above, loose matches on Subject: below --
2015-01-05 23:12 Brian Dolbec
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox