diff --git a/config.py b/config.py index df5a90a7b..4fe5b2cd5 100644 --- a/config.py +++ b/config.py @@ -80,11 +80,11 @@ class DefaultConfig(object): AUTHENTICATION_TYPE = 'Database' # Build logs - BUILDLOGS_REDIS_HOSTNAME = 'logs.quay.io' + BUILDLOGS_REDIS = {'host': 'logs.quay.io'} BUILDLOGS_OPTIONS = [] # Real-time user events - USER_EVENTS_REDIS_HOSTNAME = 'logs.quay.io' + USER_EVENTS_REDIS = {'host': 'logs.quay.io'} # Stripe config BILLING_TYPE = 'FakeStripe' diff --git a/data/buildlogs.py b/data/buildlogs.py index d2904fbc8..6e24f501b 100644 --- a/data/buildlogs.py +++ b/data/buildlogs.py @@ -16,8 +16,8 @@ class RedisBuildLogs(object): COMMAND = 'command' PHASE = 'phase' - def __init__(self, redis_host): - self._redis = redis.StrictRedis(host=redis_host, socket_connect_timeout=5) + def __init__(self, redis_config): + self._redis = redis.StrictRedis(socket_connect_timeout=5, **redis_config) @staticmethod def _logs_key(build_id): @@ -104,7 +104,13 @@ class BuildLogs(object): self.state = None def init_app(self, app): - buildlogs_hostname = app.config.get('BUILDLOGS_REDIS_HOSTNAME') + buildlogs_config = app.config.get('BUILDLOGS_REDIS') + if not buildlogs_config: + # This is the old key name. + buildlogs_config = { + 'host': app.config.get('BUILDLOGS_REDIS_HOSTNAME') + } + buildlogs_options = app.config.get('BUILDLOGS_OPTIONS', []) buildlogs_import = app.config.get('BUILDLOGS_MODULE_AND_CLASS', None) @@ -113,7 +119,7 @@ class BuildLogs(object): else: klass = import_class(buildlogs_import[0], buildlogs_import[1]) - buildlogs = klass(buildlogs_hostname, *buildlogs_options) + buildlogs = klass(buildlogs_config, *buildlogs_options) # register extension with app app.extensions = getattr(app, 'extensions', {}) diff --git a/data/userevent.py b/data/userevent.py index b732a6e12..b45d4e4fa 100644 --- a/data/userevent.py +++ b/data/userevent.py @@ -7,14 +7,14 @@ class UserEventBuilder(object): Defines a helper class for constructing UserEvent and UserEventListener instances. """ - def __init__(self, redis_host): - self._redis_host = redis_host + def __init__(self, redis_config): + self._redis_config = redis_config def get_event(self, username): - return UserEvent(self._redis_host, username) + return UserEvent(self._redis_config, username) def get_listener(self, username, events): - return UserEventListener(self._redis_host, username, events) + return UserEventListener(self._redis_config, username, events) class UserEventsBuilderModule(object): @@ -26,8 +26,14 @@ class UserEventsBuilderModule(object): self.state = None def init_app(self, app): - redis_hostname = app.config.get('USER_EVENTS_REDIS_HOSTNAME') - user_events = UserEventBuilder(redis_hostname) + redis_config = app.config.get('USER_EVENTS_REDIS') + if not redis_config: + # This is the old key name. + redis_config = { + 'host': app.config.get('USER_EVENTS_REDIS_HOSTNAME') + } + + user_events = UserEventBuilder(redis_config) # register extension with app app.extensions = getattr(app, 'extensions', {}) @@ -43,8 +49,8 @@ class UserEvent(object): Defines a helper class for publishing to realtime user events as backed by Redis. """ - def __init__(self, redis_host, username): - self._redis = redis.StrictRedis(host=redis_host, socket_connect_timeout=5) + def __init__(self, redis_config, username): + self._redis = redis.StrictRedis(socket_connect_timeout=5, **redis_config) self._username = username @staticmethod @@ -74,10 +80,10 @@ class UserEventListener(object): Defines a helper class for subscribing to realtime user events as backed by Redis. """ - def __init__(self, redis_host, username, events=set([])): + def __init__(self, redis_config, username, events=set([])): channels = [self._user_event_key(username, e) for e in events] - self._redis = redis.StrictRedis(host=redis_host, socket_connect_timeout=5) + self._redis = redis.StrictRedis(socket_connect_timeout=5, **redis_config) self._pubsub = self._redis.pubsub() self._pubsub.subscribe(channels) diff --git a/test/testlogs.py b/test/testlogs.py index 7fd9eac21..cd4ea6c9d 100644 --- a/test/testlogs.py +++ b/test/testlogs.py @@ -45,8 +45,8 @@ class TestBuildLogs(RedisBuildLogs): 'pull_completion': 0.0, } - def __init__(self, redis_host, namespace, repository, test_build_id, allow_delegate=True): - super(TestBuildLogs, self).__init__(redis_host) + def __init__(self, redis_config, namespace, repository, test_build_id, allow_delegate=True): + super(TestBuildLogs, self).__init__(redis_config) self.namespace = namespace self.repository = repository self.test_build_id = test_build_id