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

Start to add rate limiter, test value of X-Forwarded-For

parent ef5259fe
......@@ -3,6 +3,8 @@ 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
......@@ -42,6 +44,8 @@ def create_app():
DB.init_app(flask_app)
CACHE.init_app(flask_app)
create_tables = RUN_CONFIG.get('sql_alchemy').get('create_tables', False)
if create_tables:
DB.create_all()
......
......@@ -3,10 +3,11 @@ Blueprint in charge of sending the swagger configuration in json format.
"""
from pathlib import Path
from flask import Blueprint, jsonify
from flask import Blueprint, jsonify, request
import yaml
from app.config import RUN_CONFIG
from app import app_logging
SWAGGER_BLUEPRINT = Blueprint('swagger', __name__)
......@@ -15,6 +16,9 @@ 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('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')
......
"""
Module that defines the instance of the rate limiter
"""
from flask_limiter import Limiter
from flask_limiter.util import get_remote_address
RATE_LIMITER = Limiter(
key_func=get_remote_address,
default_limits=["200 per day", "50 per hour"]
)
\ No newline at end of file
......@@ -11,4 +11,5 @@ mysqlclient==1.4.2.post1
flask-cors==3.0.8
marshmallow==3.5.0
Flask-Caching==1.8.0
pylibmc==1.6.1
\ No newline at end of file
pylibmc==1.6.1
Flask-Limiter==1.2.1 l
\ 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