From 0424537bd12083cadf9f2542b6f5b18f10688971 Mon Sep 17 00:00:00 2001 From: Michael Rolli Date: Wed, 12 Jun 2024 09:07:10 +0200 Subject: [PATCH] feat: add env var REDIS_PASSWORD This change allows to set a password without the need to build up a REDIS_URL environment variable. Fixes #369 --- README.rst | 12 +++++++----- snappass/main.py | 3 ++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/README.rst b/README.rst index 6e98da75..95e5a071 100644 --- a/README.rst +++ b/README.rst @@ -88,6 +88,8 @@ need to change this. ``REDIS_PORT``: is the port redis is serving on, defaults to 6379 +``REDIS_PASSWORD``: in certain environments authtentication may be a requirement. Defaults to ``"None"`` + ``SNAPPASS_REDIS_DB``: is the database that you want to use on this redis server. Defaults to db 0 ``REDIS_URL``: (optional) will be used instead of ``REDIS_HOST``, ``REDIS_PORT``, and ``SNAPPASS_REDIS_DB`` to configure the Redis client object. For example: redis://username:password@localhost:6379/0 @@ -197,10 +199,10 @@ To check if a password exists, send a HEAD request to ``/api/v2/passwords/``, $ curl -X GET http://localhost:5000/api/v2/passwords/snappassbedf19b161794fd288faec3eba15fa41~hHnILpQ50ZfJc3nurDfHCb_22rBr5gGEya68e_cZOrY%3D If : -- the token is valid +- the token is valid - the password : - exists - - has not been read + - has not been read - is not expired Then the API will return a 200 (OK) with a JSON response containing the password : diff --git a/snappass/main.py b/snappass/main.py index 6f06572e..4bf9cafc 100644 --- a/snappass/main.py +++ b/snappass/main.py @@ -44,9 +44,10 @@ def get_locale(): else: redis_host = os.environ.get('REDIS_HOST', 'localhost') redis_port = os.environ.get('REDIS_PORT', 6379) + redis_password = os.environ.get('REDIS_PASSWORD', 'None') redis_db = os.environ.get('SNAPPASS_REDIS_DB', 0) redis_client = redis.StrictRedis( - host=redis_host, port=redis_port, db=redis_db) + host=redis_host, port=redis_port, db=redis_db, password=redis_password) REDIS_PREFIX = os.environ.get('REDIS_PREFIX', 'snappass') TIME_CONVERSION = {'two weeks': 1209600, 'week': 604800, 'day': 86400,