2626DEFAULT_TOKEN_CACHE_SIZE = 1024
2727
2828
29- def get_token (username : str , group : str , dirac_properties : set [str ], * , expires_minutes : int | None = None ):
30- """Do a legacy exchange to get a DiracX access_token+refresh_token"""
29+ def get_token (
30+ username : str , group : str , dirac_properties : set [str ], * , expires_minutes : int | None = None , source : str = ""
31+ ):
32+ """Do a legacy exchange to get a DiracX access_token+refresh_token
33+
34+ The source parameter only purpose is to appear in the URL on diracx logs"""
3135 diracxUrl = gConfig .getValue ("/DiracX/URL" )
3236 if not diracxUrl :
3337 raise ValueError ("Missing mandatory /DiracX/URL configuration" )
@@ -44,6 +48,7 @@ def get_token(username: str, group: str, dirac_properties: set[str], *, expires_
4448 "preferred_username" : username ,
4549 "scope" : " " .join (scopes ),
4650 "expires_minutes" : expires_minutes ,
51+ "source" : source ,
4752 },
4853 headers = {"Authorization" : f"Bearer { apiKey } " },
4954 timeout = 10 ,
@@ -58,15 +63,15 @@ def get_token(username: str, group: str, dirac_properties: set[str], *, expires_
5863 TTLCache (maxsize = DEFAULT_TOKEN_CACHE_SIZE , ttl = DEFAULT_TOKEN_CACHE_TTL ),
5964 key = lambda a , b , c : hashkey (a , b , * sorted (c )),
6065)
61- def _get_token_file (username : str , group : str , dirac_properties : set [str ]) -> Path :
66+ def _get_token_file (username : str , group : str , dirac_properties : set [str ], * , source : str = "" ) -> Path :
6267 """Write token to a temporary file and return the path to that file"""
63- data = get_token (username , group , dirac_properties )
68+ data = get_token (username , group , dirac_properties , source = source )
6469 token_location = Path (NamedTemporaryFile ().name )
6570 write_credentials (TokenResponse (** data ), location = token_location )
6671 return token_location
6772
6873
69- def TheImpersonator (credDict : dict [str , Any ]) -> SyncDiracClient :
74+ def TheImpersonator (credDict : dict [str , Any ], * , source : str = "" ) -> SyncDiracClient :
7075 """
7176 Client to be used by DIRAC server needing to impersonate
7277 a user for diracx.
@@ -83,6 +88,7 @@ def TheImpersonator(credDict: dict[str, Any]) -> SyncDiracClient:
8388 credDict ["username" ],
8489 credDict ["group" ],
8590 set (credDict .get ("groupProperties" , []) + credDict .get ("properties" , [])),
91+ source = source ,
8692 )
8793 pref = DiracxPreferences (url = diracxUrl , credentials_path = token_location )
8894
0 commit comments