6
6
7
7
from DIRAC import S_OK , S_ERROR , gLogger , gConfig
8
8
from DIRAC .ConfigurationSystem .Client .Helpers .Resources import getQueue
9
- from DIRAC .ConfigurationSystem .Client .Helpers .Registry import getGroupOption
9
+ from DIRAC .ConfigurationSystem .Client .Helpers .Registry import getGroupOption , getUsernameForDN
10
10
from DIRAC .FrameworkSystem .Client .ProxyManagerClient import gProxyManager
11
+ from DIRAC .FrameworkSystem .Client .TokenManagerClient import gTokenManager
11
12
from DIRAC .Resources .Computing .ComputingElementFactory import ComputingElementFactory
12
13
13
14
@@ -49,7 +50,11 @@ def getPilotCE(pilotDict):
49
50
50
51
51
52
def getPilotProxy (pilotDict ):
52
- """Get a proxy bound to a pilot"""
53
+ """Get a proxy bound to a pilot
54
+
55
+ :param dict pilotDict: pilot parameters
56
+ :return: S_OK/S_ERROR with proxy as Value
57
+ """
53
58
owner = pilotDict ["OwnerDN" ]
54
59
group = pilotDict ["OwnerGroup" ]
55
60
@@ -62,6 +67,47 @@ def getPilotProxy(pilotDict):
62
67
return S_OK (proxy )
63
68
64
69
70
+ def getPilotToken (pilotDict ):
71
+ """Get a token corresponding to the pilot
72
+
73
+ :param dict pilotDict: pilot parameters
74
+ :return: S_OK/S_ERROR with token as Value
75
+ """
76
+ ownerDN = pilotDict ["OwnerDN" ]
77
+ group = pilotDict ["OwnerGroup" ]
78
+
79
+ result = getUsernameForDN (ownerDN )
80
+ if not result ["OK" ]:
81
+ return result
82
+ username = result ["Value" ]
83
+ result = gTokenManager .getToken (
84
+ username = username ,
85
+ userGroup = group ,
86
+ requiredTimeLeft = 3600 ,
87
+ )
88
+ return result
89
+
90
+
91
+ def setPilotCredentials (ce , pilotDict ):
92
+ """Instrument the given CE with proxy or token
93
+
94
+ :param obj ce: CE object
95
+ :param pilotDict: pilot parameter dictionary
96
+ :return: S_OK/S_ERROR
97
+ """
98
+ if "Token" in ce .ceParameters .get ("Tag" , []):
99
+ result = getPilotToken (pilotDict )
100
+ if not result ["OK" ]:
101
+ return result
102
+ ce .setToken (result ["Value" ], 3500 )
103
+ else :
104
+ result = getPilotProxy (pilotDict )
105
+ if not result ["OK" ]:
106
+ return result
107
+ ce .setProxy (result ["Value" ])
108
+ return S_OK ()
109
+
110
+
65
111
def getPilotRef (pilotReference , pilotDict ):
66
112
"""Add the pilotStamp to the pilotReference, if the pilotStamp is in the dictionary,
67
113
otherwise return unchanged pilotReference.
0 commit comments