diff options
-rw-r--r-- | lorrycontroller/confparser.py | 58 |
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) |