From 36db0d6748b452368a8ae468e7eb3157669be740 Mon Sep 17 00:00:00 2001 From: Mathieu Bridon Date: Aug 13 2015 13:56:21 +0000 Subject: [PATCH 1/3] Drop obsolete functions These functions are now completely unused. They were overridden from pyrpkg to use our client-side and custom CA certificates. However, pyrpkg now handles that on its own with its new pyrpkg.lookaside module, all we need to do in fedpkg is define our fedpkg.Commands.cert_file and fedpkg.Commands.ca_cert properties... which we've been doing since forever already. Signed-off-by: Mathieu Bridon --- diff --git a/src/fedpkg/__init__.py b/src/fedpkg/__init__.py index 48f20d5..ee661d8 100644 --- a/src/fedpkg/__init__.py +++ b/src/fedpkg/__init__.py @@ -14,7 +14,6 @@ import os import cli import git import re -import pycurl import fedora_cert import platform @@ -196,41 +195,6 @@ class Commands(pyrpkg.Commands): super(Commands, self).load_user() # New functionality - def _create_curl(self): - """Common curl setup options used for all requests to lookaside.""" - - # Overloaded to add cert files to curl objects - # Call the super class - curl = super(Commands, self)._create_curl() - - # Set the users Fedora certificate: - if os.path.exists(self.cert_file): - curl.setopt(pycurl.SSLCERT, self.cert_file) - else: - self.log.warn("Missing certificate: %s" % self.cert_file) - - # Set the Fedora CA certificate: - if os.path.exists(self.ca_cert): - curl.setopt(pycurl.CAINFO, self.ca_cert) - else: - self.log.warn("Missing certificate: %s" % self.ca_cert) - - return curl - - def _do_curl(self, file_hash, file): - """Use curl manually to upload a file""" - - # This is overloaded to add in the fedora user's cert - cmd = ['curl', '-k', '--cert', self.cert_file, '--fail', '-o', - '/dev/null', '--show-error', '--progress-bar', '-F', - 'name=%s' % self.module_name, - '-F', '%ssum=%s' % (self.lookasidehash, file_hash), - '-F', 'file=@%s' % file] - if self.quiet: - cmd.append('-s') - cmd.append(self.lookaside_cgi) - self._run_command(cmd) - def _findmasterbranch(self): """Find the right "fedora" for master""" From bb5c27819a610f6a216ce6b28bf6527f12296a68 Mon Sep 17 00:00:00 2001 From: Mathieu Bridon Date: Aug 13 2015 13:56:53 +0000 Subject: [PATCH 2/3] Simplify handling of our custom certificates The property loader is an overly-complex solution to cache the results of getting a property. In the case of our certificates, the call is not very expensive so we don't even need to cache it at all. However, given that pyrpkg now has a cached_property decorator which does just that, we might as well use it. Signed-off-by: Mathieu Bridon --- diff --git a/src/fedpkg/__init__.py b/src/fedpkg/__init__.py index ee661d8..44064a8 100644 --- a/src/fedpkg/__init__.py +++ b/src/fedpkg/__init__.py @@ -17,6 +17,8 @@ import re import fedora_cert import platform +from pyrpkg.utils import cached_property + class Commands(pyrpkg.Commands): @@ -56,8 +58,6 @@ class Commands(pyrpkg.Commands): # New properties self._kojiconfig = None - self._cert_file = None - self._ca_cert = None # Store this for later self._orig_kojiconfig = kojiconfig @@ -95,27 +95,23 @@ class Commands(pyrpkg.Commands): return self._kojiconfig = self._orig_kojiconfig - @property + @cached_property def cert_file(self): - """This property ensures the cert_file attribute""" + """A client-side certificate for SSL authentication - if not self._cert_file: - self.load_cert_files() - return self._cert_file + We override this from pyrpkg because we actually need a client-side + certificate. + """ + return os.path.expanduser('~/.fedora.cert') - @property + @cached_property def ca_cert(self): - """This property ensures the ca_cert attribute""" + """A CA certificate to authenticate the server in SSL connections - if not self._ca_cert: - self.load_cert_files() - return self._ca_cert - - def load_cert_files(self): - """This loads the cert_file attribute""" - - self._cert_file = os.path.expanduser('~/.fedora.cert') - self._ca_cert = os.path.expanduser('~/.fedora-server-ca.cert') + We override this from pyrpkg because we actually need a custom + CA certificate. + """ + return os.path.expanduser('~/.fedora-server-ca.cert') # Overloaded property loaders def load_rpmdefines(self): From 9f5468de1191fa67959226e62d6ba5046d3358b9 Mon Sep 17 00:00:00 2001 From: Mathieu Bridon Date: Aug 13 2015 13:56:59 +0000 Subject: [PATCH 3/3] lookaside: Use our new download path We are moving to a new hash type for source tarballs in Fedora. As part of this process, we are moving to a new download URL where the hash type is a part of the path to the file to download. As of today, Wed Jul 15 2015, all the source files are available at that new URL. That means it is time to start downloading from that new URL now. If upstream pyrpkg ever moves its default to the new URL format, we can even drop this downstream implementation altogether. Signed-off-by: Mathieu Bridon --- diff --git a/src/fedpkg/__init__.py b/src/fedpkg/__init__.py index 44064a8..518d7ff 100644 --- a/src/fedpkg/__init__.py +++ b/src/fedpkg/__init__.py @@ -17,6 +17,7 @@ import re import fedora_cert import platform +from .lookaside import FedoraLookasideCache from pyrpkg.utils import cached_property @@ -113,6 +114,16 @@ class Commands(pyrpkg.Commands): """ return os.path.expanduser('~/.fedora-server-ca.cert') + @cached_property + def lookasidecache(self): + """A helper to interact with the lookaside cache + + We override this because we need a different download path. + """ + return FedoraLookasideCache( + self.lookasidehash, self.lookaside, self.lookaside_cgi, + client_cert=self.cert_file, ca_cert=self.ca_cert) + # Overloaded property loaders def load_rpmdefines(self): """Populate rpmdefines based on branch data""" diff --git a/src/fedpkg/lookaside.py b/src/fedpkg/lookaside.py new file mode 100644 index 0000000..470305b --- /dev/null +++ b/src/fedpkg/lookaside.py @@ -0,0 +1,29 @@ +# Copyright (c) 2015 - Red Hat Inc. +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2 of the License, or (at your +# option) any later version. See http://www.gnu.org/copyleft/gpl.html for +# the full text of the license. + + +"""Interact with the Fedora lookaside cache + +We need to override the pyrpkg.lookasidecache module to handle our custom +download path. +""" + + +from pyrpkg.errors import DownloadError +from pyrpkg.lookaside import CGILookasideCache + + +class FedoraLookasideCache(CGILookasideCache): + def __init__(self, hashtype, download_url, upload_url, + client_cert=None, ca_cert=None): + super(FedoraLookasideCache, self).__init__( + hashtype, download_url, upload_url, client_cert=client_cert, + ca_cert=ca_cert) + + self.download_path = ( + '%(name)s/%(filename)s/%(hashtype)s/%(hash)s/%(filename)s')