From: Ingo Flaschberger <ingo.flaschberger@gmail.com>
To: Patrick Ohly <patrick.ohly@intel.com>, yocto@yoctoproject.org
Subject: Re: [meta-swupd][PATCH 1/1] bundles.py: allow username/password encoded in URLs
Date: Sun, 25 Feb 2018 00:31:15 +0100 [thread overview]
Message-ID: <c835abfa-c411-eefe-3ed4-909529965813@gmail.com> (raw)
In-Reply-To: <1515578331.6718.20.camel@intel.com>
[-- Attachment #1: Type: text/plain, Size: 748 bytes --]
Dear Patrick,
attached requested patch.
Kind regards,
Ingo Flaschberger
Am 10.01.2018 um 10:58 schrieb Patrick Ohly:
> On Tue, 2018-01-09 at 19:28 +0100, Ingo Flaschberger wrote:
>> Dear Patrick,
>>
>> it works if you replace:
>> manager.add_password(None, parsed_url, parsed_url.username,
>> parsed_url.password)
>> with:
>> manager.add_password(None, new_url, parsed_url.username,
>> parsed_url.password)
> I assume this works on top of my proposal. To avoid such ambiguity and
> the risk that something gets merged that is still incomplete, please
> post the entire patch as tested by you. The right way would be "git
> send-email", but I can also take "git diff" attached to an email.
>
[-- Attachment #2: swupd_auth.patch --]
[-- Type: text/plain, Size: 2880 bytes --]
diff --git a/lib/swupd/bundles.py b/lib/swupd/bundles.py
index b4c6f49..bec95d4 100644
--- a/lib/swupd/bundles.py
+++ b/lib/swupd/bundles.py
@@ -4,6 +4,7 @@ import subprocess
import shutil
import urllib.request
import urllib.error
+import urllib.parse
from bb.utils import export_proxies
from oe.package_manager import RpmPM
from oe.package_manager import OpkgPM
@@ -152,6 +153,30 @@ def copy_bundle_contents(d):
for bndl in bundles:
stage_empty_bundle(d, bndl)
+def handle_plain_auth(url):
+ """
+ Check for special urls with username/password (as in http://user:password@host/),
+ extract those and install an auth handler which will provide them
+ to the HTTP server when needed. Returns the URL that is to be instead of the original one.
+ """
+ parsed_url = urllib.parse.urlsplit(url)
+ if parsed_url.username != None:
+ # Use the netloc with just the hostname, without username/password.
+ netloc = parsed_url.hostname
+ if parsed_url.port is not None:
+ netloc += ":%d" % parsed_url.port
+ new_url = urllib.parse.SplitResult(parsed_url.scheme, netloc, parsed_url.path, parsed_url.query, parsed_url.fragment)
+ # The username/password are installed permanently in the urllib.request module
+ # for future use with all URLs beneath 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)
+ return urllib.parse.urlunsplit(new_url)
+ else:
+ return url
+
def download_manifests(content_url, version, component, to_dir):
"""
Download one manifest file and recursively all manifests referenced by it.
@@ -203,7 +228,7 @@ def download_old_versions(d):
a normal build and thus is not on the critical path.
"""
- content_url = d.getVar('SWUPD_CONTENT_URL', True)
+ content_url = handle_plain_auth(d.getVar('SWUPD_CONTENT_URL', True))
version_url = d.getVar('SWUPD_VERSION_URL', True)
current_format = int(d.getVar('SWUPD_FORMAT', True))
deploy_dir = d.getVar('DEPLOY_DIR_SWUPD', True)
@@ -240,6 +265,11 @@ def download_old_versions(d):
bb.debug(1, '%s does not exist, skipping that format' % url)
else:
raise
+ except urllib.error.URLError as url_error:
+ if re.search( 'No such file or directory', str(url_error.reason)):
+ bb.debug(1, '%s does not exist, skipping that format' % url)
+ else:
+ raise
# Now get the Manifests of the latest versions and the
# versions we are supposed to provide a delta for, as a starting point.
prev parent reply other threads:[~2018-02-24 23:31 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c835abfa-c411-eefe-3ed4-909529965813@gmail.com \
--to=ingo.flaschberger@gmail.com \
--cc=patrick.ohly@intel.com \
--cc=yocto@yoctoproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.