Skip to content

Commit

Permalink
Use password from redis+sentinel uri
Browse files Browse the repository at this point in the history
If a password is provided in the redis+sentinel uri
pass it on to the Sentinel object.
  • Loading branch information
alisaifee committed Dec 18, 2015
1 parent 3151af3 commit 8b712df
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 6 additions & 2 deletions limits/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,10 @@ def __init__(self, uri, **options):

parsed = urllib.parse.urlparse(uri)
sentinel_configuration = []
for loc in parsed.netloc.split(","):
password = None
if parsed.password:
password = parsed.password
for loc in parsed.netloc[parsed.netloc.find("@")+1:].split(","):
host, port = loc.split(":")
sentinel_configuration.append((host, int(port)))
self.service_name = (
Expand All @@ -408,7 +411,8 @@ def __init__(self, uri, **options):
raise ConfigurationError("'service_name' not provided")
self.sentinel = get_dependency("redis.sentinel").Sentinel(
sentinel_configuration,
socket_timeout=options.get("socket_timeout", 0.2)
socket_timeout=options.get("socket_timeout", 0.2),
password=password
)
self.initialize_storage()
super(RedisSentinelStorage, self).__init__()
Expand Down
4 changes: 4 additions & 0 deletions tests/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from uuid import uuid4

import hiro
import mock
import redis
import redis.lock
from redis.sentinel import Sentinel
Expand All @@ -31,6 +32,9 @@ def test_storage_string(self):
self.assertTrue(isinstance(storage_from_string("redis+sentinel://localhost:26379/localhost-redis-sentinel"), RedisSentinelStorage))
self.assertRaises(ConfigurationError, storage_from_string, "blah://")
self.assertRaises(ConfigurationError, storage_from_string, "redis+sentinel://localhost:26379")
with mock.patch("limits.storage.get_dependency") as get_dependency:
self.assertTrue(isinstance(storage_from_string("redis+sentinel://:foobared@localhost:26379/localhost-redis-sentinel"), RedisSentinelStorage))
self.assertEqual(get_dependency().Sentinel.call_args[1]['password'], 'foobared')

def test_storage_check(self):
self.assertTrue(storage_from_string("memory://").check())
Expand Down

0 comments on commit 8b712df

Please sign in to comment.