summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xlorry-controller28
1 files changed, 28 insertions, 0 deletions
diff --git a/lorry-controller b/lorry-controller
index a3efa2c..88e6436 100755
--- a/lorry-controller
+++ b/lorry-controller
@@ -17,6 +17,7 @@
import cliapp
+import json
import logging
import os
import time
@@ -101,6 +102,13 @@ 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')
+ # make git always ignore ssl certificates
+ self.maybe_runcmd(
+ ['git', 'config', '--global', 'http.sslVerify', 'false'],
+ dry=True)
self.conf = LorryControllerConfig(self, 'git/lorry-controller.conf')
self.html = HTMLStatusManager(self)
if self.settings['dry-run']:
@@ -295,5 +303,25 @@ class LorryController(cliapp.Application):
logging.debug("DRY-RUN: Not running %r" % cmdline)
return 0, 'DRY-RUN', 'DRY-RUN'
+ 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
+ user = '%s:%s' % (proxy['username'], proxy['password'])
+ url = '%s:%s' % (proxy['hostname'], proxy['port'])
+ os.environ['http_proxy'] = 'http://%s@%s' % (user, url)
+ os.environ['https_proxy'] = 'http://%s@%s' % (user, url)
+
+ # install an opener to use the proxy
+ opener = urllib2.build_opener()
+ urllib2.install_opener(opener)
+
if __name__ == '__main__':
LorryController(version='1').run()