Skip to content

Commit

Permalink
Add prompt strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
untitaker committed Oct 4, 2015
1 parent d525408 commit 21b1baf
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
14 changes: 12 additions & 2 deletions docs/keyring.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
=======
Expand Down Expand Up @@ -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"]
8 changes: 5 additions & 3 deletions tests/cli/test_fetchparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -42,13 +42,15 @@ 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
assert 'bar' in status
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']
7 changes: 6 additions & 1 deletion vdirsyncer/cli/fetchparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

0 comments on commit 21b1baf

Please sign in to comment.