feat: add a business logic layer#403
Conversation
add09a4 to
168a6bc
Compare
|
I thought we had agreed not to do it in general, and only on adhoc cases ? |
|
Oops, I thought we said we would add a business logic layer within I thought it would be better to be consistent and have all the business logic at the same place to have a single responsibility principle between the layers + follow a standard architectural pattern. |
3a39077 to
3006c3b
Compare
af55ea2 to
b03406b
Compare
|
|
|
You can create the dev tag yourself by triggering the deployment :-) Even if it creates a new real tag, it does not really matter... :-) |
|
Alright, all is 🟢 now |
fstagni
left a comment
There was a problem hiding this comment.
It is close to impossible to properly review this PR, so these are just few comments.
For a PR that mostly should be a lot of "move around" of code, I am surprised that there are more than 700 lines of code added
| # TODO: this should probably be something mandatory | ||
| # to set by the user | ||
| token_issuer: str = "http://lhcbdirac.cern.ch/" # noqa: S105 |
There was a problem hiding this comment.
Is this something used (e.g. by the tests) or something here as an example?
There was a problem hiding this comment.
I don't think it's used, let's try to remove it and see if it breaks
There was a problem hiding this comment.
I know you did not start this file, anyway: what is the rationale for having all (?) models in it?
There was a problem hiding this comment.
Good question actually, I think we should agree on the purpose of this file and it would deserve a docstring.
I added all the models that were (i) passed as inputs to the routers; (ii) returned as outputs by the routers, so the ones that could be shared between the clients (cli, api) and the services (routers, logic, db).
At some point we should probably make a models directory with multiple modules such as jobs, auth...
| self, owner_id: int, se_name: str, pfn: str, size: int | ||
| ) -> None: | ||
| """Add a new sandbox in SandboxMetadataDB.""" | ||
| # TODO: Follow https://github.com/DIRACGrid/diracx/issues/49 |
There was a problem hiding this comment.
The linked issue is not solved. It does not apply here anymore?
There was a problem hiding this comment.
The linked issue is not solved:
- I break down the method into smaller methods in
diracx-dbto move the logic from it todiracx-logic. - The comment was moved to
diracx-logicbecause it makes more sense to read it from here now.
| # We shouldn't be able to retrieve it twice | ||
| async with auth_db as auth_db: | ||
| with pytest.raises(AuthorizationError, match="already used"): | ||
| res = await auth_db.get_authorization_flow(code, MAX_VALIDITY) | ||
|
|
There was a problem hiding this comment.
Because:
- I break down
get_authorization_flowinto smaller methods to move the logic fromdiracx-dbtodiracx-logic - The new
get_authorization_flowis now very simple and does not require complex testing as it was the case before: complex testing should now be done indiracx-routersand it's already done.
f92d3f7 to
d2c33ac
Compare
d2c33ac to
30bf8ff
Compare
Details explained in #348
Splitdiracx-dbinto 2 sub-directory:businessanddata_access.Update: create a
diracx-logiclayerdiracx-routersbecomes the presentation layer: manages user authN/Z, calls the business logic layer and converts the returned results/raised exceptions into HTTP-friendly responses for the end users.diracx-logic: deals with the business logic by performing operations and calling the data access layer to get additional data and persist them.diracx-db: abstracts sql/no sql complexities.diracx-routersand move business logic todiracx-logic.diracx-routersand move business logic todiracx-logic.DIRACfromdiracx-db.jobs.dbdiracx-dbmore simple (atomic operations + business logic moved todiracx-logic)Enforce consistency usingimport-linterUpdate: enforce consistency by adding the right dependencies in the right package:
diracx-routersdepends onfastapi, notdiracnorsqlalchemy/opensearchpy.diracx-logicdepends ondirac, notfastapinorsqlalchemy/opensearchpy.diracx-dbdepends onsqlalchemy/opensearchpy, notdiracnorfastapi.diracx.routersbecause they are injected throughdiracx.routers.dependencies, so we would need to be careful when reviewing the code.documentation about the 3-layer architecture within diracx