From patchwork Fri May 20 19:14:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Whitcroft X-Patchwork-Id: 624601 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) by ozlabs.org (Postfix) with ESMTP id 3rBHgK0zKpz9t3n; Sat, 21 May 2016 05:14:37 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1b3psX-0008V3-Sd; Fri, 20 May 2016 19:14:33 +0000 Received: from mail-wm0-f45.google.com ([74.125.82.45]) by huckleberry.canonical.com with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.76) (envelope-from ) id 1b3psQ-0008Su-Ov for kernel-team@lists.ubuntu.com; Fri, 20 May 2016 19:14:26 +0000 Received: by mail-wm0-f45.google.com with SMTP id n129so284441842wmn.1 for ; Fri, 20 May 2016 12:14:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=dGElVT2J1PpBYb1y7dGK1M10R7j/wP6AoBsL4b9bt4E=; b=fqc53aaKKO8JG8MIT5A6OMjXqUDgKYrqz7k1OhXiI2FYRLEFpVJwWiICw/OR2O44qh BeooR955X1iK8YspMdhXDGRkUkxt/UUg3nqd1JChRFtrMtVb4A740RseVGZCDwfxeuVB QqRsaMXJOQdGR18LFuue7XeXsXhc9ZbghEyp+NrQYnMyfPj25Ls6GEuaa+B2cEVo7fo8 uYTe5aTWI5lWKqAW535TlDxPDJDfFXKTdh/URfk6i5PPtJIcWUpFKfWlsX8zCsYuXRDo 3hal4AXB4Dn0pGju1LCG/HWbLTddeuMSEmmC+P5dl5QNb1f7NAw9/aGbY8zsXH2zjk+q IXzQ== X-Gm-Message-State: AOPr4FVwxFpG1veZ61zUCuDRlv1nxpmB2jLvrqayt0r/u4uez6ILOZwz4f2OZFwg6o03ZoZ4 X-Received: by 10.194.204.233 with SMTP id lb9mr4809116wjc.147.1463771666330; Fri, 20 May 2016 12:14:26 -0700 (PDT) Received: from localhost ([2001:470:6973:2:4013:ff9e:88ca:ef71]) by smtp.gmail.com with ESMTPSA id m140sm5933675wma.24.2016.05.20.12.14.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 20 May 2016 12:14:25 -0700 (PDT) From: Andy Whitcroft To: kernel-team@lists.ubuntu.com Subject: [trusty/master 1/1] UBUNTU: fix download-signed to handle private PPAs Date: Fri, 20 May 2016 20:14:22 +0100 Message-Id: <1463771662-25414-2-git-send-email-apw@canonical.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1463771662-25414-1-git-send-email-apw@canonical.com> References: <1463771662-25414-1-git-send-email-apw@canonical.com> Cc: Andy Whitcroft X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.14 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: kernel-team-bounces@lists.ubuntu.com BugLink: http://bugs.launchpad.net/bugs/1535634 Signed-off-by: Andy Whitcroft --- download-signed | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/download-signed b/download-signed index ac9b7d0..c064a79 100755 --- a/download-signed +++ b/download-signed @@ -4,8 +4,8 @@ import sys import re import shutil from urllib.parse import urlparse, urlunparse -from urllib.request import urlopen from urllib.error import HTTPError +from urllib import request import apt from aptsources.distro import get_distro @@ -33,16 +33,45 @@ distro = get_distro().codename package_dir = "/main/uefi/%s-%s/%s/" % ( src_package, package.architecture, package_version) +# Prepare the master url stem and pull out any username/password. If present +# replace the default opener with one which offers that password. +dists_parsed_master = list(pool_parsed) +if '@' in dists_parsed_master[1]: + (username_password, host) = pool_parsed[1].split('@', 1) + (username, password) = username_password.split(':', 1) + + dists_parsed_master[1] = host + + # Work out the authentication domain. + domain_parsed = [ dists_parsed_master[0], dists_parsed_master[1], '/', None, None, None ] + auth_uri = urlunparse(domain_parsed) + + # create a password manager + password_mgr = request.HTTPPasswordMgrWithDefaultRealm() + + # Add the username and password. + # If we knew the realm, we could use it instead of None. + password_mgr.add_password(None, auth_uri, username, password) + + handler = request.HTTPBasicAuthHandler(password_mgr) + + # create "opener" (OpenerDirector instance) + opener = request.build_opener(handler) + + # Now all calls to urllib.request.urlopen use our opener. + request.install_opener(opener) + + def download(base): for pocket in ('-proposed', '-updates', '-security', '', '-backports'): - dists_parsed = list(pool_parsed) + dists_parsed = list(dists_parsed_master) dists_parsed[2] = re.sub(r"/pool/.*", "/dists/" + distro + \ pocket + package_dir + base, dists_parsed[2]) dists_uri = urlunparse(dists_parsed) print("Downloading %s ... " % dists_uri, end='') try: - with urlopen(dists_uri) as dists, open(base, "wb") as out: + with request.urlopen(dists_uri) as dists, open(base, "wb") as out: shutil.copyfileobj(dists, out) except HTTPError as e: if e.code == 404: