From 21b1bafc483e1065133c0f8ed5a7f18685a2a1ae Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Sun, 4 Oct 2015 13:30:40 +0200 Subject: [PATCH] Add prompt strategy --- docs/keyring.rst | 14 ++++++++++++-- tests/cli/test_fetchparams.py | 8 +++++--- vdirsyncer/cli/fetchparams.py | 7 ++++++- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/docs/keyring.rst b/docs/keyring.rst index 4ba9d1b..a0f60df 100644 --- a/docs/keyring.rst +++ b/docs/keyring.rst @@ -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"] diff --git a/tests/cli/test_fetchparams.py b/tests/cli/test_fetchparams.py index e2391f7..0f71dff 100644 --- a/tests/cli/test_fetchparams.py +++ b/tests/cli/test_fetchparams.py @@ -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'] diff --git a/vdirsyncer/cli/fetchparams.py b/vdirsyncer/cli/fetchparams.py index cbd76b8..9623d7a 100644 --- a/vdirsyncer/cli/fetchparams.py +++ b/vdirsyncer/cli/fetchparams.py @@ -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, }