Skip to content

Commit 4af3c30

Browse files
Update core to version 3d49ce29
1 parent 1f09bb0 commit 4af3c30

File tree

15 files changed

+807
-86
lines changed

15 files changed

+807
-86
lines changed

src/onepassword/__init__.py

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

3-
from .client import Client
3+
from .client import Client, DesktopAuth
44
from .defaults import DEFAULT_INTEGRATION_NAME, DEFAULT_INTEGRATION_VERSION
55
from .types import * # noqa F403
66
from .errors import * # noqa F403
77
from .secrets import Secrets
88
from .items import Items
99
from .vaults import Vaults
10+
from .groups import Groups
1011

1112

1213
import sys
@@ -18,6 +19,8 @@
1819
"Secrets",
1920
"Items",
2021
"Vaults",
22+
"Groups",
23+
"DesktopAuth",
2124
"DEFAULT_INTEGRATION_NAME",
2225
"DEFAULT_INTEGRATION_VERSION",
2326
]

src/onepassword/client.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,48 @@
22

33
from __future__ import annotations
44
import weakref
5-
from .core import _init_client, _release_client
6-
from .defaults import new_default_config
5+
from .core import UniffiCore, InnerClient
6+
from .desktop_core import DesktopCore
7+
from .defaults import new_default_config, DesktopAuth
78
from .secrets import Secrets
89
from .items import Items
910
from .vaults import Vaults
11+
from .groups import Groups
1012

1113

1214
class Client:
1315
secrets: Secrets
1416
items: Items
1517
vaults: Vaults
18+
groups: Groups
1619

1720
@classmethod
1821
async def authenticate(
19-
cls, auth: str, integration_name: str, integration_version: str
22+
cls, auth: str | DesktopAuth, integration_name: str, integration_version: str
2023
) -> Client:
2124
config = new_default_config(
22-
auth=auth or "",
25+
auth=auth,
2326
integration_name=integration_name,
2427
integration_version=integration_version,
2528
)
2629

27-
client_id = int(await _init_client(config))
30+
if isinstance(auth, DesktopAuth):
31+
core = DesktopCore(auth.account_name)
32+
else:
33+
core = UniffiCore()
34+
35+
client_id = int(await core.init_client(config))
36+
37+
inner_client = InnerClient(client_id, core, config)
2838

2939
authenticated_client = cls()
3040

31-
authenticated_client.secrets = Secrets(client_id)
32-
authenticated_client.items = Items(client_id)
33-
authenticated_client.vaults = Vaults(client_id)
41+
authenticated_client.secrets = Secrets(inner_client)
42+
authenticated_client.items = Items(inner_client)
43+
authenticated_client.vaults = Vaults(inner_client)
44+
authenticated_client.groups = Groups(inner_client)
3445
authenticated_client._finalizer = weakref.finalize(
35-
cls, _release_client, client_id
46+
cls, core.release_client, client_id
3647
)
3748

3849
return authenticated_client

src/onepassword/errors.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
import json
44

55

6+
class DesktopSessionExpiredException(Exception):
7+
def __init__(self, message):
8+
self.message = message
9+
super().__init__(self.message)
10+
11+
612
class RateLimitExceededException(Exception):
713
def __init__(self, message):
814
self.message = message
@@ -18,7 +24,9 @@ def raise_typed_exception(e: Exception):
1824
error_name = typed_error.get("name")
1925
message = typed_error.get("message")
2026

21-
if error_name == "RateLimitExceeded":
27+
if error_name == "DesktopSessionExpired":
28+
raise DesktopSessionExpiredException(message)
29+
elif error_name == "RateLimitExceeded":
2230
raise RateLimitExceededException(message)
2331
elif message is not None:
2432
raise Exception(message)

src/onepassword/groups.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Code generated by op-codegen - DO NO EDIT MANUALLY
2+
3+
from .core import InnerClient
4+
from pydantic import TypeAdapter
5+
from .types import Group, GroupGetParams
6+
7+
8+
class Groups:
9+
"""
10+
The Groups API holds all the operations the SDK client can perform on 1Password groups.
11+
"""
12+
13+
def __init__(self, inner_client: InnerClient):
14+
self.inner_client = inner_client
15+
16+
async def get(self, group_id: str, group_params: GroupGetParams) -> Group:
17+
"""
18+
Get a group by its ID and parameters.
19+
"""
20+
response = await self.inner_client.invoke(
21+
{
22+
"invocation": {
23+
"clientId": self.inner_client.client_id,
24+
"parameters": {
25+
"name": "GroupsGet",
26+
"parameters": {
27+
"group_id": group_id,
28+
"group_params": group_params.model_dump(by_alias=True),
29+
},
30+
},
31+
}
32+
}
33+
)
34+
35+
response = TypeAdapter(Group).validate_json(response)
36+
return response

src/onepassword/items.py

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

3-
from .core import _invoke, _invoke_sync
4-
from typing import Optional, List
3+
from .core import InnerClient
4+
from typing import List
55
from pydantic import TypeAdapter
66
from .items_shares import ItemsShares
77
from .items_files import ItemsFiles
8-
from .types import Item, ItemCreateParams, ItemListFilter, ItemOverview
8+
from .types import (
9+
Item,
10+
ItemCreateParams,
11+
ItemListFilter,
12+
ItemOverview,
13+
ItemsDeleteAllResponse,
14+
ItemsGetAllResponse,
15+
ItemsUpdateAllResponse,
16+
)
917

1018

1119
class Items:
1220
"""
1321
The Items API holds all operations the SDK client can perform on 1Password items.
1422
"""
1523

16-
def __init__(self, client_id):
17-
self.client_id = client_id
18-
self.shares = ItemsShares(client_id)
19-
20-
self.files = ItemsFiles(client_id)
24+
def __init__(self, inner_client: InnerClient):
25+
self.inner_client = inner_client
26+
self.shares = ItemsShares(inner_client)
27+
self.files = ItemsFiles(inner_client)
2128

2229
async def create(self, params: ItemCreateParams) -> Item:
2330
"""
2431
Create a new item.
2532
"""
26-
response = await _invoke(
33+
response = await self.inner_client.invoke(
2734
{
2835
"invocation": {
29-
"clientId": self.client_id,
36+
"clientId": self.inner_client.client_id,
3037
"parameters": {
3138
"name": "ItemsCreate",
3239
"parameters": {"params": params.model_dump(by_alias=True)},
@@ -38,14 +45,38 @@ async def create(self, params: ItemCreateParams) -> Item:
3845
response = TypeAdapter(Item).validate_json(response)
3946
return response
4047

48+
async def create_all(
49+
self, vault_id: str, params: List[ItemCreateParams]
50+
) -> ItemsUpdateAllResponse:
51+
"""
52+
Create items in batch, within a single vault.
53+
"""
54+
response = await self.inner_client.invoke(
55+
{
56+
"invocation": {
57+
"clientId": self.inner_client.client_id,
58+
"parameters": {
59+
"name": "ItemsCreateAll",
60+
"parameters": {
61+
"vault_id": vault_id,
62+
"params": [o.model_dump(by_alias=True) for o in params],
63+
},
64+
},
65+
}
66+
}
67+
)
68+
69+
response = TypeAdapter(ItemsUpdateAllResponse).validate_json(response)
70+
return response
71+
4172
async def get(self, vault_id: str, item_id: str) -> Item:
4273
"""
43-
Get an item by vault and item ID
74+
Get an item by vault and item ID.
4475
"""
45-
response = await _invoke(
76+
response = await self.inner_client.invoke(
4677
{
4778
"invocation": {
48-
"clientId": self.client_id,
79+
"clientId": self.inner_client.client_id,
4980
"parameters": {
5081
"name": "ItemsGet",
5182
"parameters": {"vault_id": vault_id, "item_id": item_id},
@@ -57,14 +88,33 @@ async def get(self, vault_id: str, item_id: str) -> Item:
5788
response = TypeAdapter(Item).validate_json(response)
5889
return response
5990

91+
async def get_all(self, vault_id: str, item_ids: List[str]) -> ItemsGetAllResponse:
92+
"""
93+
Get items by vault and their item IDs.
94+
"""
95+
response = await self.inner_client.invoke(
96+
{
97+
"invocation": {
98+
"clientId": self.inner_client.client_id,
99+
"parameters": {
100+
"name": "ItemsGetAll",
101+
"parameters": {"vault_id": vault_id, "item_ids": item_ids},
102+
},
103+
}
104+
}
105+
)
106+
107+
response = TypeAdapter(ItemsGetAllResponse).validate_json(response)
108+
return response
109+
60110
async def put(self, item: Item) -> Item:
61111
"""
62112
Update an existing item.
63113
"""
64-
response = await _invoke(
114+
response = await self.inner_client.invoke(
65115
{
66116
"invocation": {
67-
"clientId": self.client_id,
117+
"clientId": self.inner_client.client_id,
68118
"parameters": {
69119
"name": "ItemsPut",
70120
"parameters": {"item": item.model_dump(by_alias=True)},
@@ -80,10 +130,10 @@ async def delete(self, vault_id: str, item_id: str) -> None:
80130
"""
81131
Delete an item.
82132
"""
83-
response = await _invoke(
133+
response = await self.inner_client.invoke(
84134
{
85135
"invocation": {
86-
"clientId": self.client_id,
136+
"clientId": self.inner_client.client_id,
87137
"parameters": {
88138
"name": "ItemsDelete",
89139
"parameters": {"vault_id": vault_id, "item_id": item_id},
@@ -94,14 +144,35 @@ async def delete(self, vault_id: str, item_id: str) -> None:
94144

95145
return None
96146

147+
async def delete_all(
148+
self, vault_id: str, item_ids: List[str]
149+
) -> ItemsDeleteAllResponse:
150+
"""
151+
Delete items in batch, within a single vault.
152+
"""
153+
response = await self.inner_client.invoke(
154+
{
155+
"invocation": {
156+
"clientId": self.inner_client.client_id,
157+
"parameters": {
158+
"name": "ItemsDeleteAll",
159+
"parameters": {"vault_id": vault_id, "item_ids": item_ids},
160+
},
161+
}
162+
}
163+
)
164+
165+
response = TypeAdapter(ItemsDeleteAllResponse).validate_json(response)
166+
return response
167+
97168
async def archive(self, vault_id: str, item_id: str) -> None:
98169
"""
99170
Archive an item.
100171
"""
101-
response = await _invoke(
172+
response = await self.inner_client.invoke(
102173
{
103174
"invocation": {
104-
"clientId": self.client_id,
175+
"clientId": self.inner_client.client_id,
105176
"parameters": {
106177
"name": "ItemsArchive",
107178
"parameters": {"vault_id": vault_id, "item_id": item_id},
@@ -116,10 +187,10 @@ async def list(self, vault_id: str, *filters: ItemListFilter) -> List[ItemOvervi
116187
"""
117188
List items based on filters.
118189
"""
119-
response = await _invoke(
190+
response = await self.inner_client.invoke(
120191
{
121192
"invocation": {
122-
"clientId": self.client_id,
193+
"clientId": self.inner_client.client_id,
123194
"parameters": {
124195
"name": "ItemsList",
125196
"parameters": {

0 commit comments

Comments
 (0)