Skip to content

Commit 3aba0cd

Browse files
committed
Rework the createuser cli using the new arguments parsing module.
1 parent ad0e71c commit 3aba0cd

File tree

1 file changed

+35
-17
lines changed

1 file changed

+35
-17
lines changed

mig/server/createuser.py

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
from mig.shared.conf import get_configuration_object
4545
from mig.shared.defaults import valid_auth_types, keyword_auto
4646
from mig.shared.gdp.all import ensure_gdp_user
47+
from mig.shared.minimist import parse_getopt_args, break_apart_legacy_usage
4748
from mig.shared.pwcrypto import unscramble_password, scramble_password, \
4849
make_hash
4950
from mig.shared.serial import load
@@ -75,21 +76,36 @@ def usage(name='createuser.py'):
7576
or
7677
%(name)s [OPTIONS] -i CERT_DN
7778
Where OPTIONS may be one or more of:
78-
-a AUTH_TYPE Prepare account for AUTH_TYPE login (expire, password)
79-
-c CONF_FILE Use CONF_FILE as server configuration
80-
-d DB_FILE Use DB_FILE as user data base file
81-
-e EXPIRE Set user account expiration to EXPIRE (epoch)
82-
-f Force operations to continue past errors
83-
-h Show this help
84-
-i CERT_DN Use CERT_DN as user ID despite what other fields suggest
85-
-o SHORT_ID Add SHORT_ID as OpenID alias for user
86-
-p PEER_PATTERN Verify in Peers of existing account matching PEER_PATTERN
87-
-r Renew user account with existing values
88-
-R ROLES Set user affiliation to ROLES
89-
-s SLACK_DAYS Allow peers even with account expired within SLACK_DAYS
90-
-u USER_FILE Read user information from pickle file
91-
-v Verbose output
92-
""" % {'name': name, 'cert_warn': cert_warn})
79+
""")
80+
81+
name_by_argument = break_apart_legacy_usage("""
82+
-a: AUTH_TYPE
83+
-c: CONF_FILE
84+
-d: DB_FILE
85+
-e: EXPIRE
86+
-i: CERT_DN
87+
-o: SHORT_ID
88+
-p: PEER_PATTERN
89+
-R: ROLES
90+
-s: SLACK_DAYS
91+
-u: USER_FILE
92+
""")
93+
94+
help_by_argument = break_apart_legacy_usage("""
95+
-a: Prepare account for AUTH_TYPE login (expire, password)
96+
-c: Use CONF_FILE as server configuration
97+
-d: Use DB_FILE as user data base file
98+
-e: Set user account expiration to EXPIRE (epoch)
99+
-f: Force operations to continue past errors
100+
-i: Use CERT_DN as user ID despite what other fields suggest
101+
-o: Add SHORT_ID as OpenID alias for user
102+
-p: Verify in Peers of existing account matching PEER_PATTERN
103+
-r: Renew user account with existing values
104+
-R: Set user affiliation to ROLES
105+
-s: Allow peers even with account expired within SLACK_DAYS
106+
-u: Read user information from pickle file
107+
-v: Verbose output
108+
""")
93109

94110

95111
def main(args, cwd, db_path=keyword_auto):
@@ -113,7 +129,9 @@ def main(args, cwd, db_path=keyword_auto):
113129
opt_args = 'a:c:d:e:fhi:o:p:rR:s:u:v'
114130

115131
try:
116-
(opts, args) = getopt.getopt(args, opt_args)
132+
(opts, args) = parse_getopt_args(args, opt_args,
133+
help_by_argument=help_by_argument,
134+
name_by_argument=name_by_argument)
117135
except getopt.GetoptError as err:
118136
print('Error: ', err.msg)
119137
usage()
@@ -138,7 +156,7 @@ def main(args, cwd, db_path=keyword_auto):
138156
expire = int(raw)
139157
parsed = True
140158
break
141-
except ValueError:
159+
except (TypeError, ValueError):
142160
print('Failed to parse expire value: %s' % val)
143161
sys.exit(1)
144162
elif opt == '-f':

0 commit comments

Comments
 (0)