diff --git a/src/DIRAC/DataManagementSystem/Client/FTS3Job.py b/src/DIRAC/DataManagementSystem/Client/FTS3Job.py index 650c161223e..2ccf8080a3b 100644 --- a/src/DIRAC/DataManagementSystem/Client/FTS3Job.py +++ b/src/DIRAC/DataManagementSystem/Client/FTS3Job.py @@ -499,6 +499,7 @@ def _constructTransferJob(self, pinTime, allLFNs, target_spacetoken, protocols=N userGroup="lhcb_data", requiredTimeLeft=3600, scope=[f"storage.read:/{srcTokenPath}", "offline_access"], + useCache=False, ) if not res["OK"]: return res @@ -512,6 +513,7 @@ def _constructTransferJob(self, pinTime, allLFNs, target_spacetoken, protocols=N userGroup="lhcb_data", requiredTimeLeft=3600, scope=[f"storage.modify:/{dstTokenPath}", f"storage.read:/{dstTokenPath}", "offline_access"], + useCache=False, ) if not res["OK"]: return res diff --git a/src/DIRAC/FrameworkSystem/Client/TokenManagerClient.py b/src/DIRAC/FrameworkSystem/Client/TokenManagerClient.py index 74324bcbddc..53cab1dcd64 100644 --- a/src/DIRAC/FrameworkSystem/Client/TokenManagerClient.py +++ b/src/DIRAC/FrameworkSystem/Client/TokenManagerClient.py @@ -1,6 +1,7 @@ """ The TokenManagerClient is a class representing the client of the DIRAC :py:mod:`TokenManager ` service. """ + import time from DIRAC import S_OK, S_ERROR @@ -31,7 +32,6 @@ def __init__(self, **kwargs): self.__tokensCache = DictCache() self.idps = IdProviderFactory() - @gTokensSync def getToken( self, username: str = None, @@ -40,6 +40,58 @@ def getToken( audience: str = None, identityProvider: str = None, requiredTimeLeft: int = 0, + useCache: bool = True, + ): + meth = self.getTokenWithCache if useCache else self.getTokenWithoutCache + + return meth( + username=username, + userGroup=userGroup, + scope=scope, + audience=audience, + identityProvider=identityProvider, + requiredTimeLeft=requiredTimeLeft, + ) + + def getTokenWithoutCache( + self, + username: str = None, + userGroup: str = None, + scope: list[str] = None, + audience: str = None, + identityProvider: str = None, + requiredTimeLeft: int = 0, + ): + """Get an access token for a user/group keeping the local cache + + :param username: user name + :param userGroup: group name + :param scope: scope + :param audience: audience + :param identityProvider: identity Provider + :param requiredTimeLeft: required time + :param cacheToken: if True (default) save the token in cache + + :return: S_OK(dict)/S_ERROR() + """ + # Get an IdProvider Client instance + result = getIdProviderClient(userGroup, identityProvider) + if not result["OK"]: + return result + idpObj = result["Value"] + + # No token in cache: get a token from the server + return self.executeRPC(username, userGroup, scope, audience, idpObj.name, requiredTimeLeft, call="getToken") + + @gTokensSync + def getTokenWithCache( + self, + username: str = None, + userGroup: str = None, + scope: list[str] = None, + audience: str = None, + identityProvider: str = None, + requiredTimeLeft: int = 0, ): """Get an access token for a user/group keeping the local cache