[oe-commits] [bitbake] 02/02: fetch2/wget: add Basic Auth from netrc to checkstatus()
git at git.openembedded.org
git at git.openembedded.org
Fri Dec 16 10:31:50 UTC 2016
rpurdie pushed a commit to branch master-next
in repository bitbake.
commit 873e33d0479e977520106b65d149ff1799195bf6
Author: Matthew McClintock <msm-oss at mcclintock.net>
AuthorDate: Fri Dec 16 03:32:42 2016 -0600
fetch2/wget: add Basic Auth from netrc to checkstatus()
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.
Signed-off-by: Matthew McClintock <msm-oss at mcclintock.net>
Signed-off-by: Richard Purdie <richard.purdie at linuxfoundation.org>
---
lib/bb/fetch2/wget.py | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/lib/bb/fetch2/wget.py b/lib/bb/fetch2/wget.py
index 6dfb27b..88349c9 100644
--- a/lib/bb/fetch2/wget.py
+++ b/lib/bb/fetch2/wget.py
@@ -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:
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Openembedded-commits
mailing list