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-04 09:19:56 +0000
commit897816406001b918f79358e762bfbef6af0a3e6a (patch)
treebad805fbc7598256b4555acc3544dd13a1923c5b
parent48db041a53092c965e474ac6ffad72e2effdd292 (diff)
downloadlorry-controller-adamcoldrick/access-troves-via-http.tar.gz
Update confparser to allow for requests using protocols other than ssh.adamcoldrick/access-troves-via-http
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.py58
1 files changed, 52 insertions, 6 deletions
diff --git a/lorrycontroller/confparser.py b/lorrycontroller/confparser.py
index 0ef7944..c1cfe14 100644
--- a/lorrycontroller/confparser.py
+++ b/lorrycontroller/confparser.py
@@ -187,6 +187,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 +215,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 +260,23 @@ 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)
+ elif trove['protocol'] == 'http':
+ url = 'http://%s/%s.git' % (trove['trovehost'],
+ remotereponame)
+ else:
+ url = '%s://%s:%s@%s/%s.git' % (trove['protocol'],
+ trove['auth']['username'],
+ trove['auth']['password'],
+ trove['hostname'],
+ 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 +310,31 @@ 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)
+ elif trove['protocol'] == 'http':
+ # construct a url which will return the command output
+ cmdargs = 'http://%s/gitano-command.cgi?cmd=%s' %
+ (trove['trovehost'], command)
+ else:
+ # construct a url which will use basic auth and return the output
+ cmdargs = '%s://%s:%s@%s/gitano-command.cgi?cmd=%s' %
+ (trove['protocol'],
+ trove['auth']['username'],
+ trove['auth']['password'],
+ trove['hostname'],
+ command)
+ return cmdargs
+
def _give_up(self, *args, **kwargs):
logging.error(*args, **kwargs)
raise SystemExit(5)