toaster: support authentication required proxy connection
RFC PATCH v2 1/1 toaster: support authentication required proxy connection
At authentication required proxy environment, such as setting $http_proxy to 'http://user:password@ip:port', the following error will be caught.
EE: Using proxy http://user:password@ip:port
EE: could not connect to 'url', skipping update: 'error message'
It means toaster can not fetche layer, recipe and machine information from remote repository at authentication required proxy environment.
What this patch tries to fix is that make toaster support authentication required proxy connection.
I have did some tests after applying this patch.
1. Proxy with authentication
# export http_proxy="http://user:password@ip:port" # bitbake/bin/toaster
Result: OK
2. Proxy without authentication
# export http_proxy="http://ip:port" # bitbake/bin/toaster
Result: OK
3. Directly
# bitbake/bin/toaster
Result: Unknow, Not yet tested
--- lib/toaster/orm/models.py | 36 +++++++----------------------------- 1 file changed, 7 insertions(+), 29 deletions(-)
lib/toaster/orm/models.py +7 -29
@@ -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,e: + raise Exception("Failed to read " + path + ": %d %s" % (e.code, e.reason)) + + return json.loads(res.read()) # verify we can get the basic api try:
Signature · 1 line
1.9.1
This looks OK to me, and I've tested it on my setup with an authenticated proxy, unauthenticated proxy and without a proxy, and it works fine.
I will submit it.
Elliot
Quoted 103 lines · Bian Naimeng
At authentication required proxy environment, such as setting $http_proxy to
'http://user:password@ip:port', the following error will be caught.EE: Using proxy http://user:password@ip:port
EE: could not connect to 'url', skipping update: 'error message'It means toaster can not fetche layer, recipe and machine information from remote repository
at authentication required proxy environment.What this patch tries to fix is that make toaster support authentication required proxy connection.
I have did some tests after applying this patch.
1. Proxy with authentication
# export http_proxy="http://user:password@ip:port" # bitbake/bin/toasterResult: OK
2. Proxy without authentication
# export http_proxy="http://ip:port" # bitbake/bin/toasterResult: OK
3. Directly
# bitbake/bin/toasterResult: Unknow, Not yet tested
Signed-off-by Bian Naimeng <[email protected]>--- lib/toaster/orm/models.py | 36 +++++++----------------------------- 1 file changed, 7 insertions(+), 29 deletions(-)lib/toaster/orm/models.py +7
-29@@ -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,e: + raise Exception("Failed to read " + path + ": %d %s" % (e.code, e.reason)) + + return json.loads(res.read())# verify we can get the basic api try: -- 1.9.1--
_______________________________________________
toaster mailing list
[email protected]
https://lists.yoctoproject.org/listinfo/toaster
Signature · 3 lines
Elliot Smith Software Engineer Intel Open Source Technology Centre