]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
bitbake: fetch2/wget: add Basic Auth from netrc to checkstatus()
authorMatthew McClintock <msm-oss@mcclintock.net>
Fri, 16 Dec 2016 09:32:42 +0000 (03:32 -0600)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Tue, 20 Dec 2016 15:22:51 +0000 (15:22 +0000)
fetch2/wget uses urllib to check the status of the mirrors, wget will
use netrc to pass login and password information however checkstatus
will skip that.

This adds netrc login and password to checkstatus so both will work the
same.

(Bitbake rev: 873e33d0479e977520106b65d149ff1799195bf6)

Signed-off-by: Matthew McClintock <msm-oss@mcclintock.net>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
bitbake/lib/bb/fetch2/wget.py

index 6dfb27bd955de18133c0793b07dd5f32b1c1d2dc..88349c9bf929268384a6ee8862c55272b2b68405 100644 (file)
@@ -305,12 +305,24 @@ class Wget(FetchMethod):
             r = urllib.request.Request(uri)
             r.get_method = lambda: "HEAD"
 
-            if ud.user:
+            def add_basic_auth(login_str, request):
+                '''Adds Basic auth to http request, pass in login:password as string'''
                 import base64
-                encodeuser = base64.b64encode(ud.user.encode('utf-8')).decode("utf-8")
+                encodeuser = base64.b64encode(login_str.encode('utf-8')).decode("utf-8")
                 authheader =  "Basic %s" % encodeuser
                 r.add_header("Authorization", authheader)
 
+            if ud.user:
+                add_basic_auth(ud.user, r)
+
+            try:
+                import netrc, urllib.parse
+                n = netrc.netrc()
+                login, unused, password = n.authenticators(urllib.parse.urlparse(uri).hostname)
+                add_basic_auth("%s:%s" % (login, password), r)
+            except (ImportError, IOError, netrc.NetrcParseError):
+                 pass
+
             opener.open(r)
         except urllib.error.URLError as e:
             if try_again: