Skip to content

Commit 77e1222

Browse files
Update core to version d16c23e9
1 parent bfb4627 commit 77e1222

File tree

13 files changed

+160
-20
lines changed

13 files changed

+160
-20
lines changed

example/example.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ async def main():
5050
details=None,
5151
),
5252
],
53-
sections=[ItemSection(id="", title=""), ItemSection(id="totpsection", title="")],
53+
sections=[
54+
ItemSection(id="", title=""),
55+
ItemSection(id="totpsection", title=""),
56+
],
5457
)
5558
created_item = await client.items.create(to_create)
5659

@@ -64,7 +67,6 @@ async def main():
6467
else:
6568
print(f.details.content.code)
6669

67-
6870
# Retrieve an item from your vault.
6971
item = await client.items.get(created_item.vault_id, created_item.id)
7072

src/onepassword/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from .types import * # noqa F403
55
from .secrets import Secrets
66
from .items import Items
7+
from .vaults import Vaults
78

89

910
import sys
@@ -14,6 +15,7 @@
1415
"Client",
1516
"Secrets",
1617
"Items",
18+
"Vaults",
1719
"DEFAULT_INTEGRATION_NAME",
1820
"DEFAULT_INTEGRATION_VERSION",
1921
]

src/onepassword/client.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
from .defaults import new_default_config
55
from .secrets import Secrets
66
from .items import Items
7+
from .vaults import Vaults
78

89

910
class Client:
1011
secrets: Secrets
1112
items: Items
13+
vaults: Vaults
1214

1315
@classmethod
1416
async def authenticate(cls, auth, integration_name, integration_version):
@@ -23,6 +25,7 @@ async def authenticate(cls, auth, integration_name, integration_version):
2325

2426
authenticated_client.secrets = Secrets(client_id)
2527
authenticated_client.items = Items(client_id)
28+
authenticated_client.vaults = Vaults(client_id)
2629
authenticated_client._finalizer = weakref.finalize(
2730
cls, _release_client, client_id
2831
)

src/onepassword/items.py

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# AUTO-GENERATED
22
from .core import _invoke
33
from json import loads
4-
from .types import Item
4+
from .iterator import SDKIterator
5+
from .types import Item, ItemOverview
56

67

78
class Items:
@@ -20,9 +21,9 @@ async def create(self, params):
2021
{
2122
"clientId": self.client_id,
2223
"invocation": {
23-
"name": "Create",
24+
"name": "ItemsCreate",
2425
"parameters": {
25-
"params": params.dict(),
26+
"params": params.model_dump(by_alias=True),
2627
},
2728
},
2829
}
@@ -37,10 +38,10 @@ async def get(self, vault_id, item_id):
3738
{
3839
"clientId": self.client_id,
3940
"invocation": {
40-
"name": "Get",
41+
"name": "ItemsGet",
4142
"parameters": {
42-
"vault_id": vault_id,
4343
"item_id": item_id,
44+
"vault_id": vault_id,
4445
},
4546
},
4647
}
@@ -55,9 +56,9 @@ async def put(self, item):
5556
{
5657
"clientId": self.client_id,
5758
"invocation": {
58-
"name": "Put",
59+
"name": "ItemsPut",
5960
"parameters": {
60-
"item": item.dict(),
61+
"item": item.model_dump(by_alias=True),
6162
},
6263
},
6364
}
@@ -73,11 +74,32 @@ async def delete(self, vault_id, item_id):
7374
{
7475
"clientId": self.client_id,
7576
"invocation": {
76-
"name": "Delete",
77+
"name": "ItemsDelete",
7778
"parameters": {
78-
"vault_id": vault_id,
7979
"item_id": item_id,
80+
"vault_id": vault_id,
8081
},
8182
},
8283
}
8384
)
85+
86+
async def list_all(self, vault_id):
87+
"""
88+
List all items
89+
"""
90+
response = await _invoke(
91+
{
92+
"clientId": self.client_id,
93+
"invocation": {
94+
"name": "ItemsListAll",
95+
"parameters": {
96+
"vault_id": vault_id,
97+
},
98+
},
99+
}
100+
)
101+
response_data = loads(response)
102+
103+
objects = [ItemOverview(**data) for data in response_data]
104+
105+
return SDKIterator(objects)

src/onepassword/iterator.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import asyncio
2+
from typing import AsyncIterator, Iterable, TypeVar
3+
4+
T = TypeVar("T")
5+
6+
7+
class SDKIterator(AsyncIterator[T]):
8+
def __init__(self, obj: Iterable[T]):
9+
self.obj = obj
10+
self.index = 0
11+
self.lock = asyncio.Lock()
12+
13+
def __aiter__(self) -> AsyncIterator[T]:
14+
return self
15+
16+
async def __anext__(self) -> T:
17+
async with self.lock:
18+
if self.index >= len(self.obj):
19+
raise StopAsyncIteration
20+
21+
next_obj = self.obj[self.index]
22+
self.index += 1
23+
return next_obj
-7.93 MB
Binary file not shown.
-2.63 MB
Binary file not shown.
-8.44 MB
Binary file not shown.
-2.62 MB
Binary file not shown.
1.33 MB
Binary file not shown.

0 commit comments

Comments
 (0)