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