From 5d980cbb9cd29887a888fd9627ebdca27b260bc7 Mon Sep 17 00:00:00 2001 From: Lubomír Sedlář Date: Jul 12 2017 07:39:06 +0000 Subject: Supply namespace to lookaside (if enabled) If the dist-git server is configured to be namespaced, we should send the full name including namespace so that non-default namespaces can use lookaside as well. This is guarded by a new option lookaside_namespaced. Signed-off-by: Lubomír Sedlář --- diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py index 81b1526..6e9d301 100644 --- a/pyrpkg/__init__.py +++ b/pyrpkg/__init__.py @@ -69,7 +69,7 @@ class Commands(object): build_client, koji_config_type='kojiconfig', user=None, dist=None, target=None, quiet=False, - distgit_namespaced=False, realms=None): + distgit_namespaced=False, realms=None, lookaside_namespaced=False): """Init the object and some configuration details.""" # Path to operate on, most often pwd @@ -174,6 +174,10 @@ class Commands(object): self.distgit_namespaced = distgit_namespaced # Kerberos realms used for username detection self.realms = realms + # Whether lookaside cache is namespaced as well. If set to true, + # package name will be sent to lookaside CGI script as 'namespace/name' + # instead of just name. + self.lookaside_namespaced = lookaside_namespaced # Define properties here # Properties allow us to "lazy load" various attributes, which also means @@ -1752,7 +1756,8 @@ class Commands(object): for entry in sourcesf.entries: outfile = os.path.join(outdir, entry.file) self.lookasidecache.download( - self.module_name, entry.file, entry.hash, outfile, + self.ns_module_name if self.lookaside_namespaced else self.module_name, + entry.file, entry.hash, outfile, hashtype=entry.hashtype, branch=self.branch_merge) def switch_branch(self, branch, fetch=True): @@ -2381,7 +2386,9 @@ class Commands(object): raise rpkgError(msg) gitignore.add('/%s' % file_basename) - self.lookasidecache.upload(self.module_name, f, file_hash) + self.lookasidecache.upload( + self.ns_module_name if self.lookaside_namespaced else self.module_name, + f, file_hash) sourcesf.write() gitignore.write() diff --git a/pyrpkg/cli.py b/pyrpkg/cli.py index 4ae0fba..17bd9ab 100644 --- a/pyrpkg/cli.py +++ b/pyrpkg/cli.py @@ -96,6 +96,14 @@ class cliClient(object): self.load_cmd() return(self._cmd) + def _get_bool_opt(self, opt, default=False): + try: + return self.config.getboolean(self.name, opt) + except ValueError: + raise rpkgError('%s option must be a boolean' % opt) + except configparser.NoOptionError: + return default + def load_cmd(self): """This sets up the cmd object""" @@ -107,13 +115,8 @@ class cliClient(object): # load items from the config file items = dict(self.config.items(self.name, raw=True)) - try: - dg_namespaced = self.config.getboolean(self.name, - "distgit_namespaced") - except ValueError: - raise rpkgError('distgit_namespaced option must be a boolean') - except configparser.NoOptionError: - dg_namespaced = False + dg_namespaced = self._get_bool_opt('distgit_namespaced') + la_namespaced = self._get_bool_opt('lookaside_namespaced') # Read comma separated list of kerberos realms realms = [realm @@ -155,7 +158,8 @@ class cliClient(object): target=target, quiet=self.args.q, distgit_namespaced=dg_namespaced, - realms=realms + realms=realms, + lookaside_namespaced=la_namespaced ) if self.args.module_name: diff --git a/pyrpkg/lookaside.py b/pyrpkg/lookaside.py index db906dc..21beaa4 100644 --- a/pyrpkg/lookaside.py +++ b/pyrpkg/lookaside.py @@ -136,7 +136,9 @@ class CGILookasideCache(object): """Download a source file Args: - name (str): The name of the module. (usually the name of the SRPM) + name (str): The name of the module. (usually the name of the SRPM). + This can include the namespace as well (depending on + what the server side expects). filename (str): The name of the file to download. hash (str): The known good hash of the file. outfile (str): The full path where to save the downloaded file. @@ -204,7 +206,9 @@ class CGILookasideCache(object): """Verify whether a file exists on the lookaside cache Args: - name: The name of the module. (usually the name of the SRPM) + name: The name of the module. (usually the name of the SRPM). + This can include the namespace as well (depending on + what the server side expects). filename: The name of the file to check for. hash: The known good hash of the file. """ @@ -275,6 +279,8 @@ class CGILookasideCache(object): Args: name (str): The name of the module. (usually the name of the SRPM) + This can include the namespace as well (depending on + what the server side expects). filepath (str): The full path to the file to upload. hash (str): The known good hash of the file. """