From 7c241a93f694505971912c8223b8cc19c397cebc Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Mon, 21 Jan 2019 14:40:26 -0500 Subject: [PATCH] Allow namespaces to be whitelisted for OCI, but not V22 --- app.py | 3 ++- data/registry_model/__init__.py | 7 ++++--- data/registry_model/modelsplitter.py | 7 +++++-- data/registry_model/test/test_interface.py | 3 ++- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app.py b/app.py index c5b84e174..0265c6294 100644 --- a/app.py +++ b/app.py @@ -91,7 +91,8 @@ app.config.update(environ_config) # Split the registry model based on config. # TODO(jschorr): Remove once we are fully on the OCI data model. -registry_model.setup_split(app.config.get('V22_NAMESPACE_WHITELIST') or set()) +registry_model.setup_split(app.config.get('OCI_NAMESPACE_WHITELIST') or set(), + app.config.get('V22_NAMESPACE_WHITELIST') or set()) # Allow user to define a custom storage preference for the local instance. _distributed_storage_preference = os.environ.get('QUAY_DISTRIBUTED_STORAGE_PREFERENCE', '').split() diff --git a/data/registry_model/__init__.py b/data/registry_model/__init__.py index f806bd4c3..fead18217 100644 --- a/data/registry_model/__init__.py +++ b/data/registry_model/__init__.py @@ -12,14 +12,15 @@ class RegistryModelProxy(object): def __init__(self): self._model = oci_model if os.getenv('OCI_DATA_MODEL') == 'true' else pre_oci_model - def setup_split(self, v22_whitelist): + def setup_split(self, oci_whitelist, v22_whitelist): if os.getenv('OCI_DATA_MODEL') == 'true': return logger.info('===============================') - logger.info('Enabling split registry model with namespace whitelist `%s`', v22_whitelist) + logger.info('Enabling split registry model with OCI whitelist `%s` and V22 whitelist `%s`', + oci_whitelist, v22_whitelist) logger.info('===============================') - self._model = SplitModel(v22_whitelist) + self._model = SplitModel(oci_whitelist, v22_whitelist) def set_for_testing(self, use_oci_model): self._model = oci_model if use_oci_model else pre_oci_model diff --git a/data/registry_model/modelsplitter.py b/data/registry_model/modelsplitter.py index 8f428be7c..8c61a7b35 100644 --- a/data/registry_model/modelsplitter.py +++ b/data/registry_model/modelsplitter.py @@ -11,9 +11,12 @@ logger = logging.getLogger(__name__) class SplitModel(object): - def __init__(self, v22_namespace_whitelist): + def __init__(self, oci_namespace_whitelist, v22_namespace_whitelist): self.v22_namespace_whitelist = set(v22_namespace_whitelist) + self.oci_namespace_whitelist = set(oci_namespace_whitelist) + self.oci_namespace_whitelist.update(v22_namespace_whitelist) + def supports_schema2(self, namespace_name): """ Returns whether the implementation of the data interface supports schema 2 format manifests. """ @@ -72,7 +75,7 @@ class SplitModel(object): args_dict = {argnames[index + 1]: value for index, value in enumerate(args)} namespace_name = self._namespace_from_kwargs(args_dict) - if namespace_name in self.v22_namespace_whitelist: + if namespace_name in self.oci_namespace_whitelist: logger.debug('Calling method `%s` under OCI data model for namespace `%s`', attr, namespace_name) return getattr(oci_model, attr)(*args, **kwargs) diff --git a/data/registry_model/test/test_interface.py b/data/registry_model/test/test_interface.py index 413081b97..4a61beb5f 100644 --- a/data/registry_model/test/test_interface.py +++ b/data/registry_model/test/test_interface.py @@ -35,7 +35,8 @@ from util.bytes import Bytes from test.fixtures import * -@pytest.fixture(params=[PreOCIModel(), OCIModel(), SplitModel({'buynlarge'})]) +@pytest.fixture(params=[PreOCIModel(), OCIModel(), + SplitModel({'devtable'}, {'buynlarge'})]) def registry_model(request, initialized_db): return request.param