wandera / 1password-client

Python wrapper for OnePassword CLI developed at Wandera.
MIT License
47 stars 25 forks source link

Add handling for fields with spaces #36

Closed traviscook21 closed 1 year ago

traviscook21 commented 2 years ago

Assuming a vault entry with ID "abc" and fields called "API Key" and "API Secret", the following command fails:

op.get_item("abc", ["API Key", "API Secret"])

The following traceback is thrown:

 File "/Users/traviscook/git_repos/money/.venv/lib/python3.10/site-packages/onepassword/client.py", line 333, in get_item
    item = json.loads(read_bash_return("op get item {} --fields {}".format(uuid, ",".join(fields))))
  File "/usr/local/Cellar/python@3.10/3.10.2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/usr/local/Cellar/python@3.10/3.10.2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/Cellar/python@3.10/3.10.2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

This occurs because the library ultimately sends this command:

op get item abc --fields API Key,API Secret

This isn't properly escaped for a shell. It should be:

op get item abc --fields "API Key,API Secret"

This commit fixes this behavior.

dtpryce commented 1 year ago

Hey @traviscook21 we just released 1.0.1 which is actually fully supporting v2 of the cli and app. It also meant a refresh of the client which I think might have fixed this issue. I will close this PR for now but please do try out the new client and raise it again if its still there! Thanks for your contribution, would love to see more!