26
26
DEFAULT_TOKEN_CACHE_SIZE = 1024
27
27
28
28
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"""
31
35
diracxUrl = gConfig .getValue ("/DiracX/URL" )
32
36
if not diracxUrl :
33
37
raise ValueError ("Missing mandatory /DiracX/URL configuration" )
@@ -44,6 +48,7 @@ def get_token(username: str, group: str, dirac_properties: set[str], *, expires_
44
48
"preferred_username" : username ,
45
49
"scope" : " " .join (scopes ),
46
50
"expires_minutes" : expires_minutes ,
51
+ "source" : source ,
47
52
},
48
53
headers = {"Authorization" : f"Bearer { apiKey } " },
49
54
timeout = 10 ,
@@ -58,15 +63,15 @@ def get_token(username: str, group: str, dirac_properties: set[str], *, expires_
58
63
TTLCache (maxsize = DEFAULT_TOKEN_CACHE_SIZE , ttl = DEFAULT_TOKEN_CACHE_TTL ),
59
64
key = lambda a , b , c : hashkey (a , b , * sorted (c )),
60
65
)
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 :
62
67
"""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 )
64
69
token_location = Path (NamedTemporaryFile ().name )
65
70
write_credentials (TokenResponse (** data ), location = token_location )
66
71
return token_location
67
72
68
73
69
- def TheImpersonator (credDict : dict [str , Any ]) -> SyncDiracClient :
74
+ def TheImpersonator (credDict : dict [str , Any ], * , source : str = "" ) -> SyncDiracClient :
70
75
"""
71
76
Client to be used by DIRAC server needing to impersonate
72
77
a user for diracx.
@@ -83,6 +88,7 @@ def TheImpersonator(credDict: dict[str, Any]) -> SyncDiracClient:
83
88
credDict ["username" ],
84
89
credDict ["group" ],
85
90
set (credDict .get ("groupProperties" , []) + credDict .get ("properties" , [])),
91
+ source = source ,
86
92
)
87
93
pref = DiracxPreferences (url = diracxUrl , credentials_path = token_location )
88
94
0 commit comments