From c56b7041e42a6acb70ffb8ca20fefac58b2afb2b Mon Sep 17 00:00:00 2001 From: Weidows Date: Thu, 13 Oct 2022 22:23:49 +0800 Subject: [PATCH 1/2] fix encoding & add session param --- bw_add_sshkeys.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/bw_add_sshkeys.py b/bw_add_sshkeys.py index 3c502ce..4d0401a 100755 --- a/bw_add_sshkeys.py +++ b/bw_add_sshkeys.py @@ -56,12 +56,13 @@ def cli_supports(feature: str) -> bool: return False -def get_session() -> str: +def get_session(session: str) -> str: """ Function to return a valid Bitwarden session """ # Check for an existing, user-supplied Bitwarden session - session = os.environ.get('BW_SESSION', '') + if not session: + session = os.environ.get('BW_SESSION', '') if session: logging.debug('Existing Bitwarden session found') return session @@ -101,6 +102,7 @@ def get_folders(session: str, foldername: str) -> str: stdout=subprocess.PIPE, universal_newlines=True, check=True, + encoding = "utf-8", ) folders = json.loads(proc_folders.stdout) @@ -128,6 +130,7 @@ def folder_items(session: str, folder_id: str) -> List[Dict[str, Any]]: stdout=subprocess.PIPE, universal_newlines=True, check=True, + encoding = "utf-8", ) data: List[Dict[str, Any]] = json.loads(proc_items.stdout) @@ -270,6 +273,12 @@ if __name__ == '__main__': default='passphrase', help='custom field name where key passphrase is stored', ) + parser.add_argument( + '-s', + '--session', + default='', + help='session key of bitwarden', + ) return parser.parse_args() @@ -289,7 +298,7 @@ if __name__ == '__main__': try: logging.info('Getting Bitwarden session') - session = get_session() + session = get_session(args.session) logging.debug('Session = %s', session) logging.info('Getting folder list') From fc5a20f8d8fdc2604d63045935a0ea22ab3350b4 Mon Sep 17 00:00:00 2001 From: Weidows Date: Thu, 13 Oct 2022 22:26:22 +0800 Subject: [PATCH 2/2] updadte README --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 85940e9..cc7b680 100644 --- a/README.md +++ b/README.md @@ -27,4 +27,5 @@ Fetches SSH keys stored in Bitwarden vault and adds them to `ssh-agent`. * `--debug`/`-d` - Show debug output * `--foldername`/`-f` - Folder name to use to search for SSH keys _(default: ssh-agent)_ * `--customfield`/`-c` - Custom field name where private key filename is stored _(default: private)_ -* `--passphrasefield`/`-p` - Custom field name where passphrase for the key is stored _(default: passphrase)_ \ No newline at end of file +* `--passphrasefield`/`-p` - Custom field name where passphrase for the key is stored _(default: passphrase)_ +* `--session`/`-s` - session key of bitwarden