nncli

NextCloud Notes Command Line Interface
git clone git://git.danielmoch.com/nncli.git
Log | Files | Refs | LICENSE

commit 77d8568fb8faf4fd8d0d7edb50268df0ffda59d5
parent 875b08c6095118e9adbd5be470d3e29e5e49225a
Author: Samuel Walladge <samuel@swalladge.id.au>
Date:   Fri, 17 Nov 2017 18:28:16 +1030

add config to get password from external command

- add the `cfg_sn_password_eval` config option
- document in readme

Diffstat:
MREADME.md | 6++++++
Msimplenote_cli/config.py | 19+++++++++++++++++--
2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/README.md b/README.md @@ -139,6 +139,12 @@ See example configuration file below for more notes. cfg_sn_username = lebowski@thedude.com cfg_sn_password = nihilist +# as an alternate to cfg_sn_password you could use the following config item +# any shell command can be used; its stdout is used for the password +# trailing newlines are stripped for ease of use +# note: if both password config are given, cfg_sn_password will be used +cfg_sn_password_eval = gpg --quiet --for-your-eyes-only --no-tty --decrypt ~/.sncli-pass.gpg + # see http://urwid.org/manual/userinput.html for examples of more key combinations kb_edit_note = space kb_page_down = ctrl f diff --git a/simplenote_cli/config.py b/simplenote_cli/config.py @@ -2,7 +2,7 @@ # Copyright (c) 2014 Eric Davis # Licensed under the MIT License -import os, urwid, collections, configparser +import os, sys, urwid, collections, configparser, subprocess class Config: @@ -132,11 +132,26 @@ def __init__(self, custom_file=None): if not cp.has_section(cfg_sec): cp.add_section(cfg_sec) + + # special handling for password so we can retrieve it by running a command + sn_password = cp.get(cfg_sec, 'cfg_sn_password', raw=True) + if not sn_password: + command = cp.get(cfg_sec, 'cfg_sn_password_eval', raw=True) + if command: + try: + sn_password = subprocess.check_output(command, shell=True, universal_newlines=True) + # remove trailing newlines to avoid requiring butchering shell commands (they can't usually be in passwords anyway) + sn_password = sn_password.rstrip('\n') + except subprocess.CalledProcessError as e: + print('Error evaluating command for password.') + print(e) + sys.exit(1) + # ordered dicts used to ease help self.configs = collections.OrderedDict() self.configs['sn_username'] = [ cp.get(cfg_sec, 'cfg_sn_username', raw=True), 'Simplenote Username' ] - self.configs['sn_password'] = [ cp.get(cfg_sec, 'cfg_sn_password', raw=True), 'Simplenote Password' ] + self.configs['sn_password'] = [ sn_password, 'Simplenote Password' ] self.configs['sn_host'] = [ cp.get(cfg_sec, 'cfg_sn_host', raw=True), 'Simplenote server hostname' ] self.configs['db_path'] = [ cp.get(cfg_sec, 'cfg_db_path'), 'Note storage path' ] self.configs['search_tags'] = [ cp.get(cfg_sec, 'cfg_search_tags'), 'Search tags as well' ]