Skip to content

Commit a7b8bbc

Browse files
Update core to version a4d007e7 (#149)
* Update core to version a4d007e7 * Update core functions to raise typed errors --------- Co-authored-by: 1PasswordSDKBot <[email protected]>
1 parent dbc54b9 commit a7b8bbc

File tree

13 files changed

+71
-17
lines changed

13 files changed

+71
-17
lines changed

example/example.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ async def main():
172172
await client.items.delete(created_item.vault_id, updated_item.id)
173173
# [developer-docs.sdk.python.delete-item]-end
174174

175+
175176
## NOTE: this is in a separate function to avoid creating a new item
176177
## NOTE: just for the sake of archiving it. This is because the SDK
177178
## NOTE: only works with active items, so archiving and then deleting
@@ -207,14 +208,15 @@ async def share_item(client: Client, vault_id: str, item_id: str):
207208
item,
208209
policy,
209210
ItemShareParams(
210-
recipients = valid_recipients,
211-
expireAfter= ItemShareDuration.ONEHOUR,
212-
oneTimeOnly= False,
211+
recipients=valid_recipients,
212+
expireAfter=ItemShareDuration.ONEHOUR,
213+
oneTimeOnly=False,
213214
),
214215
)
215216

216217
print(share_link)
217218
# [developer-docs.sdk.python.item-share-create-share]-end
218219

220+
219221
if __name__ == "__main__":
220222
asyncio.run(main())

src/onepassword/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from .client import Client
44
from .defaults import DEFAULT_INTEGRATION_NAME, DEFAULT_INTEGRATION_VERSION
55
from .types import * # noqa F403
6+
from .errors import * # noqa F403
67
from .secrets import Secrets
78
from .items import Items
89
from .vaults import Vaults
@@ -32,3 +33,11 @@
3233
or type(obj) == typing._LiteralGenericAlias
3334
):
3435
__all__.append(name)
36+
37+
for name, obj in inspect.getmembers(sys.modules["onepassword.errors"]):
38+
# Add all classes defined in errors.py.
39+
if (
40+
inspect.isclass(obj)
41+
and inspect.getmodule(obj) == sys.modules["onepassword.errors"]
42+
):
43+
__all__.append(name)

src/onepassword/core.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import json
22
import platform
33

4+
from onepassword.errors import raise_typed_exception
5+
46

57
machine_arch = platform.machine().lower()
68

@@ -16,17 +18,26 @@
1618

1719
# InitClient creates a client instance in the current core module and returns its unique ID.
1820
async def _init_client(client_config):
19-
return await core.init_client(json.dumps(client_config))
21+
try:
22+
return await core.init_client(json.dumps(client_config))
23+
except Exception as e:
24+
raise_typed_exception(e)
2025

2126

2227
# Invoke calls specified business logic from the SDK core.
2328
async def _invoke(invoke_config):
24-
return await core.invoke(json.dumps(invoke_config))
29+
try:
30+
return await core.invoke(json.dumps(invoke_config))
31+
except Exception as e:
32+
raise_typed_exception(e)
2533

2634

2735
# Invoke calls specified business logic from the SDK core.
2836
def _invoke_sync(invoke_config):
29-
return core.invoke_sync(json.dumps(invoke_config))
37+
try:
38+
return core.invoke_sync(json.dumps(invoke_config))
39+
except Exception as e:
40+
raise_typed_exception(e)
3041

3142

3243
# ReleaseClient releases memory in the SDK core associated with the given client ID.

src/onepassword/errors.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Code generated by op-codegen - DO NO EDIT MANUALLY
2+
3+
import json
4+
5+
6+
class RateLimitExceededException(Exception):
7+
def __init__(self, message):
8+
self.message = message
9+
super().__init__(self.message)
10+
11+
12+
def raise_typed_exception(e: Exception):
13+
try:
14+
typed_error = json.loads(e.msg)
15+
except Exception:
16+
raise e
17+
18+
error_name = typed_error.get("name")
19+
message = typed_error.get("message")
20+
21+
if error_name == "RateLimitExceeded":
22+
raise RateLimitExceededException(message)
23+
elif message is not None:
24+
raise Exception(message)
25+
else:
26+
raise e

src/onepassword/items.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Code generated by op-codegen - DO NO EDIT MANUALLY
22

3-
from .core import _invoke
3+
from .core import _invoke, _invoke_sync
44
from .iterator import SDKIterator
5+
from typing import Optional, List
56
from pydantic import TypeAdapter
67
from .items_shares import ItemsShares
78
from .types import Item, ItemCreateParams, ItemOverview
@@ -73,7 +74,7 @@ async def put(self, item: Item) -> Item:
7374
response = TypeAdapter(Item).validate_json(response)
7475
return response
7576

76-
async def delete(self, vault_id: str, item_id: str):
77+
async def delete(self, vault_id: str, item_id: str) -> None:
7778
"""
7879
Delete an item.
7980
"""
@@ -91,7 +92,7 @@ async def delete(self, vault_id: str, item_id: str):
9192

9293
return None
9394

94-
async def archive(self, vault_id: str, item_id: str):
95+
async def archive(self, vault_id: str, item_id: str) -> None:
9596
"""
9697
Archive an item.
9798
"""
@@ -125,5 +126,5 @@ async def list_all(self, vault_id: str) -> SDKIterator[ItemOverview]:
125126
}
126127
)
127128

128-
response = TypeAdapter(list[ItemOverview]).validate_json(response)
129+
response = TypeAdapter(List[ItemOverview]).validate_json(response)
129130
return SDKIterator(response)

src/onepassword/items_shares.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Code generated by op-codegen - DO NO EDIT MANUALLY
22

3-
from .core import _invoke
3+
from .core import _invoke, _invoke_sync
4+
from .iterator import SDKIterator
5+
from typing import Optional, List
46
from pydantic import TypeAdapter
57
from .types import Item, ItemShareAccountPolicy, ItemShareParams, ValidRecipient
68

@@ -31,8 +33,8 @@ async def get_account_policy(
3133
return response
3234

3335
async def validate_recipients(
34-
self, policy: ItemShareAccountPolicy, recipients: list[str]
35-
) -> list[ValidRecipient]:
36+
self, policy: ItemShareAccountPolicy, recipients: List[str]
37+
) -> List[ValidRecipient]:
3638
"""
3739
Validate the recipients of an item sharing link.
3840
"""
@@ -51,7 +53,7 @@ async def validate_recipients(
5153
}
5254
)
5355

54-
response = TypeAdapter(list[ValidRecipient]).validate_json(response)
56+
response = TypeAdapter(List[ValidRecipient]).validate_json(response)
5557
return response
5658

5759
async def create(
-7.81 KB
Binary file not shown.
239 KB
Binary file not shown.
-28.8 KB
Binary file not shown.
184 KB
Binary file not shown.

0 commit comments

Comments
 (0)