[yocto] [meta-swupd] allow username/password encoded in SWUPD_VERSION_URL and SWUPD_CONTENT_URL

Ingo Flaschberger ingo.flaschberger at gmail.com
Thu Mar 23 08:04:44 PDT 2017


This patch allows basic authentication of swupd SWUPD_VERSION_URL and 
SWUPD_CONTENT_URL.
swupd-client already support urlencoded username/password, but 
buildlayer does not.


-------------- next part --------------
diff --git a/lib/swupd/bundles.py b/lib/swupd/bundles.py
index b4c6f49..223fd3c 100644
--- a/lib/swupd/bundles.py
+++ b/lib/swupd/bundles.py
@@ -4,6 +4,8 @@ import subprocess
 import shutil
 import urllib.request
 import urllib.error
+import urllib.parse
+import re
 from bb.utils import export_proxies
 from oe.package_manager import RpmPM
 from oe.package_manager import OpkgPM
@@ -164,6 +166,15 @@ def download_manifests(content_url, version, component, to_dir):
     base_versions = set()
     if not os.path.exists(target):
         bb.debug(1, 'Downloading %s -> %s' % (source, target))
+        parsed_source = urllib.parse.urlsplit(source)
+        if( parsed_source.username != None):
+            new_source = ( parsed_source.scheme, re.sub( re.escape( parsed_source.username+':'+parsed_source.password+'@'), '',parsed_source.netloc), parsed_source.path, parsed_source.query, parsed_source.fragment)
+            source = urllib.parse.urlunsplit( new_source)
+            manager = urllib.request.HTTPPasswordMgrWithDefaultRealm()
+            manager.add_password(None, new_source, parsed_source.username, parsed_source.password)
+            authHandler = urllib.request.HTTPBasicAuthHandler(manager)
+            opener = urllib.request.build_opener(authHandler)
+            urllib.request.install_opener(opener)
         response = urllib.request.urlopen(source)
         archive = response.read()
         bb.utils.mkdirhier(to_dir)
@@ -228,6 +239,15 @@ def download_old_versions(d):
     for format in range(3, current_format + 1):
         try:
             url = '%s/version/format%d/latest' % (content_url, format)
+            parsed_url = urllib.parse.urlsplit(url)
+            if( parsed_url.username != None):
+                new_url = ( parsed_url.scheme, re.sub( re.escape( parsed_url.username+':'+parsed_url.password+'@'), '',parsed_url.netloc), parsed_url.path, parsed_url.query, parsed_url.fragment)
+                url = urllib.parse.urlunsplit( new_url)
+                manager = urllib.request.HTTPPasswordMgrWithDefaultRealm()
+                manager.add_password(None, new_url, parsed_url.username, parsed_url.password)
+                authHandler = urllib.request.HTTPBasicAuthHandler(manager)
+                opener = urllib.request.build_opener(authHandler)
+                urllib.request.install_opener(opener)
             response = urllib.request.urlopen(url)
             version = int(response.read())
             latest_versions[format] = version


More information about the yocto mailing list