All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] wget: allow basic http auth for SSTATE_MIRRORS
@ 2016-08-26 17:41 Stephano Cetola
  0 siblings, 0 replies; only message in thread
From: Stephano Cetola @ 2016-08-26 17:41 UTC (permalink / raw)
  To: bitbake-devel

If http basic auth creds were added to sstate mirrors like so:

https://foo.com/sstate/PATH;user=foo:bar;downloadfilename=PATH

The sstate mirror check would silently fail with 401 unauthorized.
This patch allows both the check, and the wget download to succeed by
checking for user credentials and if present adding the correct
headers, or wget params as needed.

[ YOCTO #9815 ]

Signed-off-by: Stephano Cetola <stephano.cetola@linux.intel.com>
---
 lib/bb/fetch2/wget.py | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/lib/bb/fetch2/wget.py b/lib/bb/fetch2/wget.py
index 6b60d9b..ecb946a 100644
--- a/lib/bb/fetch2/wget.py
+++ b/lib/bb/fetch2/wget.py
@@ -108,6 +108,10 @@ class Wget(FetchMethod):
             bb.utils.mkdirhier(os.path.dirname(dldir + os.sep + ud.localfile))
             fetchcmd += " -O " + dldir + os.sep + ud.localfile
 
+        if ud.user:
+            up = ud.user.split(":")
+            fetchcmd += " --user=%s --password=%s --auth-no-challenge" % (up[0],up[1])
+
         uri = ud.url.split(";")[0]
         if os.path.exists(ud.localpath):
             # file exists, but we didnt complete it.. trying again..
@@ -300,6 +304,13 @@ class Wget(FetchMethod):
             uri = ud.url.split(";")[0]
             r = urllib.request.Request(uri)
             r.get_method = lambda: "HEAD"
+
+            if ud.user:
+                import base64
+                encodeuser = base64.b64encode(ud.user.encode('utf-8')).decode("utf-8")
+                authheader =  "Basic %s" % encodeuser
+                r.add_header("Authorization", authheader)
+
             opener.open(r)
         except urllib.error.URLError as e:
             if try_again:
-- 
2.9.3



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2016-08-26 17:41 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-26 17:41 [PATCH] wget: allow basic http auth for SSTATE_MIRRORS Stephano Cetola

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.