@@ -52,6 +52,15 @@ def __init__(self):
52
52
self .keyLoc = None
53
53
self .result = "proxy"
54
54
self .authWith = "certificate"
55
+ self .enableCS = True
56
+
57
+ def disableCS (self , _arg ) -> S_OK :
58
+ """Set issuer
59
+
60
+ :param arg: issuer
61
+ """
62
+ self .enableCS = False
63
+ return S_OK ()
55
64
56
65
def setIssuer (self , arg : str ) -> S_OK :
57
66
"""Set issuer
@@ -85,6 +94,9 @@ def setCertificate(self, arg: str) -> S_OK:
85
94
86
95
:param arg: path
87
96
"""
97
+ if not os .path .exists (arg ):
98
+ DIRAC .gLogger .error (f"{ arg } is not exist." )
99
+ DIRAC .exit (1 )
88
100
self .useCertificate (None )
89
101
self .certLoc = arg
90
102
return S_OK ()
@@ -94,6 +106,9 @@ def setPrivateKey(self, arg: str) -> S_OK:
94
106
95
107
:param arg: path
96
108
"""
109
+ if not os .path .exists (arg ):
110
+ DIRAC .gLogger .error (f"{ arg } is not exist." )
111
+ DIRAC .exit (1 )
97
112
self .useCertificate (None )
98
113
self .keyLoc = arg
99
114
return S_OK ()
@@ -160,19 +175,20 @@ def registerCLISwitches(self):
160
175
)
161
176
Script .registerSwitch ("I:" , "issuer=" , "set issuer." , self .setIssuer )
162
177
Script .registerSwitch (
163
- " " ,
178
+ "" ,
164
179
"use-certificate" ,
165
180
"in case you want to generate a proxy using a certificate. By default." ,
166
181
self .useCertificate ,
167
182
)
168
183
Script .registerSwitch (
169
- " " , "use-diracas" , "in case you want to authorize with DIRAC Authorization Server." , self .useDIRACAS
184
+ "" , "use-diracas" , "in case you want to authorize with DIRAC Authorization Server." , self .useDIRACAS
170
185
)
171
186
Script .registerSwitch ("C:" , "certificate=" , "user certificate location" , self .setCertificate )
172
187
Script .registerSwitch ("K:" , "key=" , "user key location" , self .setPrivateKey )
173
- Script .registerSwitch (" " , "proxy" , "return proxy in case of successful authorization" , self .setProxy )
174
- Script .registerSwitch (" " , "token" , "return tokens in case of successful authorization" , self .setToken )
175
- Script .registerSwitch (" " , "status" , "print user authorization status" , self .authStatus )
188
+ Script .registerSwitch ("" , "proxy" , "return proxy in case of successful authorization" , self .setProxy )
189
+ Script .registerSwitch ("" , "token" , "return tokens in case of successful authorization" , self .setToken )
190
+ Script .registerSwitch ("" , "status" , "print user authorization status" , self .authStatus )
191
+ Script .registerSwitch ("" , "nocs" , "disable CS." , self .disableCS )
176
192
177
193
def doOAuthMagic (self ):
178
194
"""Magic method with tokens
@@ -252,8 +268,7 @@ def loginWithCertificate(self):
252
268
return S_ERROR ("Can't find user certificate and key" )
253
269
self .certLoc = self .certLoc or cakLoc [0 ]
254
270
self .keyLoc = self .keyLoc or cakLoc [1 ]
255
- # Generate proxy
256
- self .outputFile = self .outputFile or Locations .getDefaultProxyLocation ()
271
+
257
272
chain = X509Chain ()
258
273
# Load user cert and key
259
274
result = chain .loadChainFromFile (self .certLoc )
@@ -272,26 +287,28 @@ def loginWithCertificate(self):
272
287
proxy = copy .copy (chain )
273
288
274
289
# Create local proxy with group
290
+ self .outputFile = self .outputFile or Locations .getDefaultProxyLocation ()
275
291
result = chain .generateProxyToFile (self .outputFile , int (self .lifetime or 12 ) * 3600 , self .group )
276
292
if not result ["OK" ]:
277
293
return S_ERROR (f"Couldn't generate proxy: { result ['Message' ]} " )
278
294
279
- # After creating the proxy, we can try to connect to the server
280
- result = Script .enableCS ()
281
- if not result ["OK" ]:
282
- return S_ERROR (f"Cannot contact CS: { result ['Message' ]} " )
283
- gConfig .forceRefresh ()
295
+ if self .enableCS :
296
+ # After creating the proxy, we can try to connect to the server
297
+ result = Script .enableCS ()
298
+ if not result ["OK" ]:
299
+ return S_ERROR (f"Cannot contact CS: { result ['Message' ]} " )
300
+ gConfig .forceRefresh ()
284
301
285
- # Step 2: Upload proxy to DIRAC server
286
- result = gProxyManager .getUploadedProxyLifeTime (credentials ["subject" ])
287
- if not result ["OK" ]:
288
- return result
289
- uploadedProxyLifetime = result ["Value" ]
302
+ # Step 2: Upload proxy to DIRAC server
303
+ result = gProxyManager .getUploadedProxyLifeTime (credentials ["subject" ])
304
+ if not result ["OK" ]:
305
+ return result
306
+ uploadedProxyLifetime = result ["Value" ]
290
307
291
- # Upload proxy to the server if it longer that uploaded one
292
- if credentials ["secondsLeft" ] > uploadedProxyLifetime :
293
- gLogger .notice ("Upload proxy to server." )
294
- return gProxyManager .uploadProxy (proxy )
308
+ # Upload proxy to the server if it longer that uploaded one
309
+ if credentials ["secondsLeft" ] > uploadedProxyLifetime :
310
+ gLogger .notice ("Upload proxy to server." )
311
+ return gProxyManager .uploadProxy (proxy )
295
312
return S_OK ()
296
313
297
314
def howToSwitch (self ) -> bool :
@@ -367,7 +384,7 @@ def main():
367
384
result = p .doOAuthMagic ()
368
385
369
386
# Print authorization status
370
- if result ["OK" ]:
387
+ if result ["OK" ] and p . enableCS :
371
388
result = p .getAuthStatus ()
372
389
373
390
if not result ["OK" ]:
0 commit comments