-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: plugins/middleware/hooks #65
Comments
Good stuff, thanks a lot. Recently, I was looking into upgrading FOCA from Connexion 2 to Connexion 3 (https://connexion.readthedocs.io/en/latest/v3.html#migrating-from-connexion-2), and I stumbled across a possible alternative. Connexion 3 is a major rewrite that is built on Starlette (instead of Flask) to migrate from WSGI to ASGI (though Flask is still supported via some WSGI-to-ASGI compatibility layer). Importantly, Connexion 3 now applies basically all its functionalities via a Starlette-based middleware stack: https://www.starlette.io/middleware/ So, given that FOCA is underlying basically all of our services and we are planning to migrate to Connexion 3 as soon as I manage to put in the time to do so (I had already started and finished the first migration to about 75% when the summer break hit me), we could also consider making use of Starlette middlwares. Advantages:
Disadvantages:
I've put "highly generic" as both an advantage and disadvantage, because having a bit of structure might make development easier, or at least more consistent. However, a pre-defined structure can also make things more restrictive, especially because we can't foresee all use cases yet. I guess what we really need to focus on is the design of a mechanism that checks when (and when not) a middleware applies. That way we don't need to write different methods for different operations, but rather include all middlewares in the stack and just make sure that each one only runs if the right conditions are met. |
@uniqueg I agree that a pre-defined framework would be the better option. The main weakness with my proposal is that there's currently one 1 example, and a custom framework risks being premature.
Yes! We can use the intervening time (until the migration to connexion 3 is complete) to figure this out. |
Following the example of proTES, it would be useful to have a plugin/middleware/hooks system to provide additional functionality to DRS-filer, or to modify existing behaviour. Such extra functionality could e.g. include support for crypt4gh (as implemented in a plugin-less way in pa-DRS-Crypt4GH-PoC).
This is a first, rough design document to describe such a plugin system. Caveat: I only know of one realistic example of a plugin so far (offering support for Crypt4GH). If we can find a few more then we can check whether the proposed design is suitably general to support all usecases.
Considerations/context
Tentative design
Given that the plugin should be able to interfere with the behaviour of each endpoint at two moments in time (after the request has been parsed, and before the response is serialized), this suggests having two dedicated methods per endpoint (, as in the design below:
Note how the pre/post methods follow the signature of the endpoint that they wrap. Plugins do not have to implement all methods, just the ones for which they have functionality to contribute.
Advantages/disadvantages
POST
from HTTP methods; other suggestions welcome.Example plugin (Crypt4GH)
This plugin has to offer two pieces of functionality.
Note that the specific implementation is not subject to any standard, and is likely to change in the future.
The text was updated successfully, but these errors were encountered: