Skip to content

Commit 6f3379e

Browse files
committed
Farewell Marktgasse
1 parent 1a85faa commit 6f3379e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+578
-286
lines changed

.idea/mrmat-python-api-flask.iml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/cui.xml

Lines changed: 0 additions & 25 deletions
This file was deleted.

.idea/runConfigurations/mrmat_python_api_flask__local_infrastructure_.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/mrmat_python_api_flask__no_infrastructure_.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/mrmat_python_api_flask__no_infrastructure__debug_.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,38 +30,37 @@ classifiers = [
3030
]
3131
requires-python = ">=3.10"
3232
dependencies = [
33-
"rich~=12.6.0",
34-
"Flask~=2.2.2",
35-
"Flask-SQLAlchemy~=3.0.2",
36-
"Flask-Migrate~=4.0.0",
37-
"flask-smorest~=0.40.0",
38-
"Flask-Marshmallow~=0.14.0",
39-
"marshmallow-sqlalchemy~=0.28.1",
40-
"psycopg2-binary~=2.9.5",
41-
"Flask-OIDC~=1.4.0"
33+
"Flask~=2.2.3", # BSD 3-Clause
34+
"Flask-SQLAlchemy~=3.0.3", # BSD 3-Clause
35+
"Flask-Migrate~=4.0.4", # MIT
36+
"flask-smorest~=0.40.0", # MIT
37+
"Flask-Marshmallow~=0.14.0", # MIT
38+
"marshmallow-sqlalchemy~=0.28.1", # MIT
39+
"psycopg2-binary~=2.9.5", # LGPL with exceptions
40+
"Flask-OIDC~=1.4.0", # MIT
41+
"itsdangerous<=2.0.1" # BSD 3-Clause Must affix so JSONWebSignatureSerializer is known
4242
]
4343
dynamic = ["version"]
4444

4545
[tool.setuptools.dynamic]
4646
version = { attr = "ci.version "}
4747

4848
[tool.setuptools.packages.find]
49-
where = ["src/python"]
49+
where = ["src"]
5050
include = ["mrmat_python_api_flask*"]
5151
namespaces = true
5252

5353
[tool.setuptools.package-data]
5454
"*" = ["*.mo", "migrations/*", "templates/*", "static/*"]
5555

5656
[project.scripts]
57-
mrmat-python-api-flask = "mrmat_python_api_flask.cui:main"
5857
mrmat-python-api-flask-client = "mrmat_python_api_flask.client:main"
5958

6059
# If you are debugging your tests using PyCharm then comment out the coverage options
6160
# in addopts
6261
[tool.pytest.ini_options]
6362
minversion = "6.0"
64-
addopts = "--cov=mrmat_python_api_flask --cov-report=term --cov-report=xml:build/coverage.xml --junit-xml=build/junit.xml"
63+
#addopts = "--cov=mrmat_python_api_flask --cov-report=term --cov-report=xml:build/coverage.xml --junit-xml=build/junit.xml"
6564
testpaths = ["tests"]
6665
junit_family = "xunit2"
6766
log_cli = 1

requirements.txt

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,22 @@
66
# Build/Test requirements
77

88
setuptools>=42.0.0
9-
build>=0.9.0 # MIT
10-
wheel>=0.36.0 # MIT
11-
pylint~=2.15.5 # MIT
12-
pytest~=7.2.0 # GPL-2.0-or-later
9+
build>=0.10.0 # MIT
10+
wheel>=0.38.4 # MIT
11+
pylint~=2.15.10 # MIT
12+
pytest~=7.2.1 # GPL-2.0-or-later
1313
pytest-cov~=4.0.0 # MIT
1414
pyjwt~=2.6.0 # MIT
15-
python-keycloak~=2.6.0 # MIT
15+
python-keycloak~=2.6.1 # MIT
1616

1717
# Runtime requirements
1818

19-
rich~=12.6.0 # MIT
20-
Flask~=2.2.2 # BSD 3-Clause
21-
Flask-SQLAlchemy~=3.0.2 # BSD 3-Clause
22-
Flask-Migrate~=4.0.0 # MIT
19+
Flask~=2.2.3 # BSD 3-Clause
20+
Flask-SQLAlchemy~=3.0.3 # BSD 3-Clause
21+
Flask-Migrate~=4.0.4 # MIT
2322
flask-smorest~=0.40.0 # MIT
2423
Flask-Marshmallow~=0.14.0 # MIT
2524
marshmallow-sqlalchemy~=0.28.1 # MIT
2625
psycopg2-binary~=2.9.5 # LGPL with exceptions
2726
Flask-OIDC~=1.4.0 # MIT
28-
29-
# Do we need these?
30-
#requests_oauthlib~=1.3.1 # ISC
3127
itsdangerous<=2.0.1 # BSD 3-Clause Must affix so JSONWebSignatureSerializer is known

src/python/mrmat_python_api_flask/__init__.py renamed to src/mrmat_python_api_flask/__init__.py

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,8 @@
3535
from flask_sqlalchemy import SQLAlchemy
3636
from flask_migrate import Migrate
3737
from flask_marshmallow import Marshmallow
38-
from flask_oidc import OpenIDConnect
3938
from flask_smorest import Api
40-
41-
log = logging.getLogger(__name__)
39+
from authlib.integrations.flask_client import OAuth
4240

4341
#
4442
# Establish consistent logging
@@ -51,15 +49,16 @@
5149
except importlib.metadata.PackageNotFoundError:
5250
# You have not yet installed this as a package, likely because you're hacking on it in some IDE
5351
__version__ = '0.0.0.dev0'
52+
__app_version_header__ = 'X-MrMat-Python-API-Flask-Version'
5453

5554
#
5655
# Initialize supporting services
5756

5857
db = SQLAlchemy()
5958
ma = Marshmallow()
6059
migrate = Migrate()
61-
oidc = OpenIDConnect()
6260
api = Api()
61+
oauth = OAuth()
6362

6463

6564
def create_app(config_override=None, instance_path=None):
@@ -93,55 +92,59 @@ def create_app(config_override=None, instance_path=None):
9392
app.config.setdefault('OPENAPI_JSON_PATH', '/openapi.json')
9493
app.config.setdefault('OPENAPI_SWAGGER_UI_PATH', '/swagger-ui')
9594
app.config.setdefault('OPENAPI_SWAGGER_UI_URL', 'https://cdn.jsdelivr.net/npm/[email protected]/')
96-
app_config_file = os.path.expanduser(os.environ.get('APP_CONFIG', '~/etc/mrmat-python-api-flask.json'))
95+
app_config_file = os.environ.get('APP_CONFIG', os.path.expanduser('~/etc/mrmat-python-api-flask.json'))
9796
if os.path.exists(app_config_file):
98-
log.info('Applying configuration from %s', app_config_file)
97+
app.logger.info('Applying configuration from %s', app_config_file)
9998
with open(app_config_file, 'r', encoding='UTF-8') as c:
10099
config = json.load(c)
101100
app.config.from_object(config)
102-
#app.config.from_json(app_config_file)
103101
if config_override is not None:
104102
for override in config_override:
105-
log.info('Overriding configuration for %s from the command line', override)
103+
app.logger.info('Overriding configuration for %s from the command line', override)
106104
app.config.from_mapping(config_override)
107105
if app.config['SECRET_KEY'] is None:
108-
log.warning('Generating new secret key')
106+
app.logger.warning('Generating new secret key')
109107
app.config['SECRET_KEY'] = secrets.token_urlsafe(16)
110108

111109
#
112110
# Create the instance folder if it does not exist
113111

114112
try:
115113
if not os.path.exists(app.instance_path):
116-
log.info('Creating new instance path at %s', app.instance_path)
114+
app.logger.info('Creating new instance path at %s', app.instance_path)
117115
os.makedirs(app.instance_path)
118116
else:
119-
log.info('Using existing instance path at %s', app.instance_path)
117+
app.logger.info('Using existing instance path at %s', app.instance_path)
120118
except OSError:
121-
log.error('Failed to create new instance path at %s', app.instance_path)
119+
app.logger.error('Failed to create new instance path at %s', app.instance_path)
122120
sys.exit(1)
123121

124-
# When using Flask-SQLAlchemy, there is no need to explicitly import DAO classes because they themselves
125-
# inherit from the SQLAlchemy model
122+
# There is no need to explicitly load DAO classes here because they inherit from the SQLAlchemy model
126123

127124
db.init_app(app)
128125
migrate.init_app(app, db)
129126
ma.init_app(app)
130127
api.init_app(app)
131-
if 'OIDC_CLIENT_SECRETS' in app.config.keys():
132-
oidc.init_app(app)
133-
else:
134-
log.warning('Running without any authentication/authorisation')
128+
oauth.init_app(app)
129+
oauth.register(name='mrmat',
130+
server_metadata_url='http://localhost:5001/.well-known/openid-configuration',
131+
client_kwargs={'scope':'openid email profile'})
132+
# if 'OIDC_CLIENT_SECRETS' in app.config.keys():
133+
# oauth.init_app(app)
134+
# oauth.register(name='mrmat',
135+
# server_metadata_url='http://localhost:5001/.well-known/openid-configuration',
136+
# client_kwargs={'scope':'openid email profile'})
137+
# else:
138+
# app.logger.warning('Running without any authentication/authorisation')
135139

136140
#
137-
# Security Schemes
141+
# Set Security Schemes in the generated OpenAPI descriptor
138142

139-
api.spec.components.security_scheme('openId', dict(
140-
type='openIdConnect',
141-
description='MrMat OIDC',
142-
openIdConnectUrl='http://localhost:8080/auth/realms/master'
143-
'/.well-known/openid-configuration'
144-
))
143+
# api.spec.components.security_scheme('openId',
144+
# {'type': 'openIdConnect',
145+
# 'description': 'MrMat OIDC',
146+
# 'openIdConnectUrl': 'http://localhost:8080/auth/realms/master/.well-known'
147+
# '/openid-configuration'})
145148

146149
#
147150
# Import and register our APIs here
@@ -163,8 +166,8 @@ def create_app(config_override=None, instance_path=None):
163166

164167
@app.after_request
165168
def after_request(response: flask.Response) -> flask.Response:
166-
log.info('[%s]', response.status_code)
167-
response.headers.add('X-MrMat-Python-API-Flask-Version', __version__)
169+
app.logger.info('[%s]', response.status_code)
170+
response.headers.add(__app_version_header__, __version__)
168171
return response
169172

170173
return app
File renamed without changes.

0 commit comments

Comments
 (0)