foca
foca copied to clipboard
Added custom flask app wrapper to consume foca as config
Description
A number of mypy errors were coming in since foca was not included as part of the flask config but was being consumed using the current app context and otherwise too. To fix the same, I created a custom wrapper to create a flask app with an underlying config attribute for foca. Thereby removing the mypy errors. However it was observed that while consuming the attribute from current_app context, still mypy errors were coming.
- The following resulted in attribute error from
mypy
foca_conf = current_app.config.foca
- But this one did not
foca_conf = current_app.app.config.foca
Further, to fix the same the following was used.
foca_conf = getattr(current_app.config, 'foca')
In addition, following are still being ignored from mypy
- celery_app.py
class ContextTask(celery.Task): # type: ignore
- auth.py
try:
claims = jwt.decode(
jwt=token,
verify=True,
key=key, # type: ignore[arg-type]
algorithms=algorithms,
audience=audience,
options=validation_options,
)
request.headers = \
ImmutableMultiDict(req_headers) # type: ignore[assignment]
- register_access_control.py
app.add_api(
specification=spec.path[0], # type: ignore[index]
**spec.dict().get("connexion", {}),
)
Fixes #144
Type of change
Please delete options that are not relevant.
- [x] Bug fix (non-breaking change which fixes an issue)
- [x] Breaking change (fix or feature that would cause existing functionality to not work as expected)
Checklist:
- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have updated the documentation (or documentation does not need to be updated)
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my feature works
- [x] New and existing unit tests pass locally with my changes
- [x] I have not reduced the existing code coverage