Skip to content

Commit

Permalink
feat (Storage): disable bearer plugins unless copying files
Browse files Browse the repository at this point in the history
  • Loading branch information
chaen committed Mar 4, 2025
1 parent e0ccde7 commit 46c7c9f
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions src/DIRAC/Resources/Storage/GFAL2_StorageBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ def __init__(self, storageName: str, parameters: dict[str, str]):
os.environ.get("DIRAC_GFAL_GRIDFTP_ENABLE_IPV6", "true").lower() not in ["false", "no"],
)

# Disable retrieving the bearer token for every operations.
# It is only useful for TPC
self.ctx.set_opt_boolean("HTTP PLUGIN", "RETRIEVE_BEARER_TOKEN", False)

# spaceToken used for copying from and to the storage element
self.spaceToken = parameters.get("SpaceToken", "")
# stageTimeout, default timeout to try and stage/pin a file
Expand Down Expand Up @@ -304,20 +308,23 @@ def putFile(self, path, sourceSize: int = 0):
failed = {}
successful = {}

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

try:
successful[dest_url] = self._putSingleFile(src_file, dest_url, sourceSize)
except (gfal2.GError, ValueError, RuntimeError) as e:
detailMsg = f"Failed to copy {src_file} to {dest_url}: {repr(e)}"
self.log.debug("Exception while copying", detailMsg)
failed[dest_url] = detailMsg
try:
successful[dest_url] = self._putSingleFile(src_file, dest_url, sourceSize)
except (gfal2.GError, ValueError, RuntimeError) as e:
detailMsg = f"Failed to copy {src_file} to {dest_url}: {repr(e)}"
self.log.debug("Exception while copying", detailMsg)
failed[dest_url] = detailMsg

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

Expand Down

0 comments on commit 46c7c9f

Please sign in to comment.