33
33
from builtins import input
34
34
from getpass import getpass
35
35
import datetime
36
+ import errno
36
37
import getopt
37
38
import os
38
39
import sys
@@ -181,7 +182,7 @@ def main(args, cwd, db_path=keyword_auto):
181
182
if verbose :
182
183
print ('using configuration from MIG_CONF (or default)' )
183
184
184
- _main (None , args ,
185
+ ret = _main (None , args ,
185
186
conf_path = conf_path ,
186
187
db_path = db_path ,
187
188
expire = expire ,
@@ -199,6 +200,12 @@ def main(args, cwd, db_path=keyword_auto):
199
200
hash_password = hash_password
200
201
)
201
202
203
+ if ret == errno .ENOTSUP :
204
+ usage ()
205
+ sys .exit (1 )
206
+
207
+ sys .exit (ret )
208
+
202
209
203
210
def _main (configuration , args ,
204
211
conf_path = keyword_auto ,
@@ -234,14 +241,12 @@ def _main(configuration, args,
234
241
235
242
if user_file and args :
236
243
print ('Error: Only one kind of user specification allowed at a time' )
237
- usage ()
238
- sys .exit (1 )
244
+ return errno .ENOTSUP
239
245
240
246
if auth_type not in valid_auth_types :
241
247
print ('Error: invalid account auth type %r requested (allowed: %s)' %
242
248
(auth_type , ', ' .join (valid_auth_types )))
243
- usage ()
244
- sys .exit (1 )
249
+ return errno .ENOTSUP
245
250
246
251
# NOTE: renew requires original password
247
252
if auth_type == 'cert' :
@@ -262,8 +267,7 @@ def _main(configuration, args,
262
267
except IndexError :
263
268
print ('Error: too few arguments given (expected 7 got %d)'
264
269
% len (args ))
265
- usage ()
266
- sys .exit (1 )
270
+ return errno .ENOTSUP
267
271
# Force user ID fields to canonical form for consistency
268
272
# Title name, lowercase email, uppercase country and state, etc.
269
273
user_dict = canonical_user (configuration , raw_user , raw_user .keys ())
@@ -272,14 +276,12 @@ def _main(configuration, args,
272
276
user_dict = load (user_file )
273
277
except Exception as err :
274
278
print ('Error in user name extraction: %s' % err )
275
- usage ()
276
- sys .exit (1 )
279
+ return errno .ENOTSUP
277
280
elif default_renew and user_id :
278
281
saved = load_user_dict (logger , user_id , db_path , verbose )
279
282
if not saved :
280
283
print ('Error: no such user in user db: %s' % user_id )
281
- usage ()
282
- sys .exit (1 )
284
+ return errno .ENOTSUP
283
285
user_dict .update (saved )
284
286
del user_dict ['expire' ]
285
287
elif not configuration .site_enable_gdp :
@@ -301,7 +303,7 @@ def _main(configuration, args,
301
303
print ("Error: Missing one or more of the arguments: "
302
304
+ "[FULL_NAME] [ORGANIZATION] [STATE] [COUNTRY] "
303
305
+ "[EMAIL] [COMMENT] [PASSWORD]" )
304
- sys . exit ( 1 )
306
+ return 1
305
307
306
308
# Encode password if set but not already encoded
307
309
@@ -364,14 +366,16 @@ def _main(configuration, args,
364
366
print ("Error creating user: %s" % exc )
365
367
import traceback
366
368
logger .warning ("Error creating user: %s" % traceback .format_exc ())
367
- sys . exit ( 1 )
369
+ return 1
368
370
print ('Created or updated %s in user database and in file system' %
369
371
user_dict ['distinguished_name' ])
370
372
if user_file :
371
373
if verbose :
372
374
print ('Cleaning up tmp file: %s' % user_file )
373
375
os .remove (user_file )
374
376
377
+ return 0
378
+
375
379
376
380
if __name__ == '__main__' :
377
381
(args , cwd , db_path ) = init_user_adm ()
0 commit comments