Add keyserver config option
authorBrian Dolbec <dolsen@gentoo.org>
Sat, 27 Jul 2013 12:43:34 +0000 (05:43 -0700)
committerBrian Dolbec <dolsen@gentoo.org>
Sat, 27 Jul 2013 12:43:34 +0000 (05:43 -0700)
etc/gkeys.conf
gkeys/config.py
gkeys/lib.py

index 5b9159712ea2b9c927be1383a1b1ffee2303816a..46d45aaa995fe0e6b0f2dad259d266ded37116eb 100644 (file)
@@ -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
 
index 96b4aeecaef834fd20743c63d796138458edbb62..fe78dec2c34a57f2244442ddfa5c9b92679d5aca 100644 (file)
@@ -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'
 
 
 
index a97b7e7e4378815820f13d449b5ac2f24ab560c4..66e27dc7d50960b8c8c9f33baa1015a6c4185905 100644 (file)
@@ -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