mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Add option to only prompt once for passwords, use in entitle_register
A Password param always prompted to confirm the entered password. This doesn't make sense if you want to prompt for a password to another system like we do with entitlements. This adds a new boolean option to control the Password prompt parameter. https://fedorahosted.org/freeipa/ticket/1695
This commit is contained in:
parent
41d89d0d13
commit
1936b8050e
2
API.txt
2
API.txt
@ -885,7 +885,7 @@ arg: Str('username', label=Gettext('Username', domain='ipa', localedir=None))
|
|||||||
option: Str('addattr*', validate_add_attribute, cli_name='addattr', exclude='webui')
|
option: Str('addattr*', validate_add_attribute, cli_name='addattr', exclude='webui')
|
||||||
option: Str('setattr*', validate_set_attribute, cli_name='setattr', exclude='webui')
|
option: Str('setattr*', validate_set_attribute, cli_name='setattr', exclude='webui')
|
||||||
option: Str('ipaentitlementid?', flags=['no_create', 'no_update'], label='UUID')
|
option: Str('ipaentitlementid?', flags=['no_create', 'no_update'], label='UUID')
|
||||||
option: Password('password', label=Gettext('Password', domain='ipa', localedir=None))
|
option: Password('password', confirm=False, label=Gettext('Password', domain='ipa', localedir=None))
|
||||||
option: Flag('all', autofill=True, cli_name='all', default=False, exclude='webui', flags=['no_output'])
|
option: Flag('all', autofill=True, cli_name='all', default=False, exclude='webui', flags=['no_output'])
|
||||||
option: Flag('raw', autofill=True, cli_name='raw', default=False, exclude='webui', flags=['no_output'])
|
option: Flag('raw', autofill=True, cli_name='raw', default=False, exclude='webui', flags=['no_output'])
|
||||||
option: Str('version?', exclude='webui', flags=['no_option', 'no_output'])
|
option: Str('version?', exclude='webui', flags=['no_option', 'no_output'])
|
||||||
|
@ -568,7 +568,7 @@ class textui(backend.Backend):
|
|||||||
elif default is not None and data == u'':
|
elif default is not None and data == u'':
|
||||||
return default
|
return default
|
||||||
|
|
||||||
def prompt_password(self, label):
|
def prompt_password(self, label, confirm=True):
|
||||||
"""
|
"""
|
||||||
Prompt user for a password or read it in via stdin depending
|
Prompt user for a password or read it in via stdin depending
|
||||||
on whether there is a tty or not.
|
on whether there is a tty or not.
|
||||||
@ -577,6 +577,8 @@ class textui(backend.Backend):
|
|||||||
if sys.stdin.isatty():
|
if sys.stdin.isatty():
|
||||||
while True:
|
while True:
|
||||||
pw1 = getpass.getpass(u'%s: ' % unicode(label))
|
pw1 = getpass.getpass(u'%s: ' % unicode(label))
|
||||||
|
if not confirm:
|
||||||
|
return self.decode(pw1)
|
||||||
pw2 = getpass.getpass(
|
pw2 = getpass.getpass(
|
||||||
unicode(_('Enter %(label)s again to verify: ') % dict(label=label))
|
unicode(_('Enter %(label)s again to verify: ') % dict(label=label))
|
||||||
)
|
)
|
||||||
@ -1050,7 +1052,7 @@ class cli(backend.Executioner):
|
|||||||
(param.alwaysask and honor_alwaysask) or self.env.prompt_all:
|
(param.alwaysask and honor_alwaysask) or self.env.prompt_all:
|
||||||
if param.password:
|
if param.password:
|
||||||
kw[param.name] = self.Backend.textui.prompt_password(
|
kw[param.name] = self.Backend.textui.prompt_password(
|
||||||
param.label
|
param.label, param.confirm
|
||||||
)
|
)
|
||||||
elif param.autofill:
|
elif param.autofill:
|
||||||
kw[param.name] = param.get_default(**kw)
|
kw[param.name] = param.get_default(**kw)
|
||||||
@ -1070,7 +1072,7 @@ class cli(backend.Executioner):
|
|||||||
error = e.error
|
error = e.error
|
||||||
elif param.password and kw.get(param.name, False) is True:
|
elif param.password and kw.get(param.name, False) is True:
|
||||||
kw[param.name] = self.Backend.textui.prompt_password(
|
kw[param.name] = self.Backend.textui.prompt_password(
|
||||||
param.label
|
param.label, param.confirm
|
||||||
)
|
)
|
||||||
|
|
||||||
for callback in getattr(cmd, 'INTERACTIVE_PROMPT_CALLBACKS', []):
|
for callback in getattr(cmd, 'INTERACTIVE_PROMPT_CALLBACKS', []):
|
||||||
|
@ -1369,6 +1369,10 @@ class Password(Str):
|
|||||||
A parameter for passwords (stored in the ``unicode`` type).
|
A parameter for passwords (stored in the ``unicode`` type).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
kwargs = Str.kwargs + (
|
||||||
|
('confirm', bool, True),
|
||||||
|
)
|
||||||
|
|
||||||
def _convert_scalar(self, value, index=None):
|
def _convert_scalar(self, value, index=None):
|
||||||
if isinstance(value, (tuple, list)) and len(value) == 2:
|
if isinstance(value, (tuple, list)) and len(value) == 2:
|
||||||
(p1, p2) = value
|
(p1, p2) = value
|
||||||
|
@ -494,6 +494,7 @@ class entitle_register(LDAPCreate):
|
|||||||
Password('password',
|
Password('password',
|
||||||
label=_('Password'),
|
label=_('Password'),
|
||||||
doc=_('Registration password'),
|
doc=_('Registration password'),
|
||||||
|
confirm=False,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user