Skip to content

Commit 0424537

Browse files
committed
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 pinterest#369
1 parent 95b7573 commit 0424537

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

README.rst

+7-5
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ need to change this.
8888

8989
``REDIS_PORT``: is the port redis is serving on, defaults to 6379
9090

91+
``REDIS_PASSWORD``: in certain environments authtentication may be a requirement. Defaults to ``"None"``
92+
9193
``SNAPPASS_REDIS_DB``: is the database that you want to use on this redis server. Defaults to db 0
9294

9395
``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/<token
197199
$ curl --head http://localhost:5000/api/v2/passwords/snappassbedf19b161794fd288faec3eba15fa41~hHnILpQ50ZfJc3nurDfHCb_22rBr5gGEya68e_cZOrY%3D
198200

199201
If :
200-
- the passwork_key is valid
202+
- the passwork_key is valid
201203
- the password :
202204
- exists,
203-
- has not been read
205+
- has not been read
204206
- is not expired
205207

206208
Then the API will return a 200 (OK) response like so:
@@ -224,7 +226,7 @@ Otherwise, the API will return a 404 (Not Found) response like so:
224226
Content-Type: text/html; charset=utf-8
225227
Content-Length: 0
226228
Connection: close
227-
229+
228230

229231
Read a password
230232
"""""""""""""""
@@ -236,10 +238,10 @@ To read a password, send a GET request to ``/api/v2/passwords/<password_key>``,
236238
$ curl -X GET http://localhost:5000/api/v2/passwords/snappassbedf19b161794fd288faec3eba15fa41~hHnILpQ50ZfJc3nurDfHCb_22rBr5gGEya68e_cZOrY%3D
237239

238240
If :
239-
- the token is valid
241+
- the token is valid
240242
- the password :
241243
- exists
242-
- has not been read
244+
- has not been read
243245
- is not expired
244246

245247
Then the API will return a 200 (OK) with a JSON response containing the password :

snappass/main.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ def get_locale():
4444
else:
4545
redis_host = os.environ.get('REDIS_HOST', 'localhost')
4646
redis_port = os.environ.get('REDIS_PORT', 6379)
47+
redis_password = os.environ.get('REDIS_PASSWORD', 'None')
4748
redis_db = os.environ.get('SNAPPASS_REDIS_DB', 0)
4849
redis_client = redis.StrictRedis(
49-
host=redis_host, port=redis_port, db=redis_db)
50+
host=redis_host, port=redis_port, db=redis_db, password=redis_password)
5051
REDIS_PREFIX = os.environ.get('REDIS_PREFIX', 'snappass')
5152

5253
TIME_CONVERSION = {'two weeks': 1209600, 'week': 604800, 'day': 86400,

0 commit comments

Comments
 (0)