summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Coldrick <adam.coldrick@codethink.co.uk>2014-03-04 09:19:56 +0000
committerAdam Coldrick <adam.coldrick@codethink.co.uk>2014-03-05 16:42:45 +0000
commitb57f8141536508e83c9b88029948b9cd2e12e790 (patch)
treece98dc64eec384ebc63d4ad38171b5032e397198
parent9dc4d6c7b6dcbfaf613fbdf853b0d2777b9c825c (diff)
downloadlorry-controller-b57f8141536508e83c9b88029948b9cd2e12e790.tar.gz
Update confparser to allow for requests using protocols other than ssh.
Add a method that constructs either an ssh command or an http GET request based on the access protocol of the trove. Make sure that when constructing lorries the url is in the correct form for a given protocol.
-rw-r--r--lorrycontroller/confparser.py47
1 files changed, 41 insertions, 6 deletions
diff --git a/lorrycontroller/confparser.py b/lorrycontroller/confparser.py
index 0ef7944..6099ccd 100644
--- a/lorrycontroller/confparser.py
+++ b/lorrycontroller/confparser.py
@@ -21,6 +21,7 @@ import glob
import os
import time
import fnmatch
+import urllib
default_values = [
( u'create', u'never' ),
@@ -187,6 +188,14 @@ class LorryControllerConfig(object):
if type(entry.get('ignore', [])) != list:
self._give_up("Ignore is not a list for %s" %
entry['trovehost'])
+ if type(entry.get('protocol', None)) != unicode:
+ self._give_up("Trove access protocol %r is not a string" %
+ entry.get('protocol', None))
+ else:
+ if not(entry['protocol'] in ('ssh', 'http')):
+ if not(entry.get('auth', None)):
+ self._give_up("Trove access protocol requires "
+ "authorisation details but none were defined.")
# Validate prefixmap
for local, remote in entry['prefixmap'].iteritems():
if type(local) != unicode:
@@ -207,12 +216,13 @@ class LorryControllerConfig(object):
trove['uuid']))
# 1. Ensure that if we need to 'ls' the trove, we do it
now = time.time()
- listcmdargs = ["ssh", "-oStrictHostKeyChecking=no",
- "-oBatchMode=yes", "git@" + trove['trovehost'], "ls",
- "--verbose"]
+ listcmdargs = self.cmdlist(trove, 'ls', '--verbose')
state['next-vls'] = state.get('next-vls', now - 1)
if state['next-vls'] < now:
- exit, out, err = self.app.maybe_runcmd(listcmdargs, dry=True)
+ if trove['protocol'] == 'ssh':
+ exit, out, err = self.app.maybe_runcmd(listcmdargs, dry=True)
+ else:
+ exit, out, err = self.app.maybe_http_request(listcmdargs, dry=True)
if exit == 0:
repo_info = {}
for entry in [x for x in out.split("\n") if x != ""]:
@@ -251,11 +261,17 @@ class LorryControllerConfig(object):
localreponame = "%s/%s" % (local,
remotereponame[len(remote)+1:])
if ((not ignored(remotereponame)) and (localreponame is not None)):
+ # Make the url in the correct form for the given protocol
+ if trove['protocol'] == 'ssh':
+ url = 'ssh://git@%s/%s.git' % (trove['trovehost'],
+ remotereponame)
+ else:
+ url = 'http://%s/git/%s.git' % (trove['trovehost'],
+ remotereponame)
# Construct a lorry for this one.
lorry = {
"type": "git",
- "url": "ssh://git@%s/%s.git" % (trove['trovehost'],
- remotereponame),
+ "url": url,
"controller-uuid": trove['uuid'],
"source-HEAD": info["head"],
"refspecs": [ "+refs/heads/*:refs/heads/*",
@@ -289,6 +305,25 @@ class LorryControllerConfig(object):
trove_state = statemgr.get_trove(trove['uuid'])
self.update_trove(trove, trove_state)
+ def cmdlist(self, trove, command, *args):
+ """Return an ssh command or a url depending on the trove protocol."""
+ cmdargs = []
+ if trove['protocol'] == 'ssh':
+ # construct list to run command over ssh
+ cmdargs = ['ssh',
+ '-oStrictHostKeyChecking=no',
+ '-oBatchMode=yes',
+ 'git@%s' % trove['trovehost'],
+ command]
+ cmdargs.extend(args)
+ else:
+ # construct a url which will return the command output
+ cmd = command + ' ' + ' '.join(args)
+ cmd = urllib.quote(cmd)
+ cmdargs = 'http://%s/gitano-command.cgi?cmd=%s' %\
+ (trove['trovehost'], cmd)
+ return cmdargs
+
def _give_up(self, *args, **kwargs):
logging.error(*args, **kwargs)
raise SystemExit(5)