Skip to content

Commit 1990037

Browse files
authored
Merge pull request DIRACGrid#8117 from chrisburr/diracx-client-fixes
[9.0] Follow DiracX client changes
2 parents 3be24f9 + 68f9862 commit 1990037

3 files changed

Lines changed: 18 additions & 8 deletions

File tree

src/DIRAC/Core/Security/DiracX.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,17 @@
1414
import json
1515
import re
1616
import textwrap
17+
from collections.abc import Iterator
1718
from contextlib import contextmanager
1819
from pathlib import Path
1920
from tempfile import NamedTemporaryFile
2021
from typing import Any
2122

22-
from diracx.client import DiracClient as _DiracClient
23+
try:
24+
from diracx.client.sync import SyncDiracClient
25+
except ImportError:
26+
# TODO: Remove this once diracx is tagged
27+
from diracx.client import DiracClient as SyncDiracClient
2328
from diracx.core.models import TokenResponse
2429
from diracx.core.preferences import DiracxPreferences
2530
from diracx.core.utils import serialize_credentials
@@ -82,7 +87,7 @@ class FutureClient:
8287

8388

8489
@contextmanager
85-
def DiracXClient() -> _DiracClient:
90+
def DiracXClient() -> Iterator[SyncDiracClient]:
8691
"""Get a DiracX client instance with the current user's credentials"""
8792
diracxUrl = gConfig.getValue("/DiracX/URL")
8893
if not diracxUrl:
@@ -99,7 +104,7 @@ def DiracXClient() -> _DiracClient:
99104
token_file.seek(0)
100105

101106
pref = DiracxPreferences(url=diracxUrl, credentials_path=token_file.name)
102-
with _DiracClient(diracx_preferences=pref) as api:
107+
with SyncDiracClient(diracx_preferences=pref) as api:
103108
yield api
104109

105110

src/DIRAC/Core/Utilities/ReturnValues.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ def wrapped(*args: P.args, **kwargs: P.kwargs) -> DReturnType[T]:
239239
except SErrorException as e:
240240
return e.result
241241
except Exception as e:
242-
retval = S_ERROR(repr(e))
242+
retval = S_ERROR(f"{repr(e)}: {e}")
243243
# Replace CallStack with the one from the exception
244244
# Use cast as mypy doesn't understand that sys.exc_info can't return None in an exception block
245245
retval["ExecInfo"] = cast(tuple[type[BaseException], BaseException, TracebackType], sys.exc_info())

src/DIRAC/FrameworkSystem/Utilities/diracx.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@
1414
from diracx.core.utils import write_credentials
1515

1616
from diracx.core.models import TokenResponse
17-
from diracx.client import DiracClient
17+
18+
try:
19+
from diracx.client.sync import SyncDiracClient
20+
except ImportError:
21+
# TODO: Remove this once diracx is tagged
22+
from diracx.client import DiracClient as SyncDiracClient
1823

1924
# How long tokens are kept
2025
DEFAULT_TOKEN_CACHE_TTL = 5 * 60
@@ -61,11 +66,11 @@ def _get_token_file(username: str, group: str, dirac_properties: set[str]) -> Pa
6166
return token_location
6267

6368

64-
def TheImpersonator(credDict: dict[str, Any]) -> DiracClient:
69+
def TheImpersonator(credDict: dict[str, Any]) -> SyncDiracClient:
6570
"""
6671
Client to be used by DIRAC server needing to impersonate
6772
a user for diracx.
68-
It queries a token, places it in a file, and returns the `DiracClient`
73+
It queries a token, places it in a file, and returns the `SyncDiracClient`
6974
class
7075
7176
Use as a context manager
@@ -81,4 +86,4 @@ def TheImpersonator(credDict: dict[str, Any]) -> DiracClient:
8186
)
8287
pref = DiracxPreferences(url=diracxUrl, credentials_path=token_location)
8388

84-
return DiracClient(diracx_preferences=pref)
89+
return SyncDiracClient(diracx_preferences=pref)

0 commit comments

Comments
 (0)