Skip to content

Commit 1f30699

Browse files
authored
Merge pull request #8070 from chaen/v8.0_feat_gfalBearerToken
[8.0] feat (Storage): disable bearer plugins unless copying files
2 parents cff0526 + 46c7c9f commit 1f30699

1 file changed

Lines changed: 20 additions & 13 deletions

File tree

src/DIRAC/Resources/Storage/GFAL2_StorageBase.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@ def __init__(self, storageName: str, parameters: dict[str, str]):
166166
os.environ.get("DIRAC_GFAL_GRIDFTP_ENABLE_IPV6", "true").lower() not in ["false", "no"],
167167
)
168168

169+
# Disable retrieving the bearer token for every operations.
170+
# It is only useful for TPC
171+
self.ctx.set_opt_boolean("HTTP PLUGIN", "RETRIEVE_BEARER_TOKEN", False)
172+
169173
# spaceToken used for copying from and to the storage element
170174
self.spaceToken = parameters.get("SpaceToken", "")
171175
# stageTimeout, default timeout to try and stage/pin a file
@@ -306,20 +310,23 @@ def putFile(self, path, sourceSize: int = 0):
306310
failed = {}
307311
successful = {}
308312

309-
for dest_url, src_file in urls.items():
310-
if not src_file:
311-
errStr = "GFAL2_StorageBase.putFile: Source file not set. Argument must be a dictionary \
312-
(or a list of a dictionary) {url : local path}"
313-
self.log.debug(errStr)
314-
failed[dest_url] = errStr
315-
continue
313+
# In principle we only need the bearer token when doing TPC, however it's a
314+
# bit cumbersome to test, so we always re-enable it when uploading
315+
with setGfalSetting(self.ctx, "HTTP PLUGIN", "RETRIEVE_BEARER_TOKEN", True):
316+
for dest_url, src_file in urls.items():
317+
if not src_file:
318+
errStr = "GFAL2_StorageBase.putFile: Source file not set. Argument must be a dictionary \
319+
(or a list of a dictionary) {url : local path}"
320+
self.log.debug(errStr)
321+
failed[dest_url] = errStr
322+
continue
316323

317-
try:
318-
successful[dest_url] = self._putSingleFile(src_file, dest_url, sourceSize)
319-
except (gfal2.GError, ValueError, RuntimeError) as e:
320-
detailMsg = f"Failed to copy {src_file} to {dest_url}: {repr(e)}"
321-
self.log.debug("Exception while copying", detailMsg)
322-
failed[dest_url] = detailMsg
324+
try:
325+
successful[dest_url] = self._putSingleFile(src_file, dest_url, sourceSize)
326+
except (gfal2.GError, ValueError, RuntimeError) as e:
327+
detailMsg = f"Failed to copy {src_file} to {dest_url}: {repr(e)}"
328+
self.log.debug("Exception while copying", detailMsg)
329+
failed[dest_url] = detailMsg
323330

324331
return {"Failed": failed, "Successful": successful}
325332

0 commit comments

Comments
 (0)