From 5cabcf6de25359cafde9f1a26ea272cc16a66106 Mon Sep 17 00:00:00 2001 From: Daniil <94884910+Filienko@users.noreply.github.com> Date: Tue, 13 Aug 2024 17:24:28 -0700 Subject: [PATCH] Changing to new json producer --- jwt_proxy/api.py | 17 +++++++------- jwt_proxy/app.py | 3 --- requirements.dev.txt | 53 +++++++++++++++++++++++++++++++++++++++++--- requirements.txt | 12 +++++----- 4 files changed, 63 insertions(+), 22 deletions(-) diff --git a/jwt_proxy/api.py b/jwt_proxy/api.py index 4675554..a52e357 100644 --- a/jwt_proxy/api.py +++ b/jwt_proxy/api.py @@ -1,13 +1,20 @@ -from flask import Blueprint, abort, current_app, jsonify, request, json as flask_json +from flask import Blueprint, abort, current_app, jsonify, request import jwt import requests import json +from flask.json.provider import DefaultJSONProvider from jwt_proxy.audit import audit_HAPI_change blueprint = Blueprint('auth', __name__) SUPPORTED_METHODS = ('GET', 'POST', 'PUT', 'DELETE', 'OPTIONS') +# Workaround no JSON representation for datetime.timedelta +class CustomJSONProvider(DefaultJSONProvider): + @staticmethod + def default(obj): + return str(obj) + def proxy_request(req, upstream_url, user_info=None): """Forward request to given url""" @@ -94,14 +101,6 @@ def smart_configuration(): @blueprint.route("/settings/") def config_settings(config_key): """Non-secret application settings""" - - # workaround no JSON representation for datetime.timedelta - class CustomJSONEncoder(flask_json.JSONEncoder): - def default(self, obj): - return str(obj) - - current_app.json_encoder = CustomJSONEncoder - # return selective keys - not all can be be viewed by users, e.g.secret key blacklist = ("SECRET", "KEY") diff --git a/jwt_proxy/app.py b/jwt_proxy/app.py index 6a428c6..aabb280 100644 --- a/jwt_proxy/app.py +++ b/jwt_proxy/app.py @@ -5,13 +5,11 @@ from jwt_proxy import api from jwt_proxy.audit import audit_log_init, audit_entry - def create_app(testing=False, cli=False): """Application factory, used to create application""" app = Flask("jwt_proxy") register_blueprints(app) configure_app(app) - return app @@ -22,7 +20,6 @@ def register_blueprints(app): def configure_app(app): """Load successive configs - overriding defaults""" - app.config.from_object("jwt_proxy.config") configure_logging(app) diff --git a/requirements.dev.txt b/requirements.dev.txt index cd43029..ef6d295 100644 --- a/requirements.dev.txt +++ b/requirements.dev.txt @@ -4,11 +4,24 @@ # # pip-compile # ---requirement requirements.txt +blinker==1.8.2 + # via flask cachetools==5.4.0 # via tox +certifi==2024.7.4 + # via requests +cffi==1.17.0 + # via cryptography +chardet==5.2.0 + # via tox +charset-normalizer==3.3.2 + # via requests +click==8.1.7 + # via flask colorama==0.4.6 # via tox +cryptography==43.0.0 + # via pyjwt distlib==0.3.8 # via virtualenv exceptiongroup==1.2.2 @@ -17,8 +30,30 @@ filelock==3.15.4 # via # tox # virtualenv +flask==3.0.3 + # via jwt_proxy (setup.cfg) +gunicorn==22.0.0 + # via jwt_proxy (setup.cfg) +idna==3.7 + # via requests +importlib-metadata==8.2.0 + # via flask iniconfig==2.0.0 # via pytest +itsdangerous==2.2.0 + # via flask +jinja2==3.1.4 + # via flask +markupsafe==2.1.5 + # via + # jinja2 + # werkzeug +packaging==24.1 + # via + # gunicorn + # pyproject-api + # pytest + # tox platformdirs==4.2.2 # via # tox @@ -27,16 +62,28 @@ pluggy==1.5.0 # via # pytest # tox +pycparser==2.22 + # via cffi +pyjwt[crypto]==2.9.0 + # via jwt_proxy (setup.cfg) pyproject-api==1.7.1 # via tox pytest==8.3.2 # via jwt_proxy (setup.cfg) +requests==2.32.3 + # via jwt_proxy (setup.cfg) tomli==2.0.1 # via # pyproject-api # pytest # tox -tox==4.16.0 +tox==4.17.1 # via jwt_proxy (setup.cfg) +urllib3==2.2.2 + # via requests virtualenv==20.26.3 - # via tox \ No newline at end of file + # via tox +werkzeug==3.0.3 + # via flask +zipp==3.19.2 + # via importlib-metadata \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 0eb3e52..94edfa9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,7 +8,7 @@ blinker==1.8.2 # via flask certifi==2024.7.4 # via requests -cffi==1.16.0 +cffi==1.17.0 # via cryptography charset-normalizer==3.3.2 # via requests @@ -16,7 +16,7 @@ click==8.1.7 # via flask cryptography==43.0.0 # via pyjwt -flask==2.0.1 +flask==3.0.3 # via jwt_proxy (setup.cfg) gunicorn==22.0.0 # via jwt_proxy (setup.cfg) @@ -24,7 +24,7 @@ idna==3.7 # via requests importlib-metadata==8.2.0 # via flask -itsdangerous==2.0.1 +itsdangerous==2.2.0 # via flask jinja2==3.1.4 # via flask @@ -36,15 +36,13 @@ packaging==24.1 # via gunicorn pycparser==2.22 # via cffi -python-json-logger==2.0.7 - # via jwt_proxy (setup.cfg) -pyjwt[crypto]==2.8.0 +pyjwt[crypto]==2.9.0 # via jwt_proxy (setup.cfg) requests==2.32.3 # via jwt_proxy (setup.cfg) urllib3==2.2.2 # via requests -werkzeug==2.0.1 +werkzeug==3.0.3 # via flask zipp==3.19.2 # via importlib-metadata \ No newline at end of file