Skip to content

Commit 407a3af

Browse files
authored
Merge pull request #8139 from chaen/9.0_impersonator_source
feat (TheImpersonator): add a source parameter
2 parents 34119de + ddc0e74 commit 407a3af

File tree

4 files changed

+24
-14
lines changed

4 files changed

+24
-14
lines changed

src/DIRAC/FrameworkSystem/Service/ProxyManagerHandler.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
""" ProxyManager is the implementation of the ProxyManagement service in the DISET framework
1+
"""ProxyManager is the implementation of the ProxyManagement service in the DISET framework
22
3-
.. literalinclude:: ../ConfigTemplate.cfg
4-
:start-after: ##BEGIN ProxyManager:
5-
:end-before: ##END
6-
:dedent: 2
7-
:caption: ProxyManager options
3+
.. literalinclude:: ../ConfigTemplate.cfg
4+
:start-after: ##BEGIN ProxyManager:
5+
:end-before: ##END
6+
:dedent: 2
7+
:caption: ProxyManager options
88
"""
9+
910
from DIRAC import S_ERROR, S_OK, gLogger
1011
from DIRAC.ConfigurationSystem.Client.Helpers import Registry
1112
from DIRAC.Core.DISET.RequestHandler import RequestHandler, getServiceOption
@@ -325,6 +326,7 @@ def export_exchangeProxyForToken(self):
325326
credDict["group"],
326327
set(credDict.get("groupProperties", []) + credDict.get("properties", [])),
327328
expires_minutes=credDict["secondsLeft"] // 60 + 1,
329+
source="ProxyManager",
328330
)
329331

330332

src/DIRAC/FrameworkSystem/Utilities/diracx.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@
2626
DEFAULT_TOKEN_CACHE_SIZE = 1024
2727

2828

29-
def get_token(username: str, group: str, dirac_properties: set[str], *, expires_minutes: int | None = None):
30-
"""Do a legacy exchange to get a DiracX access_token+refresh_token"""
29+
def get_token(
30+
username: str, group: str, dirac_properties: set[str], *, expires_minutes: int | None = None, source: str = ""
31+
):
32+
"""Do a legacy exchange to get a DiracX access_token+refresh_token
33+
34+
The source parameter only purpose is to appear in the URL on diracx logs"""
3135
diracxUrl = gConfig.getValue("/DiracX/URL")
3236
if not diracxUrl:
3337
raise ValueError("Missing mandatory /DiracX/URL configuration")
@@ -44,6 +48,7 @@ def get_token(username: str, group: str, dirac_properties: set[str], *, expires_
4448
"preferred_username": username,
4549
"scope": " ".join(scopes),
4650
"expires_minutes": expires_minutes,
51+
"source": source,
4752
},
4853
headers={"Authorization": f"Bearer {apiKey}"},
4954
timeout=10,
@@ -58,15 +63,15 @@ def get_token(username: str, group: str, dirac_properties: set[str], *, expires_
5863
TTLCache(maxsize=DEFAULT_TOKEN_CACHE_SIZE, ttl=DEFAULT_TOKEN_CACHE_TTL),
5964
key=lambda a, b, c: hashkey(a, b, *sorted(c)),
6065
)
61-
def _get_token_file(username: str, group: str, dirac_properties: set[str]) -> Path:
66+
def _get_token_file(username: str, group: str, dirac_properties: set[str], *, source: str = "") -> Path:
6267
"""Write token to a temporary file and return the path to that file"""
63-
data = get_token(username, group, dirac_properties)
68+
data = get_token(username, group, dirac_properties, source=source)
6469
token_location = Path(NamedTemporaryFile().name)
6570
write_credentials(TokenResponse(**data), location=token_location)
6671
return token_location
6772

6873

69-
def TheImpersonator(credDict: dict[str, Any]) -> SyncDiracClient:
74+
def TheImpersonator(credDict: dict[str, Any], *, source: str = "") -> SyncDiracClient:
7075
"""
7176
Client to be used by DIRAC server needing to impersonate
7277
a user for diracx.
@@ -83,6 +88,7 @@ def TheImpersonator(credDict: dict[str, Any]) -> SyncDiracClient:
8388
credDict["username"],
8489
credDict["group"],
8590
set(credDict.get("groupProperties", []) + credDict.get("properties", [])),
91+
source=source,
8692
)
8793
pref = DiracxPreferences(url=diracxUrl, credentials_path=token_location)
8894

src/DIRAC/WorkloadManagementSystem/Service/SandboxStoreHandler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def _getFromClient(self, fileId, token, fileSize, fileHelper=None, data=""):
120120
format=extension,
121121
)
122122

123-
with TheImpersonator(credDict) as client:
123+
with TheImpersonator(credDict, source="SandboxStore") as client:
124124
res = client.jobs.initiate_sandbox_upload(sandbox_info)
125125

126126
if res.url:
@@ -415,7 +415,7 @@ def _sendToClient(self, fileID, token, fileHelper=None, raw=False):
415415
# If the PFN starts with S3, we know it has been uploaded to the
416416
# S3 sandbox store, so download it from there before sending it
417417
if filePath.startswith("/S3"):
418-
with TheImpersonator(credDict) as client:
418+
with TheImpersonator(credDict, source="SandboxStore") as client:
419419
res = client.jobs.get_sandbox_file(pfn=filePath)
420420
r = requests.get(res.url)
421421
r.raise_for_status()

tests/CI/docker-compose.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ services:
8383

8484
# Mock of an S3 storage
8585
s3-direct:
86-
image: adobe/s3mock
86+
# Fix the version until https://github.com/adobe/S3Mock/issues/2321
87+
# is resolved
88+
image: adobe/s3mock:3.12.0
8789
container_name: s3-direct
8890
hostname: s3-direct
8991
ports:

0 commit comments

Comments
 (0)