diff options
Diffstat (limited to 'lorry-controller')
-rwxr-xr-x | lorry-controller | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/lorry-controller b/lorry-controller index b8a59c7..d9dc1e0 100755 --- a/lorry-controller +++ b/lorry-controller @@ -17,10 +17,12 @@ import cliapp +import json import logging import os import time import re +import urllib import urllib2 @@ -101,6 +103,9 @@ class LorryController(cliapp.Application): logging.error("Unable to find lorry-controller.conf in git") raise SystemExit(4) + if os.path.isfile('git/proxy.conf'): + self.set_proxy('git/proxy.conf') + logging.info('Loaded proxy information') self.conf = LorryControllerConfig(self, 'git/lorry-controller.conf') self.html = HTMLStatusManager(self) if self.settings['dry-run']: @@ -251,6 +256,11 @@ class LorryController(cliapp.Application): logging.info("Running %d/%d. Lorrying: %s" % ( lorried, len(lorries_to_run),lorry)) self.html.set_processing(lorry) + # Before we run lorry, make sure that Git doesn't verify + # SSL certificates. This is a workaround for the fact that + # we don't yet have a solution for proper SSL certificates + # in Trove yet. + os.environ['GIT_SSL_NO_VERIFY'] = 'true' with mgr.runner(lorry) as runner: runner.run_lorry(*self.lorrycmd) while state['next-due'] <= now: @@ -307,5 +317,31 @@ class LorryController(cliapp.Application): else: return code, response.read(), str(code) + def set_proxy(self, proxy_def): + """Tell urllib2 to use a proxy for http action by lorry-controller. + + Load the proxy information from the JSON file given by proxy_def, then + set urllib2's url opener to open urls via an authenticated proxy. + + """ + with open(proxy_def, 'r') as proxy_info: + proxy = json.load(proxy_info) + + # set the required environment variables + hostname = urllib.quote(proxy['hostname']) + user = '%s:%s' % (proxy['username'], proxy['password']) + url = '%s:%s' % (hostname, proxy['port']) + os.environ['http_proxy'] = 'http://%s@%s' % (user, url) + os.environ['https_proxy'] = 'https://%s@%s' % (user, url) + + # create a ProxyHandler + proxies = {'http_proxy': 'http://%s@%s' % (user, url), + 'https_proxy': 'https://%s@%s' % (user, url)} + proxy_handler = urllib2.ProxyHandler(proxies) + + # install an opener to use the proxy + opener = urllib2.build_opener(proxy_handler) + urllib2.install_opener(opener) + if __name__ == '__main__': LorryController(version='1').run() |