Allow for additional REDIS config such as password and port
This commit is contained in:
parent
d9c7e92637
commit
2c5cc7990f
4 changed files with 30 additions and 18 deletions
|
@ -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'
|
||||
|
|
|
@ -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', {})
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Reference in a new issue