Allow namespaces to be whitelisted for OCI, but not V22

This commit is contained in:
Joseph Schorr 2019-01-21 14:40:26 -05:00
parent 92808e8d3f
commit 7c241a93f6
4 changed files with 13 additions and 7 deletions

3
app.py
View file

@ -91,7 +91,8 @@ app.config.update(environ_config)
# Split the registry model based on config. # Split the registry model based on config.
# TODO(jschorr): Remove once we are fully on the OCI data model. # 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. # Allow user to define a custom storage preference for the local instance.
_distributed_storage_preference = os.environ.get('QUAY_DISTRIBUTED_STORAGE_PREFERENCE', '').split() _distributed_storage_preference = os.environ.get('QUAY_DISTRIBUTED_STORAGE_PREFERENCE', '').split()

View file

@ -12,14 +12,15 @@ class RegistryModelProxy(object):
def __init__(self): def __init__(self):
self._model = oci_model if os.getenv('OCI_DATA_MODEL') == 'true' else pre_oci_model 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': if os.getenv('OCI_DATA_MODEL') == 'true':
return return
logger.info('===============================') 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('===============================') logger.info('===============================')
self._model = SplitModel(v22_whitelist) self._model = SplitModel(oci_whitelist, v22_whitelist)
def set_for_testing(self, use_oci_model): def set_for_testing(self, use_oci_model):
self._model = oci_model if use_oci_model else pre_oci_model self._model = oci_model if use_oci_model else pre_oci_model

View file

@ -11,9 +11,12 @@ logger = logging.getLogger(__name__)
class SplitModel(object): 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.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): def supports_schema2(self, namespace_name):
""" Returns whether the implementation of the data interface supports schema 2 format """ Returns whether the implementation of the data interface supports schema 2 format
manifests. """ manifests. """
@ -72,7 +75,7 @@ class SplitModel(object):
args_dict = {argnames[index + 1]: value for index, value in enumerate(args)} args_dict = {argnames[index + 1]: value for index, value in enumerate(args)}
namespace_name = self._namespace_from_kwargs(args_dict) 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`', logger.debug('Calling method `%s` under OCI data model for namespace `%s`',
attr, namespace_name) attr, namespace_name)
return getattr(oci_model, attr)(*args, **kwargs) return getattr(oci_model, attr)(*args, **kwargs)

View file

@ -35,7 +35,8 @@ from util.bytes import Bytes
from test.fixtures import * 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): def registry_model(request, initialized_db):
return request.param return request.param