mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-04-27 14:57:41 +00:00
Adds shell strategy to config fetch params to run command string in a shell
This commit is contained in:
parent
ec101b20d6
commit
4dd15716db
5 changed files with 17 additions and 3 deletions
|
|
@ -6,6 +6,7 @@ In alphabetical order:
|
||||||
- Ben Boeckel
|
- Ben Boeckel
|
||||||
- Christian Geier
|
- Christian Geier
|
||||||
- Clément Mondon
|
- Clément Mondon
|
||||||
|
- Corey Hinshaw
|
||||||
- Hugo Osvaldo Barrera
|
- Hugo Osvaldo Barrera
|
||||||
- Julian Mehne
|
- Julian Mehne
|
||||||
- Malte Kiefer
|
- Malte Kiefer
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ may want to subscribe to `GitHub's tag feed
|
||||||
Version 0.19.0
|
Version 0.19.0
|
||||||
==============
|
==============
|
||||||
|
|
||||||
|
- Add "shell" password fetch strategy to pass command string to a shell.
|
||||||
- Add "description" and "order" as metadata. These fetch the CalDAV:
|
- Add "description" and "order" as metadata. These fetch the CalDAV:
|
||||||
calendar-description, CardDAV:addressbook-description and apple-ns:calendar-order
|
calendar-description, CardDAV:addressbook-description and apple-ns:calendar-order
|
||||||
properties.
|
properties.
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,12 @@ You can fetch the username as well::
|
||||||
|
|
||||||
Or really any kind of parameter in a storage section.
|
Or really any kind of parameter in a storage section.
|
||||||
|
|
||||||
|
You can also pass the command as a string to be executed in a shell::
|
||||||
|
|
||||||
|
[storage foo]
|
||||||
|
...
|
||||||
|
password.fetch = ["shell", "~/.local/bin/get-my-password | head -n1"]
|
||||||
|
|
||||||
With pass_ for example, you might find yourself writing something like this in
|
With pass_ for example, you might find yourself writing something like this in
|
||||||
your configuration file::
|
your configuration file::
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ def test_get_password_from_command(tmpdir, runner):
|
||||||
collections = ["a", "b", "c"]
|
collections = ["a", "b", "c"]
|
||||||
|
|
||||||
[storage foo]
|
[storage foo]
|
||||||
type = "filesystem"
|
type.fetch = ["shell", "echo filesystem"]
|
||||||
path = "{base}/foo/"
|
path = "{base}/foo/"
|
||||||
fileext.fetch = ["command", "echo", ".txt"]
|
fileext.fetch = ["command", "echo", ".txt"]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ def _fetch_value(opts, key):
|
||||||
return rv
|
return rv
|
||||||
|
|
||||||
|
|
||||||
def _strategy_command(*command: str):
|
def _strategy_command(*command: str, shell: bool = False):
|
||||||
"""Execute a user-specified command and return its output."""
|
"""Execute a user-specified command and return its output."""
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
|
@ -82,18 +82,24 @@ def _strategy_command(*command: str):
|
||||||
expanded_command = list(map(expand_path, command))
|
expanded_command = list(map(expand_path, command))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
stdout = subprocess.check_output(expanded_command, universal_newlines=True)
|
stdout = subprocess.check_output(expanded_command, universal_newlines=True, shell=shell)
|
||||||
return stdout.strip("\n")
|
return stdout.strip("\n")
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
cmd = " ".join(expanded_command)
|
cmd = " ".join(expanded_command)
|
||||||
raise exceptions.UserError(f"Failed to execute command: {cmd}\n{str(e)}")
|
raise exceptions.UserError(f"Failed to execute command: {cmd}\n{str(e)}")
|
||||||
|
|
||||||
|
|
||||||
|
def _strategy_shell(*command: str):
|
||||||
|
"""Execute a user-specified command string in a shell and return its output."""
|
||||||
|
return _strategy_command(*command, shell=True)
|
||||||
|
|
||||||
|
|
||||||
def _strategy_prompt(text):
|
def _strategy_prompt(text):
|
||||||
return click.prompt(text, hide_input=True)
|
return click.prompt(text, hide_input=True)
|
||||||
|
|
||||||
|
|
||||||
STRATEGIES = {
|
STRATEGIES = {
|
||||||
"command": _strategy_command,
|
"command": _strategy_command,
|
||||||
|
"shell": _strategy_shell,
|
||||||
"prompt": _strategy_prompt,
|
"prompt": _strategy_prompt,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue