40
40
import time
41
41
42
42
from mig .shared .accountstate import default_account_expire
43
- from mig .shared .arguments import parse_getopt_args , break_apart_legacy_usage
43
+ from mig .shared .arguments import parse_getopt_args , break_apart_legacy_usage , \
44
+ ArgumentBundleDefinition
44
45
from mig .shared .base import fill_distinguished_name , fill_user , canonical_user
45
46
from mig .shared .conf import get_configuration_object
46
47
from mig .shared .defaults import valid_auth_types , keyword_auto
@@ -107,8 +108,26 @@ def usage(name='createuser.py'):
107
108
-v: Verbose output
108
109
""" )
109
110
111
+ def _is_not_none (value ):
112
+ """value is not None"""
113
+ return value is not None
110
114
111
- def main (args , cwd , db_path = keyword_auto ):
115
+ def _is_string_and_non_empty (value ):
116
+ """value is a non-empty string"""
117
+ return isinstance (value , str ) and len (value ) > 0
118
+
119
+ _BUNDLE_DEFINITION = ArgumentBundleDefinition ('UserArguments' , [
120
+ (None , 'full_name' , _is_string_and_non_empty ),
121
+ (None , 'organization' , _is_string_and_non_empty ),
122
+ (None , 'state' , _is_string_and_non_empty ),
123
+ (None , 'country' , _is_string_and_non_empty ),
124
+ (None , 'email' , _is_string_and_non_empty ),
125
+ (None , 'comment' , _is_string_and_non_empty ),
126
+ (None , 'password' , _is_string_and_non_empty ),
127
+ ])
128
+
129
+
130
+ def main (_main , args , cwd , db_path = keyword_auto ):
112
131
conf_path = None
113
132
auth_type = 'custom'
114
133
expire = None
@@ -200,7 +219,9 @@ def main(args, cwd, db_path=keyword_auto):
200
219
if verbose :
201
220
print ('using configuration from MIG_CONF (or default)' )
202
221
203
- ret = _main (None , args ,
222
+ bundle = _BUNDLE_DEFINITION (* args )
223
+
224
+ ret = _main (None , bundle ,
204
225
conf_path = conf_path ,
205
226
db_path = db_path ,
206
227
expire = expire ,
@@ -218,6 +239,9 @@ def main(args, cwd, db_path=keyword_auto):
218
239
hash_password = hash_password
219
240
)
220
241
242
+ if ret is None :
243
+ return
244
+
221
245
if ret == errno .ENOTSUP :
222
246
usage ()
223
247
sys .exit (1 )
@@ -397,4 +421,4 @@ def _main(configuration, args,
397
421
398
422
if __name__ == '__main__' :
399
423
(args , cwd , db_path ) = init_user_adm ()
400
- main (args , cwd , db_path = db_path )
424
+ main (_main , args , cwd , db_path = db_path )
0 commit comments