File tree Expand file tree Collapse file tree 2 files changed +23
-4
lines changed
src/DIRAC/FrameworkSystem Expand file tree Collapse file tree 2 files changed +23
-4
lines changed Original file line number Diff line number Diff line change @@ -653,15 +653,18 @@ def getVOMSAttributes(self, chain):
653
653
"""
654
654
return VOMS ().getVOMSAttributes (chain )
655
655
656
- def getUploadedProxyLifeTime (self , DN , group ):
656
+ def getUploadedProxyLifeTime (self , DN , group = None ):
657
657
"""Get the remaining seconds for an uploaded proxy
658
658
659
659
:param str DN: user DN
660
660
:param str group: group
661
661
662
662
:return: S_OK(int)/S_ERROR()
663
663
"""
664
- result = self .getDBContents ({"UserDN" : [DN ], "UserGroup" : [group ]})
664
+ parameters = dict (UserDN = [DN ])
665
+ if group :
666
+ parameters ["UserGroup" ] = [group ]
667
+ result = self .getDBContents (parameters )
665
668
if not result ["OK" ]:
666
669
return result
667
670
data = result ["Value" ]
Original file line number Diff line number Diff line change @@ -272,6 +272,12 @@ def loginWithCertificate(self):
272
272
if not result ["OK" ]:
273
273
return result
274
274
275
+ # Read user credentials
276
+ result = chain .getCredentials (withRegistryInfo = False )
277
+ if not result ["OK" ]:
278
+ return result
279
+ credentials = result ["Value" ]
280
+
275
281
# Remember a clean proxy to then upload it in step 2
276
282
proxy = copy .copy (chain )
277
283
@@ -280,13 +286,23 @@ def loginWithCertificate(self):
280
286
if not result ["OK" ]:
281
287
return S_ERROR (f"Couldn't generate proxy: { result ['Message' ]} " )
282
288
289
+ # After creating the proxy, we can try to connect to the server
283
290
result = Script .enableCS ()
284
291
if not result ["OK" ]:
285
- return S_ERROR ("Cannot contact CS. " )
292
+ return S_ERROR (f "Cannot contact CS: { result [ 'Message' ] } " )
286
293
gConfig .forceRefresh ()
287
294
288
295
# Step 2: Upload proxy to DIRAC server
289
- return gProxyManager .uploadProxy (proxy )
296
+ result = gProxyManager .getUploadedProxyLifeTime (credentials ["subject" ])
297
+ if not result ["OK" ]:
298
+ return result
299
+ uploadedProxyLifetime = result ["Value" ]
300
+
301
+ # Upload proxy to the server if it longer that uploaded one
302
+ if credentials ["secondsLeft" ] > uploadedProxyLifetime :
303
+ gLogger .notice ("Upload proxy to server." )
304
+ return gProxyManager .uploadProxy (proxy )
305
+ return S_OK ()
290
306
291
307
def howToSwitch (self ) -> bool :
292
308
"""Helper message, how to switch access type(proxy or access token)"""
You can’t perform that action at this time.
0 commit comments