Skip to content

Commit dd1e749

Browse files
Add support for connecting to redis server over SSL (#53)
* Add support for connecting to redis server over SSL Intention of this commit is to provide very basic support for connecting to redis server over SSL. It doesn't perform any kind of cert verification which means connection to redis server won't be secure. * Drop python 3.4 support
1 parent 6213bb6 commit dd1e749

File tree

6 files changed

+15
-8
lines changed

6 files changed

+15
-8
lines changed

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
language: python
22
python:
3-
- "3.4"
43
- "3.5"
4+
- "3.6"
5+
- "3.7"
6+
- "3.8"
57

68
script: python run_tests
79

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Installing rma
1717

1818
Pre-Requisites :
1919

20-
1. python >= 3.4 and pip.
20+
1. python >= 3.5 and pip.
2121
2. redis-py.
2222

2323
To install from PyPI (recommended) :

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
redis==2.10.5
1+
redis==3.4.1
22
tabulate==0.7.5
33
tqdm==3.7.1
44
msgpack-python==0.4.7

rma/application.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def ptransform(nm):
3434
return rt
3535

3636

37-
def connect_to_redis(host, port, db=0, password=None):
37+
def connect_to_redis(host, port, db=0, password=None, ssl=False):
3838
"""
3939
4040
:param host:
@@ -44,7 +44,7 @@ def connect_to_redis(host, port, db=0, password=None):
4444
:return RmaRedis:
4545
"""
4646
try:
47-
redis = RmaRedis(host=host, port=port, db=db, password=password)
47+
redis = RmaRedis(host=host, port=port, db=db, password=password, ssl=ssl)
4848
if not check_redis_version(redis):
4949
sys.stderr.write('This script only works with Redis Server version 2.6.x or higher\n')
5050
sys.exit(-1)
@@ -79,13 +79,13 @@ class RmaApplication(object):
7979
REDIS_TYPE_ID_ZSET: [],
8080
}
8181

82-
def __init__(self, host="127.0.0.1", port=6367, password=None, db=0, match="*", limit=0, filters=None, logger=None, format="text", separator=":"):
82+
def __init__(self, host="127.0.0.1", port=6367, password=None, db=0, ssl=False, match="*", limit=0, filters=None, logger=None, format="text", separator=":"):
8383
self.logger = logger or logging.getLogger(__name__)
8484

8585
self.splitter = SimpleSplitter(separator)
8686
self.isTextFormat = format == "text"
8787
self.reporter = TextReporter() if self.isTextFormat else JsonReporter()
88-
self.redis = connect_to_redis(host=host, port=port, db=db, password=password)
88+
self.redis = connect_to_redis(host=host, port=port, db=db, password=password, ssl=ssl)
8989

9090
self.match = match
9191
self.limit = limit if limit != 0 else sys.maxsize

rma/cli/rma_cli.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ def main():
5050
dest="db",
5151
default=0,
5252
help="Database number, defaults to 0")
53+
parser.add_argument("--ssl",
54+
dest="ssl",
55+
action="store_true",
56+
help="If argument is specified, SSL will be used for making connection")
5357
parser.add_argument("-m", "--match",
5458
dest="match",
5559
default="*",
@@ -98,7 +102,7 @@ def main():
98102
filters['types'].append(x)
99103

100104
app = RmaApplication(host=options.host, port=options.port, db=options.db, password=options.password,
101-
match=options.match, limit=options.limit, filters=filters, format=options.format,
105+
ssl=options.ssl, match=options.match, limit=options.limit, filters=filters, format=options.format,
102106
separator=options.separator)
103107

104108
start_time = time_clock()

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
install_requires=['redis', 'tabulate', 'tqdm', 'msgpack-python'],
3232
include_package_data=True,
3333
packages=['rma', 'rma.helpers', 'rma.reporters', 'rma.rule', 'rma.cli'],
34+
python_requires='>3.5',
3435
package_data={
3536
'rma.cli': ['*.template']
3637
},

0 commit comments

Comments
 (0)