From fbd507f5e9e2e54f928b636db1844cde9aea6a8e Mon Sep 17 00:00:00 2001 From: Felipe Zipitria Date: Mon, 27 May 2024 11:47:03 -0300 Subject: [PATCH 1/2] feat: add support for otp fields Signed-off-by: Felipe Zipitria --- onepassword/client.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/onepassword/client.py b/onepassword/client.py index e9663c7..de14efe 100644 --- a/onepassword/client.py +++ b/onepassword/client.py @@ -445,3 +445,13 @@ def get_item(uuid: str | bytes, fields: str | bytes | list | None = None): else: item = json.loads(read_bash_return("op item get {} --format=json".format(uuid), single=False)) return item + + @staticmethod + def get_item_otp(uuid: str | bytes): + """ + Helper function to get the item otp, you can find the UUID you need using list_items + + :param uuid: Uuid of the item you wish to get, no vault needed + :return: the otp of the item, if it exists + """ + return read_bash_return("op item get {} --otp".format(uuid), single=False) From 5d3b8fab36229e63117550f6474fab25ae853102 Mon Sep 17 00:00:00 2001 From: David Pryce Date: Tue, 28 May 2024 12:38:12 +0100 Subject: [PATCH 2/2] fix: adding test and new line split --- onepassword/client.py | 2 +- test/test_client.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/onepassword/client.py b/onepassword/client.py index de14efe..7f5863c 100644 --- a/onepassword/client.py +++ b/onepassword/client.py @@ -454,4 +454,4 @@ def get_item_otp(uuid: str | bytes): :param uuid: Uuid of the item you wish to get, no vault needed :return: the otp of the item, if it exists """ - return read_bash_return("op item get {} --otp".format(uuid), single=False) + return read_bash_return("op item get {} --otp".format(uuid), single=False).rstrip('\n') diff --git a/test/test_client.py b/test/test_client.py index 89c6d3c..33234a3 100644 --- a/test/test_client.py +++ b/test/test_client.py @@ -111,6 +111,12 @@ def test_get_items(self): """ pass + def test_get_item_otp(self): + """ + Without user interaction will not be signed in and be unable to list anything + """ + pass + if __name__ == '__main__': unittest.main()