All of lore.kernel.org
 help / color / mirror / Atom feed
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: Thu, 21 Dec 2017 00:18:20 +0100	[thread overview]
Message-ID: <8524e767-204b-2e4f-9971-d0c51862de0c@gmail.com> (raw)
In-Reply-To: <20171220155058.8961-1-patrick.ohly@intel.com>

Dear Patrick,

this doesn't work:
      0162:    """
      0163:    parsed_url = urllib.parse.urlsplit(url)
      0164:    if parsed_url.username != None:
      0165:        # Use the netloc with just the hostname, without 
username/password.
  *** 0166:        parsed_url.netloc = parsed_url.hostname
      0167:        # The username/password are installed permanently in 
the urllib.request module
      0168:        # for future use with all URLs beneath url.
      0169:        manager = 
urllib.request.HTTPPasswordMgrWithDefaultRealm()
      0170:        manager.add_password(None, parsed_url, 
parsed_url.username, parsed_url.password)
Exception: AttributeError: can't set attribute


Using hostname as netloc will also remove an additional portnumber - 
could this be a problem?

Bye,
     Ingo


Am 20.12.2017 um 16:50 schrieb Patrick Ohly:
> Downloading content and version information via HTTP may need a
> username/password for basic authentication. To support this,
> SWUPD_VERSION_URL and SWUPD_CONTENT_URL can now contain URLs of the
> form http(s)://<user>:<password>@<host>/.
>
> Original patch from: Ingo Flaschberger <ingo.flaschberger@gmail.com>
>
> Signed-off-by: Patrick Ohly <patrick.ohly@intel.com>
> ---
>   lib/swupd/bundles.py | 26 ++++++++++++++++++++++++--
>   1 file changed, 24 insertions(+), 2 deletions(-)
>
> diff --git a/lib/swupd/bundles.py b/lib/swupd/bundles.py
> index e1eec5a..48c7455 100644
> --- a/lib/swupd/bundles.py
> +++ b/lib/swupd/bundles.py
> @@ -5,6 +5,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
> @@ -153,6 +154,27 @@ 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.
> +        parsed_url.netloc = parsed_url.hostname
> +        # 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, parsed_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_source)
> +    else:
> +        return url
> +
>   def download_manifests(content_url, version, component, to_dir):
>       """
>       Download one manifest file and recursively all manifests referenced by it.
> @@ -204,8 +226,8 @@ def download_old_versions(d):
>       a normal build and thus is not on the critical path.
>       """
>   
> -    content_url = d.getVar('SWUPD_CONTENT_BUILD_URL', True)
> -    version_url = d.getVar('SWUPD_VERSION_BUILD_URL', True)
> +    content_url = handle_plain_auth(d.getVar('SWUPD_CONTENT_BUILD_URL', True))
> +    version_url = handle_plain_auth(d.getVar('SWUPD_VERSION_BUILD_URL', True))
>       current_format = int(d.getVar('SWUPD_FORMAT', True))
>       deploy_dir = d.getVar('DEPLOY_DIR_SWUPD', True)
>       www_dir = os.path.join(deploy_dir, 'www')



  reply	other threads:[~2017-12-20 23:18 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 [this message]
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

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=8524e767-204b-2e4f-9971-d0c51862de0c@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.