Skip to content

Commit 7d91957

Browse files
committed
refactor (dirac-login): upload proxy only if needed
1 parent 6bf1723 commit 7d91957

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

src/DIRAC/FrameworkSystem/Client/ProxyManagerClient.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -653,15 +653,18 @@ def getVOMSAttributes(self, chain):
653653
"""
654654
return VOMS().getVOMSAttributes(chain)
655655

656-
def getUploadedProxyLifeTime(self, DN, group):
656+
def getUploadedProxyLifeTime(self, DN, group=None):
657657
"""Get the remaining seconds for an uploaded proxy
658658
659659
:param str DN: user DN
660660
:param str group: group
661661
662662
:return: S_OK(int)/S_ERROR()
663663
"""
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)
665668
if not result["OK"]:
666669
return result
667670
data = result["Value"]

src/DIRAC/FrameworkSystem/scripts/dirac_login.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,12 @@ def loginWithCertificate(self):
272272
if not result["OK"]:
273273
return result
274274

275+
# Read user credentials
276+
result = chain.getCredentials(withRegistryInfo=False)
277+
if not result["OK"]:
278+
return result
279+
credentials = result["Value"]
280+
275281
# Remember a clean proxy to then upload it in step 2
276282
proxy = copy.copy(chain)
277283

@@ -280,13 +286,23 @@ def loginWithCertificate(self):
280286
if not result["OK"]:
281287
return S_ERROR(f"Couldn't generate proxy: {result['Message']}")
282288

289+
# After creating the proxy, we can try to connect to the server
283290
result = Script.enableCS()
284291
if not result["OK"]:
285-
return S_ERROR("Cannot contact CS.")
292+
return S_ERROR(f"Cannot contact CS: {result['Message']}")
286293
gConfig.forceRefresh()
287294

288295
# 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()
290306

291307
def howToSwitch(self) -> bool:
292308
"""Helper message, how to switch access type(proxy or access token)"""

0 commit comments

Comments
 (0)