public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/gentoo-keys:master commit in: etc/, gkeys/
@ 2012-12-10  3:26 Brian Dolbec
  0 siblings, 0 replies; 5+ messages in thread
From: Brian Dolbec @ 2012-12-10  3:26 UTC (permalink / raw
  To: gentoo-commits

commit:     308f68f98b01d9980790816d3a4bf64d0008786b
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Mon Dec 10 03:23:51 2012 +0000
Commit:     Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Mon Dec 10 03:23:51 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-keys.git;a=commit;h=308f68f9

hyphenate the config file variables, make config handling work.

---
 etc/gkeys.conf  |   23 +++++++++++++++++------
 gkeys/config.py |   33 +++++++++++++++++++++------------
 2 files changed, 38 insertions(+), 18 deletions(-)

diff --git a/etc/gkeys.conf b/etc/gkeys.conf
index 6b7c929..de39db5 100644
--- a/etc/gkeys.conf
+++ b/etc/gkeys.conf
@@ -4,24 +4,35 @@
 [MAIN]
 
 # keysdir: base directory to store the binary keyrings and data
-keysdir: /home/brian/gpg-test
+keys-dir: /var/lib/gentoo
+
 
 # devkeydir: the directory where the gentoo developer keys
 # will be stored.
-devkeydir: %(keysdir)s/devs
+dev-keydir: %(keysdir)s/devs
+
 
 # releaskeydir: the directory where the official release media keys
 # will be stored.
-releasekeydir: %(keysdir)s/release
+release-keydir: %(keysdir)s/release
+
+
+# overlayskeydir: the directory where the overlay keys
+# will be stored.
+overlays-keydir: %(keysdir)s/overlays
+
 
 # knownkeysfile: txt file to hold a cache of the
 # installed (name, keyid, fingerprint) keys
-knownkeysfile:  %(keysdir)s/knownkeys
+known-keysfile:  %(keysdir)s/knownkeys
+
 
 # releaseseedfile: txt file of one tuple of (name, keyid, fingerprint)
 # entry per line
-releaseseedfile: /etc/gentoo-keys/release.seeds
+release-seedfile: /etc/gentoo-keys/release.seeds
+
 
 # devseedfile: txt file of one tuple of (name, keyid, fingerprint)
 # entry per line
-devseedfile: /etc/gentoo-keys/developer.seeds
+dev-seedfile: /etc/gentoo-keys/developer.seeds
+

diff --git a/gkeys/config.py b/gkeys/config.py
index a15ec55..3695242 100644
--- a/gkeys/config.py
+++ b/gkeys/config.py
@@ -34,7 +34,7 @@ class GKeysConfig(GPGConfig):
     """ Configuration superclass which holds our gentoo-keys
     config settings for pygpg """
 
-    def __init__ (self, config=None, root=None):
+    def __init__ (self, config=None, root=None, read_configfile=False):
         """ Class initialiser """
         GPGConfig.__init__(self)
 
@@ -46,18 +46,18 @@ class GKeysConfig(GPGConfig):
             self.defaults['configdir'] = path([self.root, EPREFIX, '/etc/gentoo-keys'])
             self.defaults['config'] = '%(configdir)s/gkeys.conf'
         self.configparser = None
-
-        # read our config file overrides
-        self.read_config()
+        if read_configfile:
+            self.read_config()
 
 
     def _add_gkey_defaults(self):
-        self.defaults['keysdir'] = path([self.root, EPREFIX, '/var/gentoo/gkeys'])
-        self.defaults['devkeydir'] = '%(keysdir)s/devs'
-        self.defaults['releasekeydir'] = '%(keysdir)s/release'
-        self.defaults['knownkeysfile'] = '%(keysdir)s/knownkeys'
-        self.fedualts['releaseseedfile'] = '%(configdir)s/release.seeds'
-        self.fedualts['devseedfile'] = '%(configdir)s/developer.seeds'
+        self.defaults['key-sdir'] = path([self.root, EPREFIX, '/var/gentoo/gkeys'])
+        self.defaults['dev-keydir'] = '%(keysdir)s/devs'
+        self.defaults['release-keydir'] = '%(keysdir)s/release'
+        self.defaults['overlays-keydir'] = '%(keysdir)s/overlays'
+        self.defaults['known-keysfile'] = '%(keysdir)s/knownkeys'
+        self.defaults['release-seedfile'] = '%(configdir)s/release.seeds'
+        self.defaults['dev-seedfile'] = '%(configdir)s/developer.seeds'
 
 
 
@@ -73,11 +73,20 @@ class GKeysConfig(GPGConfig):
         self.configparser.add_section('MAIN')
         self.configparser.read(defaults['config'])
 
+
+    def get_key(self, key):
+        return self._get_(key)
+
+
     def _get_(self, key):
         if self.configparser and self.configparser.has_option('MAIN', key):
             return self.configparser.get('MAIN', key)
-        else:
-            super('GKeysConfig', self)._get_(key)
+        elif key in self.options:
+            return self.options[key]
+        elif key in self.defaults:
+            return self.defaults[key]
+        logger.error("GKeysConfig: _get_(); didn't find :", key)
+        return None
 
 
 class GKEY(namedtuple('GKEY', ['name', 'keyid', 'longkeyid',


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [gentoo-commits] proj/gentoo-keys:master commit in: etc/, gkeys/
@ 2013-11-10  1:01 Brian Dolbec
  0 siblings, 0 replies; 5+ messages in thread
From: Brian Dolbec @ 2013-11-10  1:01 UTC (permalink / raw
  To: gentoo-commits

commit:     e27dfb1acd82f3559c91d03d36302a98fa3f14a7
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Sat Jul 27 12:43:34 2013 +0000
Commit:     Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Sat Jul 27 12:43:34 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-keys.git;a=commit;h=e27dfb1a

Add keyserver config option

---
 etc/gkeys.conf  |  4 ++++
 gkeys/config.py |  1 +
 gkeys/lib.py    | 64 ++++++++++++++++++++++++++++++++++++---------------------
 3 files changed, 46 insertions(+), 23 deletions(-)

diff --git a/etc/gkeys.conf b/etc/gkeys.conf
index 5b91597..46d45aa 100644
--- a/etc/gkeys.conf
+++ b/etc/gkeys.conf
@@ -3,6 +3,10 @@
 
 [MAIN]
 
+# keyserver: server to use to obtain the keys from
+keyserver: pool.sks-keyservers.net
+
+
 # keysdir: base directory to store the binary keyrings and data
 keysdir: /var/lib/gentoo
 

diff --git a/gkeys/config.py b/gkeys/config.py
index 96b4aee..fe78dec 100644
--- a/gkeys/config.py
+++ b/gkeys/config.py
@@ -61,6 +61,7 @@ class GKeysConfig(GPGConfig):
         self.defaults['known-keysfile'] = '%(keysdir)s/knownkeys'
         self.defaults['release-seedfile'] = '%(configdir)s/release.seeds'
         self.defaults['dev-seedfile'] = '%(configdir)s/developer.seeds'
+        self.defaults['keyserver'] = 'pool.sks-keyservers.net'
 
 
 

diff --git a/gkeys/lib.py b/gkeys/lib.py
index a97b7e7..66e27dc 100644
--- a/gkeys/lib.py
+++ b/gkeys/lib.py
@@ -16,6 +16,7 @@ with gentoo-keys specific convienience functions.
 
 '''
 
+import os
 from os.path import join as pjoin
 
 from pyGPG.gpg import GPG
@@ -33,38 +34,52 @@ class GkeysGPG(GPG):
         @param keydir: string, the path to the keydir to be used
                         for all operations.
         '''
-        GPG.__init__(self, config)
+        GPG.__init__(self, config, logger)
         self.config = config
         self.basedir = keydir
         self.keydir = None
-        self.task = None
-        self.task_value = None
+        self.server = None
 
 
-    def set_keypath(self, keyring, task=None):
+    def set_keyserver(self, server=None):
+        '''Set the keyserver and add the --keyserver option to the gpg defaults
+        '''
+        if self.server and not server:
+            return
+        self.server = server or self.config['keyserver']
+        self.config.options['gpg_defaults'] = self.config.defaults['gpg_defaults'][:]
+        logger.debug("keyserver: %s" % (self.server))
+        server_value = ['--keyserver', self.server]
+        self.config.options['gpg_defaults'].extend(server_value)
+        logger.debug("self.config.options['gpg_defaults']: %s"
+            % (self.config.options['gpg_defaults']))
+        return
+
+
+    def set_keyring(self, keyring, task, reset=True):
+        '''Sets the keyring to use as well as related task options
+        '''
         logger.debug("keydir: %s, keyring: %s" % (self.keydir, keyring))
-        self.task = task
-        keypath = pjoin(self.keydir, keyring)
+        if reset:
+            self.config.options['tasks'][task] =  self.config.defaults['tasks'][task][:]
         # --keyring file |  Note that this adds a keyring to the current list.
         # If the intent is to use the specified keyring alone,
         # use  --keyring  along with --no-default-keyring.
-        self.task_value = ['--no-default-keyring', '--keyring', keypath]
-        task.extend(self.task_value)
+        task_value = ['--no-default-keyring', '--keyring', keyring]
+        self.config.options['tasks'][task].extend(task_value)
+        logger.debug("set_keyring: New task options: %s" %str(self.config.options['tasks'][task]))
         return
 
 
-    def reset_task(self):
-        if self.task:
-            for item in self.task_value:
-                self.task.remove(item)
-            self.task = None
-            self.task_value = None
-
-
-    def set_keydir(self, keydir):
+    def set_keydir(self, keydir, task, reset=True):
         logger.debug("basedir: %s, keydir: %s" % (self.basedir, keydir))
-        self.task = task
         self.keydir = pjoin(self.basedir, keydir)
+        self.task = task
+        if reset:
+            self.config.options['tasks'][task] = self.config.defaults['tasks'][task][:]
+        task_value = ['--homedir', self.keydir]
+        self.config.options['tasks'][task].extend(task_value)
+        logger.debug("set_keydir: New task options: %s" %str(self.config.options['tasks'][task]))
         return
 
 
@@ -74,7 +89,11 @@ class GkeysGPG(GPG):
         @param gkey: GKEY namedtuple with
             (name, keyid/longkeyid, keydir, fingerprint,)
         '''
-        self.set_keydir(gkey.keydir)
+        self.set_keyserver()
+        self.set_keydir(gkey.keydir, 'recv-keys', reset=True)
+        self.set_keyring('pubring.gpg', 'recv-keys', reset=False)
+        if not os.path.exists(self.keydir):
+            os.makedirs(self.keydir, mode=0700)
 
         # prefer the longkeyid if available
         #logger.debug("LIB: add_key; keyids %s, %s"
@@ -89,7 +108,7 @@ class GkeysGPG(GPG):
         for keyid in keyids:
             logger.debug("LIB: add_key; final keyids" + keyid)
             logger.debug("** Calling runGPG with Running 'gpg %s --recv-keys %s' for: %s"
-                % (' '.join(self.config['tasks']['recv-keys']),
+                % (' '.join(self.config.get_key('tasks', 'recv-keys')),
                     keyid, gkey.name)
                 )
             result = self.runGPG(task='recv-keys', inputfile=keyid)
@@ -149,13 +168,12 @@ class GkeysGPG(GPG):
         if '--with-colons' in self.config['tasks']['list-keys']:
             self.config['tasks']['list-keys'].remove('--with-colons')
 
-        self.set_keydir(keydir)
+        self.set_keydir(keydir, 'list-keys')
         logger.debug("** Calling runGPG with Running 'gpg %s --list-keys %s'"
             % (' '.join(self.config['tasks']['list-keys']), keydir)
             )
-        result = self.runGPG(task='list-keys')
+        result = self.runGPG(task='list-keys', inputfile=keydir)
         logger.info('GPG return code: ' + str(result.returncode))
-        #self.reset_task()
         return result
 
 


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [gentoo-commits] proj/gentoo-keys:master commit in: etc/, gkeys/
@ 2014-03-01  0:54 Brian Dolbec
  0 siblings, 0 replies; 5+ messages in thread
From: Brian Dolbec @ 2014-03-01  0:54 UTC (permalink / raw
  To: gentoo-commits

commit:     11aa646eac0397f32e7617961d4f339f33e52fb8
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Sat Mar  1 00:54:25 2014 +0000
Commit:     Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Sat Mar  1 00:54:25 2014 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-keys.git;a=commit;h=11aa646e

gkeys/actions.py: Add listseedfiles() and fix -S option support.

---
 etc/gkeys.conf   |  9 +++++++--
 gkeys/actions.py | 25 +++++++++++++++++++------
 2 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/etc/gkeys.conf b/etc/gkeys.conf
index 46d45aa..2497c30 100644
--- a/etc/gkeys.conf
+++ b/etc/gkeys.conf
@@ -31,14 +31,19 @@ overlays-keydir: %(keysdir)s/overlays
 known-keysfile:  %(keysdir)s/knownkeys
 
 
+# seedsdir: base directory for all seed files
+# used when searching all seed files.
+seedsdir: %(keysdir)s/seeds
+
+
 # releaseseedfile: txt file of one tuple of (name, keyid, fingerprint)
 # entry per line
-release-seedfile: /etc/gentoo-keys/release.seeds
+release-seedfile: %(seedsdir)s/release.seeds
 
 
 # devseedfile: txt file of one tuple of (name, keyid, fingerprint)
 # entry per line
-dev-seedfile: /etc/gentoo-keys/developer.seeds
+dev-seedfile: %(seedsdir)s/developer.seeds
 
 
 # logfile directory

diff --git a/gkeys/actions.py b/gkeys/actions.py
index 77ac212..2e2b1b7 100644
--- a/gkeys/actions.py
+++ b/gkeys/actions.py
@@ -12,14 +12,17 @@
 
 from __future__ import print_function
 
+import os
+
 
 from gkeys.seedhandler import SeedHandler
 from gkeys.lib import GkeysGPG
 from gkeys.seed import Seeds
 
 
-Avialable_Actions = ['listseed', 'addseed', 'removeseed', 'moveseed', 'listkey',
-            'addkey', 'removekey', 'movekey', 'installed']
+Avialable_Actions = ['listseed', 'addseed', 'removeseed', 'moveseed',
+            'listseedfiles', 'listkey', 'addkey', 'removekey', 'movekey',
+            'installed']
 
 
 class Actions(object):
@@ -32,13 +35,17 @@ class Actions(object):
         self.seeds = None
 
 
-    def load_seeds(self, filename):
-        if not filename:
+    def load_seeds(self, seeds=None ,seedfile=None):
+        if not seeds and not seedfile:
             self.logger.error("ACTIONS: load_seeds; no filename to load: "
             "setting = %s.  Please use the -s option to indicate: which seed "
             "file to use." % filename)
             return None
-        filepath = self.config.get_key(filename + "-seedfile")
+        if seeds:
+            filepath = self.config.get_key(filename + "-seedfile")
+        elif seedfile:
+            filepath = os.path.join(self.config.get_key('seedsdir'),
+                                    '%s.seeds' % seedfile)
         self.logger.debug("ACTIONS: load_seeds; seeds filepath to load: "
             "%s" % filepath)
         seeds = Seeds()
@@ -52,7 +59,7 @@ class Actions(object):
         kwargs = handler.build_gkeydict(args)
         self.logger.debug("ACTIONS: listseed; kwargs: %s" % str(kwargs))
         if not self.seeds:
-            self.seeds = self.load_seeds(args.seeds)
+            self.seeds = self.load_seeds(args.seeds, args.seedfile)
         if self.seeds:
             results = self.seeds.list(**kwargs)
             return results
@@ -275,3 +282,9 @@ class Actions(object):
         '''
         pass
 
+
+    def listseedfiles(self, args):
+        seedsdir = self.config.get_key('seedsdir')
+        files = os.listdir(seedsdir)
+        return {"Seed files found at path: %s\n   %s"
+            % (seedsdir, "\n   ".join(files)): True}


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [gentoo-commits] proj/gentoo-keys:master commit in: etc/, gkeys/
@ 2014-05-15 17:20 Brian Dolbec
  0 siblings, 0 replies; 5+ messages in thread
From: Brian Dolbec @ 2014-05-15 17:20 UTC (permalink / raw
  To: gentoo-commits

commit:     47c4373d6071879eb61bb78c1436f6b5f1f52fe5
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Thu May 15 17:19:08 2014 +0000
Commit:     Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Thu May 15 17:19:08 2014 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-keys.git;a=commit;h=47c4373d

config: clean up unused defaults, add seedurls

---
 etc/gkeys.conf  |  7 +++++++
 gkeys/config.py | 16 +++++++---------
 2 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/etc/gkeys.conf b/etc/gkeys.conf
index 2497c30..d6bfd79 100644
--- a/etc/gkeys.conf
+++ b/etc/gkeys.conf
@@ -48,3 +48,10 @@ dev-seedfile: %(seedsdir)s/developer.seeds
 
 # logfile directory
 logdir: %(keysdir)s/logs
+
+[seedurls]
+# Use the filenames as the keys.
+# The will be paired to the seed file of the same name for fetching, updating
+
+release.seeds: https://dev.gentoo.org/~dolsen/gkey-seeds/release.seeds
+developers.seeds: https://dev.gentoo.org/~dolsen/gkey-seeds/developer.seeds

diff --git a/gkeys/config.py b/gkeys/config.py
index 1883703..4e309b0 100644
--- a/gkeys/config.py
+++ b/gkeys/config.py
@@ -66,18 +66,16 @@ class GKeysConfig(GPGConfig):
         self.defaults['release-keydir'] = '%(keysdir)s/release'
         self.defaults['overlays-keydir'] = '%(keysdir)s/overlays'
         self.defaults['logdir'] = '%(keysdir)s/logs'
-        # known-keysfile is a repositories.xml like file of gpg seeds
-        # distributed through api.g.o for convenience
-        self.defaults['known-keysfile'] = '%(keysdir)s/knownkeys'
-        self.defaults['seedsdir'] = '%(keysdir)s/seeds'
-        self.defaults['release-seedfile'] = '%(configdir)s/release.seeds'
-        self.defaults['dev-seedfile'] = '%(configdir)s/developer.seeds'
         # local directory to scan for seed files installed via ebuild, layman
         # or manual install.
-        self.defaults['installable-seeddir'] = '%(configdir)s/installable.seeds'
+        self.defaults['seedsdir'] = '%(keysdir)s/seeds'
+        self.defaults['release-seedfile'] = '%(seedsdir)s/release.seeds'
+        self.defaults['dev-seedfile'] = '%(seedsdir)s/developer.seeds'
         self.defaults['keyserver'] = 'pool.sks-keyservers.net'
-        self.defaults['dev-seedurl'] = 'https://dev.gentoo.org/~dolsen/gkey-seeds/developer.seeds'
-        self.defaults['release-seedurl'] = 'https://dev.gentoo.org/~dolsen/gkey-seeds/release.seeds'
+        self.defaults['seedurls'] = {
+            'release.seeds': https://dev.gentoo.org/~dolsen/gkey-seeds/release.seeds,
+            'developers.seeds': https://dev.gentoo.org/~dolsen/gkey-seeds/developer.seeds,
+        }
 
 
     def read_config(self):


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [gentoo-commits] proj/gentoo-keys:master commit in: etc/, gkeys/
@ 2014-08-20  3:55 Brian Dolbec
  0 siblings, 0 replies; 5+ messages in thread
From: Brian Dolbec @ 2014-08-20  3:55 UTC (permalink / raw
  To: gentoo-commits

commit:     c1f231291afa94d9a0020569d8d7da2a7674b7fd
Author:     Pavlos Ratis <dastergon <AT> gentoo <DOT> org>
AuthorDate: Mon Jul 28 18:17:18 2014 +0000
Commit:     Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Mon Jul 28 18:17:18 2014 +0000
URL:        http://sources.gentoo.org/gitweb/?p=proj/gentoo-keys.git;a=commit;h=c1f23129

binary keyring support

Import specified trusted keys to a specified keyring file.

---
 etc/gkeys.conf.sample |  3 +++
 gkeys/actions.py      | 55 +++++++++++++++++++++++++++++++++++++++++----------
 gkeys/cli.py          |  2 ++
 gkeys/config.py       |  1 +
 gkeys/lib.py          | 31 ++++++++++++++++++++++++++++-
 5 files changed, 81 insertions(+), 11 deletions(-)

diff --git a/etc/gkeys.conf.sample b/etc/gkeys.conf.sample
index 9f2d8da..a777ab1 100644
--- a/etc/gkeys.conf.sample
+++ b/etc/gkeys.conf.sample
@@ -20,6 +20,9 @@ dev-keydir: %(keysdir)s/devs
 # will be stored.
 rel-keydir: %(keysdir)s/release
 
+# keyring: the directory where the official keyring  with the specified keys
+# will be exported.
+keyring: %(keysdir)s/keyring
 
 # overlayskeydir: the directory where the overlay keys
 # will be stored.

diff --git a/gkeys/actions.py b/gkeys/actions.py
index caa0d7f..5d65552 100644
--- a/gkeys/actions.py
+++ b/gkeys/actions.py
@@ -22,8 +22,8 @@ from gkeys.seedhandler import SeedHandler
 from gkeys.config import GKEY
 
 Available_Actions = ['listseed', 'addseed', 'removeseed', 'moveseed', 'fetchseed',
-            'listseedfiles', 'listkey', 'addkey', 'removekey', 'movekey',
-            'installed']
+            'listseedfiles', 'listkey', 'installkey', 'removekey', 'movekey',
+            'installed', 'importkey']
 
 
 class Actions(object):
@@ -69,7 +69,7 @@ class Actions(object):
             return ["Provide a nickname, a name and a fingerprint."]
         gkey = handler.new(args, checkgkey=True)
         if len(gkeys) == 0:
-            self.logger.debug("ACTIONS: addkey; now adding gkey: %s" % str(gkey))
+            self.logger.debug("ACTIONS: installkey; now adding gkey: %s" % str(gkey))
             success = self.seeds.add(getattr(gkey, 'nick'), gkey)
             if success:
                 success = self.seeds.save()
@@ -186,13 +186,13 @@ class Actions(object):
         return messages
 
 
-    def addkey(self, args):
+    def installkey(self, args):
         '''Install a key from the seed(s)'''
         if not args.nick:
             return ["Please provide a nickname or -n *"]
         handler = SeedHandler(self.logger, self.config)
         kwargs = handler.build_gkeydict(args)
-        self.logger.debug("ACTIONS: addkey; kwargs: %s" % str(kwargs))
+        self.logger.debug("ACTIONS: installkey; kwargs: %s" % str(kwargs))
         gkey = self.listseed(args)[1]
         if gkey:
             if gkey and not args.nick == '*' and self.output:
@@ -200,7 +200,7 @@ class Actions(object):
             elif gkey and self.output:
                 self.output(['all'], "\n Installing seeds:")
             else:
-                self.logger.info("ACTIONS: addkey; "
+                self.logger.info("ACTIONS: installkey; "
                     "Matching seed entry not found")
                 if args.nick:
                     return ["Search failed for: %s" % args.nick]
@@ -211,16 +211,16 @@ class Actions(object):
             # get confirmation
             # fill in code here
             keydir = self.config.get_key(args.seeds + "-keydir")
-            self.logger.debug("ACTIONS: addkey; keysdir = %s" % keydir)
+            self.logger.debug("ACTIONS: installkey; keysdir = %s" % keydir)
             self.gpg = GkeysGPG(self.config, keydir)
             results = {}
             failed = []
             for key in gkey:
-                self.logger.debug("ACTIONS: addkey; adding key:")
+                self.logger.debug("ACTIONS: installkey; adding key:")
                 self.logger.debug("ACTIONS: " + str(key))
                 results[key.name] = self.gpg.add_key(key)
                 for result in results[key.name]:
-                    self.logger.debug("ACTIONS: addkey; result.failed = " +
+                    self.logger.debug("ACTIONS: installkey; result.failed = " +
                                       str(result.failed))
                 if self.config.options['print_results']:
                     for result in results[key.name]:
@@ -231,7 +231,7 @@ class Actions(object):
                         if result.failed:
                             failed.append(key)
             if failed and self.output:
-                self.output(failed, "\n Failed to install:")
+                self.output([failed], "\n Failed to install:")
             return ["Completed"]
         return ["No seeds to search or install"]
 
@@ -274,6 +274,41 @@ class Actions(object):
         pass
 
 
+    def importkey(self, args):
+        '''Add a specified key to a specified keyring'''
+        if args.seeds:
+            keydir = self.config.get_key(args.seeds + "-keydir")
+            keyring_dir = self.config.get_key("keyring")
+            self.logger.debug("ACTIONS: importkey; keydir = %s" % keydir)
+            self.gpg = GkeysGPG(self.config, keydir)
+            handler = SeedHandler(self.logger, self.config)
+            gkeys = self.listseed(args)[1]
+            results = {}
+            failed = []
+            print("Importing specified keys to keyring.")
+            for gkey in gkeys:
+                self.logger.debug("ACTIONS: importkey; adding key: %s", gkey.name)
+                results[gkey.name] = self.gpg.add_key(gkey)
+                if self.config.options['print_results']:
+                    for result in results[gkey.name]:
+                        print("key desired:", gkey.name, ", key added:",
+                            result.username, ", succeeded:",
+                            not result.failed, ", fingerprint:", result.fingerprint)
+                        self.logger.debug("stderr_out: " + str(result.stderr_out))
+                        if result.failed:
+                            self.logger.debug("ACTIONS: importkey; result.failed = " + str(result.failed))
+                            failed.append(gkey)
+                if not results[gkey.name][0].failed:
+                    print("Importing: ", gkey.name)
+                    self.logger.debug("ACTIONS: importkey; importing key: %s", gkey.name)
+                    keyring = os.path.join(keyring_dir,args.keyring + '.gpg')
+                    self.gpg.add_to_keyring(gkey, keydir, keyring)
+            if failed and self.output:
+                self.output([failed], "\n Failed to install:")
+            return ["Completed."]
+        return ["No seeds to search or install"]
+
+
     def installed(self, args):
         '''Lists the installed key directories'''
         if args.seeds:

diff --git a/gkeys/cli.py b/gkeys/cli.py
index 3df3435..c8d5be7 100644
--- a/gkeys/cli.py
+++ b/gkeys/cli.py
@@ -70,6 +70,8 @@ class Main(object):
             help='The logging level to set for the logfile')
         parser.add_argument('-f', '--fingerprint', dest='fingerprint', default=None,
             help='The fingerprint of the the key')
+        parser.add_argument('-k', '--keyring', dest='keyring', default='trusted_keyring',
+            help='The name of the keyring to use')
         parser.add_argument('-n', '--nick', dest='nick', default=None,
             help='The nick associated with the the key')
         parser.add_argument('-N', '--name', dest='name', nargs='*',

diff --git a/gkeys/config.py b/gkeys/config.py
index b75d562..6b9888e 100644
--- a/gkeys/config.py
+++ b/gkeys/config.py
@@ -73,6 +73,7 @@ class GKeysConfig(GPGConfig):
         self.defaults['keysdir'] = path([self.root, EPREFIX, '/var/gentoo/gkeys'])
         self.defaults['dev-keydir'] = '%(keysdir)s/devs'
         self.defaults['rel-keydir'] = '%(keysdir)s/release'
+        self.defaults['keyring'] = '%(keysdir)s/keyring'
         self.defaults['overlays-keydir'] = '%(keysdir)s/overlays'
         self.defaults['logdir'] = '%(keysdir)s/logs'
         # local directory to scan for seed files installed via ebuild, layman

diff --git a/gkeys/lib.py b/gkeys/lib.py
index 3861012..4d150bb 100644
--- a/gkeys/lib.py
+++ b/gkeys/lib.py
@@ -20,6 +20,7 @@ with gentoo-keys specific convienience functions.
 from __future__ import print_function
 
 
+from os.path import abspath, pardir
 from os.path import join as pjoin
 
 from pyGPG.gpg import GPG
@@ -60,7 +61,7 @@ class GkeysGPG(GPG):
         return
 
 
-    def set_keyring(self, keyring, task, reset=True):
+    def set_keyring(self, keyring, task, importkey=False, reset=True):
         '''Sets the keyring to use as well as related task options
         '''
         logger.debug("keydir: %s, keyring: %s" % (self.keydir, keyring))
@@ -69,6 +70,11 @@ class GkeysGPG(GPG):
         # --keyring file |  Note that this adds a keyring to the current list.
         # If the intent is to use the specified keyring alone,
         # use  --keyring  along with --no-default-keyring.
+        if importkey:
+            task_value = ['--import-options', 'import-clean']
+            self.config.options['tasks'][task].extend(task_value)
+            parent_dir = abspath(pjoin(keyring, pardir))
+            ensure_dirs(parent_dir)
         task_value = ['--no-default-keyring', '--keyring', keyring]
         self.config.options['tasks'][task].extend(task_value)
         logger.debug("set_keyring: New task options: %s" %str(self.config.options['tasks'][task]))
@@ -87,6 +93,29 @@ class GkeysGPG(GPG):
         return
 
 
+    def add_to_keyring(self, gkey, keydir, keyring):
+        '''Add the specified key to the specified keyring
+
+        @param gkey: GKEY namedtuple with
+            (name, keyid/longkeyid, keydir, fingerprint)
+        @param keydir: path with the specified keydir
+        @param keyring: string with the specified keyring
+        '''
+        self.set_keydir(keydir, 'import', reset=True)
+        self.set_keyring(keyring, 'import', importkey=True, reset=False)
+        results = []
+        logger.debug("LIB: import_to_keyring; name: " + gkey.name)
+        logger.debug("** Calling runGPG with Running: gpg %s --import' for: %s"
+                     % (' '.join(self.config.get_key('tasks', 'import')),
+                        gkey.name))
+        pubring_path = pjoin(self.keydir, gkey.keydir, 'pubring.gpg')
+        result = self.runGPG(task='import', inputfile=pubring_path)
+        logger.info('GPG return code: ' + str(result.returncode))
+        results.append(result)
+        print(result.stderr_out)
+        return results
+
+
     def add_key(self, gkey):
         '''Add the specified key to the specified keydir
 


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-08-20  3:55 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-20  3:55 [gentoo-commits] proj/gentoo-keys:master commit in: etc/, gkeys/ Brian Dolbec
  -- strict thread matches above, loose matches on Subject: below --
2014-05-15 17:20 Brian Dolbec
2014-03-01  0:54 Brian Dolbec
2013-11-10  1:01 Brian Dolbec
2012-12-10  3:26 Brian Dolbec

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox