diff --git a/docker/Dockerfile.bots b/docker/Dockerfile.bots index fc2ec693c..a989a105c 100644 --- a/docker/Dockerfile.bots +++ b/docker/Dockerfile.bots @@ -1,4 +1,4 @@ -FROM python:3.7-alpine3.14 AS build_shared +FROM python:3.12-alpine3.18 AS build_shared WORKDIR /build_shared/ @@ -8,7 +8,7 @@ RUN python -m build -FROM python:3.7-alpine3.14 AS production +FROM python:3.12-alpine3.18 AS production WORKDIR /app/ diff --git a/src/bots/managers/auth_manager.py b/src/bots/managers/auth_manager.py index c7d94a288..24b59d938 100644 --- a/src/bots/managers/auth_manager.py +++ b/src/bots/managers/auth_manager.py @@ -1,11 +1,16 @@ +"""Authorization manager for the API. + +Returns: + wrapper: Wrapper function for the API endpoints. +""" from functools import wraps from flask import request import os import ssl -api_key = os.getenv('API_KEY') +api_key = os.getenv("API_KEY") -if os.getenv('SSL_VERIFICATION') == "False": +if os.getenv("SSL_VERIFICATION") == "False": try: _create_unverified_https_context = ssl._create_unverified_context except AttributeError: @@ -15,11 +20,18 @@ def api_key_required(fn): + """Check for API key in the request header. + + Arguments: + fn -- The function to be decorated. + Returns: + wrapper: Wrapper function for the API endpoints. + """ + @wraps(fn) def wrapper(*args, **kwargs): - - if not request.headers.has_key('Authorization') or request.headers['Authorization'] != ('Bearer ' + api_key): - return {'error': 'not authorized'}, 401 + if "Authorization" not in request.headers.keys() or request.headers["Authorization"] != ("Bearer " + api_key): + return {"error": "not authorized"}, 401 else: return fn(*args, **kwargs) diff --git a/src/bots/requirements.txt b/src/bots/requirements.txt index 4139b7a7e..bc21d0327 100644 --- a/src/bots/requirements.txt +++ b/src/bots/requirements.txt @@ -1,26 +1,13 @@ -certifi==2019.11.28 -Flask==1.1.4 -Flask-Cors==3.0.10 -Flask-RESTful==0.3.7 -gevent==21.8.0 -greenlet==1.1.1 -gunicorn==20.0.4 -idna==2.8 -marshmallow==3.18.0 +Flask==3.0.0 +Flask-Cors==4.0.0 +Flask-RESTful==0.3.10 +gevent==23.9.1 +gunicorn==21.2.0 +marshmallow==3.20.1 marshmallow-enum==1.5.1 -Jinja2==2.11.3 -MarkupSafe==1.1.0 -oauthlib==3.1.0 +oauthlib==3.2.2 PySocks==1.7.1 -python-dateutil==2.8.1 -python-dotenv==0.10.5 -pytz==2019.3 -requests==2.26.0 -requests-oauthlib==1.3.0 -schedule==0.6.0 -six==1.14.0 -sseclient-py==1.7 -tweepy==3.8.0 -urllib3==1.26.7 -Werkzeug==0.16.0 -zipp==3.1.0 +python-dotenv==1.0.0 +requests==2.31.0 +schedule==1.2.1 +sseclient-py==1.8.0