]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
toaster: Support environments which have proxies set
authorBian Naimeng <biannm@cn.fujitsu.com>
Fri, 28 Aug 2015 15:37:38 +0000 (16:37 +0100)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Sat, 29 Aug 2015 12:59:43 +0000 (13:59 +0100)
In an environment with a proxy which requires authentication, e.g. with
$http_proxy = 'http://user:password@ip:port', the following error
occurs when running Toaster:

  EE: Using proxy http://user:password@ip:port
  EE: could not connect to 'url', skipping update: 'error message'

This prevents Toaster from fetching layer, recipe and machine information
from remote repositories.

This patch allows Toaster to use the proxy settings from the
environment for HTTP/HTTPS requests.

Signed-off-by: Bian Naimeng <biannm@cn.fujitsu.com>
Signed-off-by: Elliot Smith <elliot.smith@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
lib/toaster/orm/models.py

index 92fcaa7adffcc019dad1a720c36b3fc1c5549c72..58f76a8342dfcf747c443f061c9bbd17bf468ee9 100644 (file)
@@ -817,42 +817,20 @@ class LayerIndexLayerSource(LayerSource):
         assert self.apiurl is not None
         from django.db import transaction, connection
 
-        import httplib, urlparse, json
+        import urllib2, urlparse, json
         import os
         proxy_settings = os.environ.get("http_proxy", None)
 
         def _get_json_response(apiurl = self.apiurl):
-            conn = None
             _parsedurl = urlparse.urlparse(apiurl)
             path = _parsedurl.path
-            query = _parsedurl.query
-            def parse_url(url):
-                parsedurl = urlparse.urlparse(url)
-                try:
-                    (host, port) = parsedurl.netloc.split(":")
-                except ValueError:
-                    host = parsedurl.netloc
-                    port = None
-
-                if port is None:
-                    port = 80
-                else:
-                    port = int(port)
-                return (host, port)
 
-            if proxy_settings is None:
-                host, port = parse_url(apiurl)
-                conn = httplib.HTTPConnection(host, port)
-                conn.request("GET", path + "?" + query)
-            else:
-                host, port = parse_url(proxy_settings)
-                conn = httplib.HTTPConnection(host, port)
-                conn.request("GET", apiurl)
-
-            r = conn.getresponse()
-            if r.status != 200:
-                raise Exception("Failed to read " + path + ": %d %s" % (r.status, r.reason))
-            return json.loads(r.read())
+            try:
+                res = urllib2.urlopen(apiurl)
+            except urllib2.URLError as e:
+                raise Exception("Failed to read %s: %s" % (path, e.reason))
+
+            return json.loads(res.read())
 
         # verify we can get the basic api
         try: