From 70c457106743babe772616a38367c0336f4e198e Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Fri, 14 Oct 2022 13:27:34 -0400 Subject: [PATCH] Add --req-limit-storage redis support --- README.md | 1 + app/app.py | 1 + app/default_values.py | 5 +++++ app/main.py | 7 +++++++ requirements.txt | 1 + 5 files changed, 15 insertions(+) diff --git a/README.md b/README.md index f7be817..56dd5fa 100644 --- a/README.md +++ b/README.md @@ -184,6 +184,7 @@ docker-compose -f docker-compose.cuda.yml up -d --build | --port | Set port to bind the server to | `5000` | LT_PORT | | --char-limit | Set character limit | `No limit` | LT_CHAR_LIMIT | | --req-limit | Set maximum number of requests per minute per client | `No limit` | LT_REQ_LIMIT | +| --req-limit-storage | Storage URI to use for request limit data storage. See [Flask Limiter](https://flask-limiter.readthedocs.io/en/stable/configuration.html) | `memory://` | LT_REQ_STORAGE | | --batch-limit | Set maximum number of texts to translate in a batch request | `No limit` | LT_BATCH_LIMIT | | --ga-id | Enable Google Analytics on the API client page by providing an ID | `No tracking` | LT_GA_ID | | --debug | Enable debug environment | `False` | LT_DEBUG | diff --git a/app/app.py b/app/app.py index e3ef13b..d58adbc 100644 --- a/app/app.py +++ b/app/app.py @@ -161,6 +161,7 @@ def create_app(args): default_limits=get_routes_limits( args.req_limit, args.daily_req_limit, api_keys_db ), + storage_uri=args.req_limit_storage, ) else: from .no_limiter import Limiter diff --git a/app/default_values.py b/app/default_values.py index 88a32ef..343f22c 100644 --- a/app/default_values.py +++ b/app/default_values.py @@ -56,6 +56,11 @@ _default_options_objects = [ 'default_value': -1, 'value_type': 'int' }, + { + 'name': 'REQ_LIMIT_STORAGE', + 'default_value': 'memory://', + 'value_type': 'str' + }, { 'name': 'DAILY_REQ_LIMIT', 'default_value': -1, diff --git a/app/main.py b/app/main.py index 0df79fb..6e24158 100644 --- a/app/main.py +++ b/app/main.py @@ -28,6 +28,13 @@ def get_args(): metavar="", help="Set the default maximum number of requests per minute per client (%(default)s)", ) + parser.add_argument( + "--req-limit-storage", + default=DEFARGS['REQ_LIMIT_STORAGE'], + type=str, + metavar="", + help="Storage URI to use for request limit data storage. See https://flask-limiter.readthedocs.io/en/stable/configuration.html. (%(default)s)", + ) parser.add_argument( "--daily-req-limit", default=DEFARGS['DAILY_REQ_LIMIT'], diff --git a/requirements.txt b/requirements.txt index b52b177..39a300f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -16,3 +16,4 @@ argos-translate-files==1.1.0 itsdangerous==2.1.2 Werkzeug==2.2.2 requests==2.28.1 +redis==4.3.4