summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Coldrick <adam.coldrick@codethink.co.uk>2014-03-20 15:09:34 +0000
committerAdam Coldrick <adam.coldrick@codethink.co.uk>2014-03-20 15:09:34 +0000
commit627c50633977804e6a10bafad81e72ae376b1cf6 (patch)
treed4083ecac44151bf5d160c11aa0805e74d5cd391
parent0a0b829261ec572fa8c254fa625b38b7d504a60d (diff)
parent65c32e67eb8fcd57377fc14f4503faa700a14cb2 (diff)
downloadlorry-controller-627c50633977804e6a10bafad81e72ae376b1cf6.tar.gz
Merge branch 'adamcoldrick/https-fix-rebase'
Author: Adam Coldrick <adam.coldrick@codethink.co.uk> Reviewed by: * Daniel Silverstone <daniel.silverstone@codethink.co.uk> * Richard Maw <richard.maw@codethink.co.uk>
-rwxr-xr-xlorry-controller16
-rw-r--r--lorrycontroller/confparser.py12
2 files changed, 16 insertions, 12 deletions
diff --git a/lorry-controller b/lorry-controller
index d9dc1e0..0ae4ceb 100755
--- a/lorry-controller
+++ b/lorry-controller
@@ -285,10 +285,10 @@ class LorryController(cliapp.Application):
self.runcmd(['git']+args, cwd=os.path.join(self.settings['work-area'],
'git'))
- def maybe_http_request(self, url, dry=False):
+ def maybe_http_request(self, url, auth=None, dry=False):
"""If not a dry run, make an HTTP request and return its output."""
if (not self.settings['dry-run']) or dry:
- return self.http_request(url)
+ return self.http_request(url, auth)
else:
logging.debug('DRY-RUN: Not sending a request to %s' % url)
return 0, 'DRY-RUN', 'DRY-RUN'
@@ -300,7 +300,7 @@ class LorryController(cliapp.Application):
logging.debug("DRY-RUN: Not running %r" % cmdline)
return 0, 'DRY-RUN', 'DRY-RUN'
- def http_request(self, url):
+ def http_request(self, url, auth=None):
"""Make an HTTP request to the given url, return the output.
Make an HTTP request to `url`. If the request succeeds (response code
@@ -310,7 +310,15 @@ class LorryController(cliapp.Application):
"""
request = urllib2.Request(url, None, {})
- response = urllib2.urlopen(request)
+ if auth:
+ password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
+ password_mgr.add_password(
+ None, url, auth['username'], auth['password'])
+ auth_handler = urllib2.HTTPBasicAuthHandler(password_mgr)
+ opener = urllib2.build_opener(auth_handler)
+ response = opener.open(url)
+ else:
+ response = urllib2.urlopen(request)
code = response.getcode()
if code == 200:
return 0, response.read(), '200'
diff --git a/lorrycontroller/confparser.py b/lorrycontroller/confparser.py
index e8b78d8..403b768 100644
--- a/lorrycontroller/confparser.py
+++ b/lorrycontroller/confparser.py
@@ -323,15 +323,11 @@ class LorryControllerConfig(object):
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
+ url = '%s://%s/gitano-command.cgi?cmd=%s' % (
+ trove['protocol'], trovehost, query_string)
+ auth = trove.get('auth', None)
# make an http request to the url
- exit, out, err = self.app.maybe_http_request(url, dry=dry)
+ exit, out, err = self.app.maybe_http_request(url, auth=auth, dry=dry)
return exit, out, err
def _give_up(self, *args, **kwargs):