Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.0] feat (Storage): disable bearer plugins unless copying files #8070

Merged
merged 1 commit into from
Mar 5, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading