diff options
Diffstat (limited to 'lorrycontroller/confparser.py')
-rw-r--r-- | lorrycontroller/confparser.py | 57 |
1 files changed, 51 insertions, 6 deletions
diff --git a/lorrycontroller/confparser.py b/lorrycontroller/confparser.py index 0ef7944..7dae82e 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,13 @@ class LorryControllerConfig(object): if type(entry.get('ignore', [])) != list: self._give_up("Ignore is not a list for %s" % entry['trovehost']) + protocol = entry.get('protocol') + auth = entry.get('auth') + if protocol == 'https' and not auth: + self._give_up('Trove access protocol requires authorisation ' + 'details but none were defined.') + elif not protocol: + self._give_up('Trove access protocol not defined.') # Validate prefixmap for local, remote in entry['prefixmap'].iteritems(): if type(local) != unicode: @@ -207,12 +215,9 @@ 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"] state['next-vls'] = state.get('next-vls', now - 1) if state['next-vls'] < now: - exit, out, err = self.app.maybe_runcmd(listcmdargs, dry=True) + exit, out, err = self.run_gitano_command(trove, True, 'ls', '--verbose') if exit == 0: repo_info = {} for entry in [x for x in out.split("\n") if x != ""]: @@ -251,11 +256,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'] == 'https': + auth = trove['auth'] + url = 'https://%s:%s@%s/git/%s.git' % (auth['username'], + auth['password'], + 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 +306,34 @@ class LorryControllerConfig(object): trove_state = statemgr.get_trove(trove['uuid']) self.update_trove(trove, trove_state) + def run_gitano_command(self, trove, dry, command, *args): + """Run a gitano command on the trove, and return the output.""" + 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) + # run the command + exit, out, err = self.app.maybe_runcmd(cmd_args, dry=dry) + else: + # construct a url which will return the command output + query_string = '%s %s' % (command, ' '.join(args)) + query_string = urllib.quote(query_string) + trovehost = urllib.quote(trove['trovehost']) + url = '%s/gitano-command.cgi?cmd=%s' % (trovehost, query_string) + if trove['protocol'] == 'https': + url = ('https://%s:%s@%s' % (trove['auth']['username'], + trove['auth']['password'], + url)) + else: + url = 'http://%s' % url + # make an http request to the url + exit, out, err = self.app.maybe_http_request(url, dry=dry) + return exit, out, err + def _give_up(self, *args, **kwargs): logging.error(*args, **kwargs) raise SystemExit(5) |