@@ -164,6 +164,10 @@ def __init__(self, storageName: str, parameters: dict[str, str]):
164164 os .environ .get ("DIRAC_GFAL_GRIDFTP_ENABLE_IPV6" , "true" ).lower () not in ["false" , "no" ],
165165 )
166166
167+ # Disable retrieving the bearer token for every operations.
168+ # It is only useful for TPC
169+ self .ctx .set_opt_boolean ("HTTP PLUGIN" , "RETRIEVE_BEARER_TOKEN" , False )
170+
167171 # spaceToken used for copying from and to the storage element
168172 self .spaceToken = parameters .get ("SpaceToken" , "" )
169173 # stageTimeout, default timeout to try and stage/pin a file
@@ -304,20 +308,23 @@ def putFile(self, path, sourceSize: int = 0):
304308 failed = {}
305309 successful = {}
306310
307- for dest_url , src_file in urls .items ():
308- if not src_file :
309- errStr = "GFAL2_StorageBase.putFile: Source file not set. Argument must be a dictionary \
310- (or a list of a dictionary) {url : local path}"
311- self .log .debug (errStr )
312- failed [dest_url ] = errStr
313- continue
311+ # In principle we only need the bearer token when doing TPC, however it's a
312+ # bit cumbersome to test, so we always re-enable it when uploading
313+ with setGfalSetting (self .ctx , "HTTP PLUGIN" , "RETRIEVE_BEARER_TOKEN" , True ):
314+ for dest_url , src_file in urls .items ():
315+ if not src_file :
316+ errStr = "GFAL2_StorageBase.putFile: Source file not set. Argument must be a dictionary \
317+ (or a list of a dictionary) {url : local path}"
318+ self .log .debug (errStr )
319+ failed [dest_url ] = errStr
320+ continue
314321
315- try :
316- successful [dest_url ] = self ._putSingleFile (src_file , dest_url , sourceSize )
317- except (gfal2 .GError , ValueError , RuntimeError ) as e :
318- detailMsg = f"Failed to copy { src_file } to { dest_url } : { repr (e )} "
319- self .log .debug ("Exception while copying" , detailMsg )
320- failed [dest_url ] = detailMsg
322+ try :
323+ successful [dest_url ] = self ._putSingleFile (src_file , dest_url , sourceSize )
324+ except (gfal2 .GError , ValueError , RuntimeError ) as e :
325+ detailMsg = f"Failed to copy { src_file } to { dest_url } : { repr (e )} "
326+ self .log .debug ("Exception while copying" , detailMsg )
327+ failed [dest_url ] = detailMsg
321328
322329 return {"Failed" : failed , "Successful" : successful }
323330
0 commit comments