[Toaster] [RFC PATCH v2] toaster: support authentication required proxy connection

Smith, Elliot elliot.smith at intel.com
Fri Aug 28 08:27:36 PDT 2015


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

On 28 August 2015 at 03:18, Bian Naimeng <biannm at cn.fujitsu.com> wrote:

> 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
>
> Signed-off-by: Bian Naimeng <biannm at cn.fujitsu.com>
> ---
>  lib/toaster/orm/models.py | 36 +++++++-----------------------------
>  1 file changed, 7 insertions(+), 29 deletions(-)
>
> diff --git a/lib/toaster/orm/models.py b/lib/toaster/orm/models.py
> index 92fcaa7..ffd435b 100644
> --- a/lib/toaster/orm/models.py
> +++ b/lib/toaster/orm/models.py
> @@ -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
> toaster at yoctoproject.org
> https://lists.yoctoproject.org/listinfo/toaster
>



-- 
Elliot Smith
Software Engineer
Intel Open Source Technology Centre
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.yoctoproject.org/pipermail/toaster/attachments/20150828/0cc0f220/attachment-0001.html>


More information about the toaster mailing list