Skip to content

Commit

Permalink
Add support for connecting to redis server over SSL (#53)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Ashish-Bansal authored Jun 8, 2020
1 parent 6213bb6 commit dd1e749
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 8 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
language: python
python:
- "3.4"
- "3.5"
- "3.6"
- "3.7"
- "3.8"

script: python run_tests

2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Installing rma

Pre-Requisites :

1. python >= 3.4 and pip.
1. python >= 3.5 and pip.
2. redis-py.

To install from PyPI (recommended) :
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
redis==2.10.5
redis==3.4.1
tabulate==0.7.5
tqdm==3.7.1
msgpack-python==0.4.7
8 changes: 4 additions & 4 deletions rma/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def ptransform(nm):
return rt


def connect_to_redis(host, port, db=0, password=None):
def connect_to_redis(host, port, db=0, password=None, ssl=False):
"""
:param host:
Expand All @@ -44,7 +44,7 @@ def connect_to_redis(host, port, db=0, password=None):
:return RmaRedis:
"""
try:
redis = RmaRedis(host=host, port=port, db=db, password=password)
redis = RmaRedis(host=host, port=port, db=db, password=password, ssl=ssl)
if not check_redis_version(redis):
sys.stderr.write('This script only works with Redis Server version 2.6.x or higher\n')
sys.exit(-1)
Expand Down Expand Up @@ -79,13 +79,13 @@ class RmaApplication(object):
REDIS_TYPE_ID_ZSET: [],
}

def __init__(self, host="127.0.0.1", port=6367, password=None, db=0, match="*", limit=0, filters=None, logger=None, format="text", separator=":"):
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=":"):
self.logger = logger or logging.getLogger(__name__)

self.splitter = SimpleSplitter(separator)
self.isTextFormat = format == "text"
self.reporter = TextReporter() if self.isTextFormat else JsonReporter()
self.redis = connect_to_redis(host=host, port=port, db=db, password=password)
self.redis = connect_to_redis(host=host, port=port, db=db, password=password, ssl=ssl)

self.match = match
self.limit = limit if limit != 0 else sys.maxsize
Expand Down
6 changes: 5 additions & 1 deletion rma/cli/rma_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ def main():
dest="db",
default=0,
help="Database number, defaults to 0")
parser.add_argument("--ssl",
dest="ssl",
action="store_true",
help="If argument is specified, SSL will be used for making connection")
parser.add_argument("-m", "--match",
dest="match",
default="*",
Expand Down Expand Up @@ -98,7 +102,7 @@ def main():
filters['types'].append(x)

app = RmaApplication(host=options.host, port=options.port, db=options.db, password=options.password,
match=options.match, limit=options.limit, filters=filters, format=options.format,
ssl=options.ssl, match=options.match, limit=options.limit, filters=filters, format=options.format,
separator=options.separator)

start_time = time_clock()
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
install_requires=['redis', 'tabulate', 'tqdm', 'msgpack-python'],
include_package_data=True,
packages=['rma', 'rma.helpers', 'rma.reporters', 'rma.rule', 'rma.cli'],
python_requires='>3.5',
package_data={
'rma.cli': ['*.template']
},
Expand Down

0 comments on commit dd1e749

Please sign in to comment.