aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--master/master/slave_api.py20
-rw-r--r--slave/autotua/config.py41
-rw-r--r--slave/autotua/crypt/__init__.py10
3 files changed, 44 insertions, 27 deletions
diff --git a/master/master/slave_api.py b/master/master/slave_api.py
index e08f4d7..c1d750d 100644
--- a/master/master/slave_api.py
+++ b/master/master/slave_api.py
@@ -1,5 +1,5 @@
# vim: set sw=4 sts=4 et :
-# Copyright: 2008 Gentoo Foundation
+# Copyright: 2008-2009 Gentoo Foundation
# Author(s): Nirbheek Chauhan <nirbheek.chauhan@gmail.com>
# License: AGPL-3
#
@@ -16,7 +16,9 @@ from django.http import HttpResponse, Http404
from django.shortcuts import *
from master.models import Job, User, Slave
-import process, const
+from . import process, const
+
+CRYPTO = crypt.Crypto(gpghome=const.GPGHOME)
def _pickled_http_response(response, crypto=None, recipient=None):
response = pickle.dumps(response, 0)
@@ -45,13 +47,15 @@ def job_list(request, **kwargs):
jobs.append(job_data(job))
if kwargs.has_key('job_name') and len(jobs) == 1:
jobs = jobs[0]
+ # TODO: If logged in, send encrypted job list
+ # Also, find a way to let the slave explicitely request unencrypted
+ # communication
return _pickled_http_response(jobs)
def accept_job(request):
if request.method == 'GET' or not request.POST.has_key('data'):
raise Http404
- crypto = crypt.Crypto(gpghome=const.GPGHOME)
- (data, sender) = crypto.decrypt(request.POST['data'])
+ (data, sender) = CRYPTO.decrypt(request.POST['data'])
data = pickle.loads(data)
data['maintainer'] = get_object_or_404(User, username=data['maintainer'])
job = get_object_or_404(Job, **data)
@@ -65,7 +69,11 @@ def accept_job(request):
def get_pubkey(request):
pubkey_file = '%s/autotua_master.asc' % const.GPGHOME
- if not os.path.exists(pubkey_file):
+ try:
+ pubkey = open(pubkey_file)
+ except IOError, OSError:
crypto = crypt.Crypto(gpghome=const.GPGHOME)
crypto.export_pubkey(pubkey_file, 'AutotuA Master')
- return HttpResponse(open(pubkey_file).read())
+ pubkey = open(pubkey_file)
+ finally:
+ return HttpResponse(pubkey.read())
diff --git a/slave/autotua/config.py b/slave/autotua/config.py
index 7ab4267..704a310 100644
--- a/slave/autotua/config.py
+++ b/slave/autotua/config.py
@@ -1,5 +1,5 @@
# vim: set sw=4 sts=4 et :
-# Copyright: 2008 Gentoo Foundation
+# Copyright: 2008-2009 Gentoo Foundation
# Author(s): Nirbheek Chauhan <nirbheek.chauhan@gmail.com>
# License: GPL-3
#
@@ -7,10 +7,12 @@
#
"""
-Default configuration, overriden by /etc/autotua/slave.cfg
+Default configuration, overriden by const.CONFIG_PATH
"""
-import os, ConfigParser, const
+from __future__ import with_statement
+import os, ConfigParser
+from . import const
VERBOSE = False
FULL_CLEAN = False
@@ -29,21 +31,24 @@ PORTAGE_DIR = '/usr/portage'
DISTFILES_DIR = '/usr/portage/distfiles'
# Read settings from slave.cfg which override the above
-if os.path.exists('%s/slave.cfg' % const.CONFIG_PATH):
- options = locals().copy()
- cfg = ConfigParser.ConfigParser()
- cfg.readfp(open('%s/slave.cfg' % const.CONFIG_PATH))
- for option, value in options.iteritems():
- if not isinstance(value, (str, int, bool)):
- continue
- if cfg.has_option('global', option.lower()):
- if isinstance(value, str):
- if not option.startswith('__'):
- exec('%s = %s' % (option, cfg.get('global', option.lower())))
- elif isinstance(value, bool):
- exec('%s = %s' % (option, cfg.getboolean('global', option.lower())))
- elif isinstance(value, int):
- exec('%s = %s' % (option, cfg.getint('global', option.lower())))
+try:
+ with open('%s/slave.cfg' % const.CONFIG_PATH) as slave_cfg:
+ options = locals().copy()
+ cfg = ConfigParser.ConfigParser()
+ cfg.readfp(slave_cfg)
+ for option, value in options.iteritems():
+ if not isinstance(value, (str, int, bool)):
+ continue
+ if cfg.has_option('global', option.lower()):
+ if isinstance(value, str):
+ if not option.startswith('__'):
+ exec('%s = %s' % (option, cfg.get('global', option.lower())))
+ elif isinstance(value, bool):
+ exec('%s = %s' % (option, cfg.getboolean('global', option.lower())))
+ elif isinstance(value, int):
+ exec('%s = %s' % (option, cfg.getint('global', option.lower())))
+except IOError, OSError:
+ print "!!! Unable to read %s/slave.cfg, ignoring..." % const.CONFIG_PATH
if not AUTOTUA_MASTER:
print "!!! WARNING: You did not edit the autotua_master variable in slave.cfg (or AUTOTUA_MASTER in config.py)"
diff --git a/slave/autotua/crypt/__init__.py b/slave/autotua/crypt/__init__.py
index 29e37f3..0ee5073 100644
--- a/slave/autotua/crypt/__init__.py
+++ b/slave/autotua/crypt/__init__.py
@@ -1,5 +1,5 @@
# vim: set sw=4 sts=4 et :
-# Copyright: 2008 Gentoo Foundation
+# Copyright: 2008-2009 Gentoo Foundation
# Author(s): Nirbheek Chauhan <nirbheek.chauhan@gmail.com>
# License: GPL-3
#
@@ -22,8 +22,12 @@ class Crypto(object):
self.gpgcmd += '--homedir="%s" ' % self.gpghome
def _validate_gpghome(self):
- if not os.path.exists(self.gpghome+'/secring.gpg'):
- raise Exception('"%s": Invalid GPG homedir' % self.gpghome)
+ try:
+ gpghome = open(self.gpghome+'/secring.gpg')
+ except IOError, OSError:
+ raise Exception('"%s": Unable to use GPG homedir' % self.gpghome)
+ finally:
+ gpghome.close()
def _get_fp_from_keyid(self, keyid):
gpg_args = '--with-colons --fingerprint --list-keys "%s"' % keyid