All of lore.kernel.org
 help / color / mirror / Atom feed
* [meta-swupd] allow username/password encoded in SWUPD_VERSION_URL and SWUPD_CONTENT_URL
@ 2017-03-23 15:04 Ingo Flaschberger
  2017-03-24  9:04 ` Patrick Ohly
  0 siblings, 1 reply; 10+ messages in thread
From: Ingo Flaschberger @ 2017-03-23 15:04 UTC (permalink / raw)
  To: yocto

[-- Attachment #1: Type: text/plain, Size: 183 bytes --]

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.



[-- Attachment #2: basic-auth.patch --]
[-- Type: text/plain, Size: 2500 bytes --]

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

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2018-02-24 23:31 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-23 15:04 [meta-swupd] allow username/password encoded in SWUPD_VERSION_URL and SWUPD_CONTENT_URL Ingo Flaschberger
2017-03-24  9:04 ` Patrick Ohly
2017-03-25 20:14   ` Ingo Flaschberger
2017-12-20 15:50     ` Patrick Ohly
2017-12-20 15:50       ` [meta-swupd][PATCH 1/1] bundles.py: allow username/password encoded in URLs Patrick Ohly
2017-12-20 23:18         ` Ingo Flaschberger
2018-01-09 16:57           ` Patrick Ohly
2018-01-09 18:28             ` Ingo Flaschberger
2018-01-10  9:58               ` Patrick Ohly
2018-02-24 23:31                 ` Ingo Flaschberger

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.