Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add redis user and password support #199

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion datapackage_pipelines/celery_tasks/dependency_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ class DependencyManager(object):
def __init__(self, host=os.environ.get('DPP_REDIS_HOST'), port=6379):
self.redis = None
if host is not None and len(host) > 0:
conn = redis.StrictRedis(host=host, port=port, db=5)
params = {
'host': host,
'port': port,
'db': 5,
'username': os.environ.get('DPP_REDIS_USERNAME'),
'password': os.environ.get('DPP_REDIS_PASSWORD'),
}
conn = redis.StrictRedis(**params)
try:
conn.ping()
self.redis = conn
Expand Down
5 changes: 3 additions & 2 deletions datapackage_pipelines/status/backend_redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ class RedisBackend(object):

KIND = 'redis'

def __init__(self, host=None, port=6379):
def __init__(self, host=None, port=6379, username=None, password=None):
self.redis = None
if host is not None and len(host) > 0:
conn = redis.StrictRedis(host=host, port=port, db=5)
conn = redis.StrictRedis(host=host, port=port, db=5,
username=username, password=password)
try:
conn.ping()
self.redis = conn
Expand Down
8 changes: 5 additions & 3 deletions datapackage_pipelines/status/status_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@
class StatusManager(object):

def __init__(self, *, host=None, port=6379, root_dir='.'):
self._host = host
self._host = os.environ.get('DPP_REDIS_HOST')
self._port = port
self._username = os.environ.get('DPP_REDIS_USERNAME')
self._password = os.environ.get('DPP_REDIS_PASSWORD')
self._backend = None
self._root_dir = root_dir

@property
def backend(self):
if self._backend is None:
redis = RedisBackend(self._host, self._port)
redis = RedisBackend(self._host, self._port, self._username, self._password)
self._backend = redis if redis.is_init() else FilesystemBackend(self._root_dir)
return self._backend

Expand Down Expand Up @@ -53,5 +55,5 @@ def status_mgr(root_dir='.') -> StatusManager:
if _status is not None and _root_dir == root_dir:
return _status
_root_dir = root_dir
_status = StatusManager(host=os.environ.get('DPP_REDIS_HOST'), root_dir=root_dir)
_status = StatusManager(root_dir=root_dir)
return _status