Skip to content

Commit 21bc12e

Browse files
committed
refactor: Simplify definition of dependencies
1 parent 63d3a01 commit 21bc12e

36 files changed

Lines changed: 310 additions & 269 deletions

File tree

diracx-db/src/diracx/db/sql/utils/base.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,12 @@ async def post_create(cls, conn: AsyncConnection) -> None:
165165

166166
@classmethod
167167
def transaction(cls) -> Self:
168+
"""Dependency injection sentinel: overridden at startup to yield a DB inside a transaction."""
169+
raise NotImplementedError("This should never be called")
170+
171+
@classmethod
172+
def no_transaction(cls) -> Self:
173+
"""Dependency injection sentinel: overridden at startup to yield a DB without a transaction."""
168174
raise NotImplementedError("This should never be called")
169175

170176
@property

diracx-logic/src/diracx/logic/auth/token.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ async def get_oidc_token_info_from_refresh_flow(
193193
# Revoke all the user tokens from the subject
194194
await auth_db.revoke_user_refresh_tokens(sub)
195195

196-
# Commit here, otherwise the revokation operation will not be taken into account
196+
# Commit here, otherwise the revocation operation will not be taken into account
197197
# as we return an error to the user
198198
await auth_db.conn.commit()
199199

diracx-logic/src/diracx/logic/jobs/sandboxes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ async def clean_sandboxes(
210210
3. Deletes from DB
211211
212212
Args:
213-
sandbox_metadata_db: Database connection (not yet entered).
213+
sandbox_metadata_db: Database connection (not in a transaction).
214214
settings: Sandbox store settings with S3 client.
215215
216216
Returns:

diracx-routers/src/diracx/routers/access_policies.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
AccessTokenPayload,
3232
RefreshTokenPayload,
3333
)
34-
from diracx.routers.dependencies import DevelopmentSettings
34+
from diracx.core.settings import DevelopmentSettings
35+
from diracx.routers.dependencies import auto_inject
3536
from diracx.routers.utils.users import AuthorizedUserInfo, verify_dirac_access_token
3637

3738
if "annotations" in globals():
@@ -107,6 +108,7 @@ def enrich_tokens(
107108
return {}, {}
108109

109110

111+
@auto_inject
110112
def check_permissions(
111113
policy: Callable,
112114
policy_name: str,

diracx-routers/src/diracx/routers/auth/authorize_code_flow.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,17 @@
1616
)
1717

1818
from diracx.core.exceptions import AuthorizationError, IAMClientError, IAMServerError
19+
from diracx.core.settings import AuthSettings
20+
from diracx.db.sql import AuthDB
1921
from diracx.logic.auth.authorize_code_flow import (
2022
complete_authorization_flow as complete_authorization_flow_bl,
2123
)
2224
from diracx.logic.auth.authorize_code_flow import (
2325
initiate_authorization_flow as initiate_authorization_flow_bl,
2426
)
27+
from diracx.routers.dependencies import Config
2528

26-
from ..dependencies import (
27-
AuthDB,
28-
AuthSettings,
29-
AvailableSecurityProperties,
30-
Config,
31-
)
29+
from ..dependencies import AvailableSecurityProperties
3230
from ..fastapi_classes import DiracxRouter
3331

3432
logger = logging.getLogger(__name__)

diracx-routers/src/diracx/routers/auth/device_flow.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,18 @@
1818

1919
from diracx.core.exceptions import IAMClientError, IAMServerError
2020
from diracx.core.models.auth import InitiateDeviceFlowResponse
21+
from diracx.core.settings import AuthSettings
22+
from diracx.db.sql import AuthDB
2123
from diracx.logic.auth.device_flow import do_device_flow as do_device_flow_bl
2224
from diracx.logic.auth.device_flow import (
2325
finish_device_flow as finish_device_flow_bl,
2426
)
2527
from diracx.logic.auth.device_flow import (
2628
initiate_device_flow as initiate_device_flow_bl,
2729
)
30+
from diracx.routers.dependencies import Config
2831

29-
from ..dependencies import (
30-
AuthDB,
31-
AuthSettings,
32-
AvailableSecurityProperties,
33-
Config,
34-
)
32+
from ..dependencies import AvailableSecurityProperties
3533
from ..fastapi_classes import DiracxRouter
3634

3735
logger = logging.getLogger(__name__)

diracx-routers/src/diracx/routers/auth/management.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
from diracx.core.exceptions import InvalidCredentialsError, TokenNotFoundError
1818
from diracx.core.properties import PROXY_MANAGEMENT, SecurityProperty
19+
from diracx.core.settings import AuthSettings
20+
from diracx.db.sql import AuthDB
1921
from diracx.logic.auth.management import (
2022
get_refresh_tokens as get_refresh_tokens_bl,
2123
)
@@ -26,7 +28,6 @@
2628
revoke_refresh_token_by_refresh_token as revoke_refresh_token_by_refresh_token_bl,
2729
)
2830

29-
from ..dependencies import AuthDB, AuthSettings
3031
from ..fastapi_classes import DiracxRouter
3132
from ..utils.users import AuthorizedUserInfo, verify_dirac_access_token
3233

diracx-routers/src/diracx/routers/auth/token.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,17 @@
2020
RefreshTokenPayload,
2121
TokenResponse,
2222
)
23+
from diracx.core.settings import AuthSettings
24+
from diracx.db.sql import AuthDB
2325
from diracx.logic.auth.token import create_token
2426
from diracx.logic.auth.token import get_oidc_token as get_oidc_token_bl
2527
from diracx.logic.auth.token import (
2628
perform_legacy_exchange as perform_legacy_exchange_bl,
2729
)
2830
from diracx.routers.access_policies import BaseAccessPolicy
31+
from diracx.routers.dependencies import Config
2932

30-
from ..dependencies import AuthDB, AuthSettings, AvailableSecurityProperties, Config
33+
from ..dependencies import AvailableSecurityProperties
3134
from ..fastapi_classes import DiracxRouter
3235

3336
router = DiracxRouter(require_auth=False)

diracx-routers/src/diracx/routers/auth/well_known.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from fastapi import Request
44

55
from diracx.core.models.auth import Metadata, OpenIDConfiguration
6+
from diracx.core.settings import AuthSettings
67
from diracx.logic.auth.well_known import (
78
get_installation_metadata as get_installation_metadata_bl,
89
)
@@ -12,8 +13,8 @@
1213
from diracx.logic.auth.well_known import (
1314
get_openid_configuration as get_openid_configuration_bl,
1415
)
16+
from diracx.routers.dependencies import Config
1517

16-
from ..dependencies import AuthSettings, Config
1718
from ..fastapi_classes import DiracxRouter
1819

1920
router = DiracxRouter(require_auth=False, path_root="")

diracx-routers/src/diracx/routers/configuration.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
status,
1212
)
1313

14+
from diracx.routers.dependencies import Config
15+
1416
from .access_policies import open_access
15-
from .dependencies import Config
1617
from .fastapi_classes import DiracxRouter
1718

1819
logger = logging.getLogger(__name__)

0 commit comments

Comments
 (0)