Commit b6419729 authored by David Mendez's avatar David Mendez
Browse files

Set initial default limit for all routes in rate limiter

parent ce700e91
......@@ -3,8 +3,6 @@ Entry file for the delayed jobs app
"""
from flask import Flask
from flask_cors import CORS
from flask_limiter import Limiter
from flask_limiter.util import get_remote_address
from app.blueprints.admin.controllers.admin_tasks_controller import ADMIN_TASKS_BLUEPRINT
from app.blueprints.admin.controllers.authorisation_controller import ADMIN_AUTH_BLUEPRINT
......@@ -17,6 +15,7 @@ from app.config import RunEnvs
from app.db import DB
from app.models import delayed_job_models
from app.cache import CACHE
from app.rate_limiter import RATE_LIMITER
def create_app():
"""
......@@ -43,8 +42,7 @@ def create_app():
with flask_app.app_context():
DB.init_app(flask_app)
CACHE.init_app(flask_app)
RATE_LIMITER.init_app(flask_app)
create_tables = RUN_CONFIG.get('sql_alchemy').get('create_tables', False)
if create_tables:
......
......@@ -3,11 +3,10 @@ Blueprint in charge of sending the swagger configuration in json format.
"""
from pathlib import Path
from flask import Blueprint, jsonify, request
from flask import Blueprint, jsonify
import yaml
from app.config import RUN_CONFIG
from app import app_logging
SWAGGER_BLUEPRINT = Blueprint('swagger', __name__)
......@@ -16,9 +15,6 @@ def get_json():
yaml_file_path = Path(Path().absolute()).joinpath('app', 'swagger', 'swagger.yaml')
forwarded_for_value = request.headers.get('X-Forwarded-For')
app_logging.info(f'forwarded_for_value: {forwarded_for_value}')
with open(yaml_file_path, 'r') as stream:
swagger_desc = yaml.safe_load(stream)
swagger_desc['host'] = RUN_CONFIG.get('server_public_host')
......
......@@ -2,9 +2,11 @@
Module that defines the instance of the rate limiter
"""
from flask_limiter import Limiter
from flask_limiter.util import get_remote_address
from flask_limiter.util import get_ipaddr
PER_SECOND = 2
RATE_LIMITER = Limiter(
key_func=get_remote_address,
default_limits=["200 per day", "50 per hour"]
key_func=get_ipaddr,
default_limits=[f'{PER_SECOND*60*60*24} per day', f'{PER_SECOND*60*60} per hour']
)
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment