Add prompt strategy

This commit is contained in:
Markus Unterwaditzer 2015-10-04 13:30:40 +02:00
parent d5254081f8
commit 21b1bafc48
3 changed files with 23 additions and 6 deletions

View file

@ -6,8 +6,7 @@ Storing passwords
Password configuration got completely overhauled.
Vdirsyncer can fetch passwords from a custom command or your system keyring if
the keyring_ Python package is installed.
Vdirsyncer can fetch passwords from several sources other than the config file.
Command
=======
@ -53,3 +52,14 @@ Given that you have the keyring_ Python library installed, you can use::
password.fetch = ["keyring", "myservicename", "myusername"]
.. _keyring: https://pypi.python.org/pypi/keyring
Password Prompt
===============
You can also simply prompt for the password::
[storage foo]
type = caldav
username = myusername
password.fetch = ["prompt", "Password for CalDAV"]

View file

@ -30,7 +30,7 @@ def test_get_password_from_command(tmpdir, runner):
[storage bar]
type = filesystem
path = {base}/bar/
fileext.fetch = ["command", "echo", ".asdf"]
fileext.fetch = ["prompt", "Fileext for bar"]
'''.format(base=str(tmpdir))))
foo = tmpdir.ensure('foo', dir=True)
@ -42,7 +42,7 @@ def test_get_password_from_command(tmpdir, runner):
bar.ensure('b', dir=True)
bar.ensure('c', dir=True)
result = runner.invoke(['discover'])
result = runner.invoke(['discover'], input='.asdf\n')
assert not result.exception
status = tmpdir.join('status').join('foobar.collections').read()
assert 'foo' in status
@ -50,5 +50,7 @@ def test_get_password_from_command(tmpdir, runner):
assert 'asdf' not in status
assert 'txt' not in status
result = runner.invoke(['sync'])
foo.join('a').join('foo.txt').write('BEGIN:VCARD\nUID:foo\nEND:VCARD')
result = runner.invoke(['sync'], input='.asdf\n')
assert not result.exception
assert [x.basename for x in bar.join('a').listdir()] == ['foo.asdf']

View file

@ -85,7 +85,12 @@ def _strategy_command(*command):
.format(' '.join(command), str(e)))
def _strategy_prompt(text):
return click.prompt(text, hide_input=True)
STRATEGIES = {
'keyring': _strategy_keyring,
'command': _strategy_command
'command': _strategy_command,
'prompt': _strategy_prompt,
}