Skip to content

Commit

Permalink
Changing to new json producer
Browse files Browse the repository at this point in the history
  • Loading branch information
Filienko committed Aug 14, 2024
1 parent b3036c3 commit 5cabcf6
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 22 deletions.
17 changes: 8 additions & 9 deletions jwt_proxy/api.py
Original file line number Diff line number Diff line change
@@ -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"""
Expand Down Expand Up @@ -94,14 +101,6 @@ def smart_configuration():
@blueprint.route("/settings/<string:config_key>")
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")

Expand Down
3 changes: 0 additions & 3 deletions jwt_proxy/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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)

Expand Down
53 changes: 50 additions & 3 deletions requirements.dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
# via tox
werkzeug==3.0.3
# via flask
zipp==3.19.2
# via importlib-metadata
12 changes: 5 additions & 7 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ 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
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)
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
Expand All @@ -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

0 comments on commit 5cabcf6

Please sign in to comment.