Skip to content

Commit 8736bb0

Browse files
committed
Added banned ip blocking
1 parent d59bb8d commit 8736bb0

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

app/v2/blueprint.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11

22
import logging
3-
import os
43
import traceback
54
import pandas as pd
5+
import os
66

77
import geoglows
8-
from flask import Blueprint, request, jsonify, abort
8+
from flask import Blueprint, request, jsonify
99
from flask_cors import cross_origin
1010

11+
1112
from .analytics import log_request
1213
from .controllers_forecasts import (forecast,
1314
forecast_stats,
@@ -23,18 +24,17 @@
2324
yearly_averages,
2425
return_periods)
2526
from .controllers_misc import get_river_id
26-
from datetime import datetime
2727

2828
logger = logging.getLogger("DEBUG")
2929

3030
app = Blueprint('rest-endpoints-v2', __name__)
3131

3232
BANNED_IPS = {
33-
ip.strip() for ip in os.getenv("BANNED_IPS", "").split(",") if ip.strip()
33+
ip.strip().strip("'").strip('"') for ip in os.getenv("BANNED_IPS", "").split(",") if ip.strip()
3434
}
3535

3636
@app.before_app_request
37-
def block_bad_ips():
37+
def block_banned_ips():
3838
if not BANNED_IPS:
3939
return
4040

@@ -44,7 +44,8 @@ def block_bad_ips():
4444

4545
if ip in BANNED_IPS:
4646
logger.warning(f"Blocked banned IP: {ip}")
47-
return jsonify({"error": "Access denied", "message": "Access to this service has been restricted for your network. If you believe this is an error, please contact us at michael.souffront@geoglows.org."}), 403
47+
# TESTING ONLY
48+
return jsonify({"error": "Your IP address has been blocked from accessing this service."}), 403
4849

4950

5051
@app.route(f'/api/v2/<product>/', methods=['GET'])
@@ -80,7 +81,6 @@ def rest_endpoints_v2(product: str, river_id: int = None):
8081
year_difference = get_year_difference(start_date, end_date)
8182
if year_difference > 10:
8283
return jsonify({'error': f'Please limit the date range to 10 years or less.'}), 400
83-
8484

8585

8686
# forecast data products

0 commit comments

Comments
 (0)