Skip to content

Commit f1bdebd

Browse files
committed
Add item sharing functionality
1 parent 5aedbae commit f1bdebd

File tree

7 files changed

+376
-23
lines changed

7 files changed

+376
-23
lines changed

src/onepassword/client.py

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

3+
from __future__ import annotations
34
import weakref
45
from .core import _init_client, _release_client
56
from .defaults import new_default_config
@@ -14,7 +15,9 @@ class Client:
1415
vaults: Vaults
1516

1617
@classmethod
17-
async def authenticate(cls, auth, integration_name, integration_version):
18+
async def authenticate(
19+
cls, auth: str, integration_name: str, integration_version: str
20+
) -> Client:
1821
config = new_default_config(
1922
auth=auth or "",
2023
integration_name=integration_name,

src/onepassword/items.py

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
from .core import _invoke, _invoke_sync
44
from json import loads
55
from .iterator import SDKIterator
6-
from .types import Item, ItemOverview
6+
from .items_share import ItemsShare
7+
from .types import Item, ItemCreateParams, ItemOverview, Option
78

89

910
class Items:
@@ -13,8 +14,9 @@ class Items:
1314

1415
def __init__(self, client_id):
1516
self.client_id = client_id
17+
self.share = ItemsShare(client_id)
1618

17-
async def create(self, params):
19+
async def create(self, params: ItemCreateParams) -> Item:
1820
"""
1921
Create a new item
2022
"""
@@ -31,7 +33,7 @@ async def create(self, params):
3133
)
3234
return Item.model_validate_json(response)
3335

34-
async def get(self, vault_id, item_id):
36+
async def get(self, vault_id: str, item_id: str) -> Item:
3537
"""
3638
Get an item by vault and item ID
3739
"""
@@ -48,7 +50,27 @@ async def get(self, vault_id, item_id):
4850
)
4951
return Item.model_validate_json(response)
5052

51-
async def put(self, item):
53+
async def get_all(self, vault_id: str, item_ids: list[str]) -> list[Option]:
54+
"""
55+
Get items by vault and their item IDs.
56+
"""
57+
response = await _invoke(
58+
{
59+
"invocation": {
60+
"clientId": self.client_id,
61+
"parameters": {
62+
"name": "ItemsGetAll",
63+
"parameters": {"vault_id": vault_id, "item_ids": item_ids},
64+
},
65+
}
66+
}
67+
)
68+
69+
response = loads(response)
70+
response = [Option.model_validate(data) for data in response]
71+
return response
72+
73+
async def put(self, item: Item) -> Item:
5274
"""
5375
Update an existing item.
5476
"""
@@ -65,7 +87,7 @@ async def put(self, item):
6587
)
6688
return Item.model_validate_json(response)
6789

68-
async def delete(self, vault_id, item_id):
90+
async def delete(self, vault_id: str, item_id: str):
6991
"""
7092
Delete an item.
7193
"""
@@ -81,7 +103,23 @@ async def delete(self, vault_id, item_id):
81103
}
82104
)
83105

84-
async def list_all(self, vault_id):
106+
async def archive(self, vault_id: str, item_id: str):
107+
"""
108+
Archive an item.
109+
"""
110+
await _invoke(
111+
{
112+
"invocation": {
113+
"clientId": self.client_id,
114+
"parameters": {
115+
"name": "ItemsArchive",
116+
"parameters": {"vault_id": vault_id, "item_id": item_id},
117+
},
118+
}
119+
}
120+
)
121+
122+
async def list_all(self, vault_id: str) -> SDKIterator[ItemOverview]:
85123
"""
86124
List all items
87125
"""
@@ -97,8 +135,6 @@ async def list_all(self, vault_id):
97135
}
98136
)
99137

100-
response_data = loads(response)
101-
102-
objects = [ItemOverview.model_validate(data) for data in response_data]
103-
104-
return SDKIterator(objects)
138+
response = loads(response)
139+
response = [ItemOverview.model_validate(data) for data in response]
140+
return SDKIterator(response)

src/onepassword/items_share.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Code generated by op-codegen - DO NO EDIT MANUALLY
2+
3+
from .core import _invoke, _invoke_sync
4+
from json import loads
5+
from .iterator import SDKIterator
6+
from .types import Item, ItemsShareAccountPolicy, ItemsShareParams, ValidRecipient
7+
8+
9+
class ItemsShare:
10+
def __init__(self, client_id):
11+
self.client_id = client_id
12+
13+
async def get_account_policy(
14+
self, vault_id: str, item_id: str
15+
) -> ItemsShareAccountPolicy:
16+
response = await _invoke(
17+
{
18+
"invocation": {
19+
"clientId": self.client_id,
20+
"parameters": {
21+
"name": "ItemsShareGetAccountPolicy",
22+
"parameters": {"vault_id": vault_id, "item_id": item_id},
23+
},
24+
}
25+
}
26+
)
27+
return ItemsShareAccountPolicy.model_validate_json(response)
28+
29+
async def validate_recipients(
30+
self, policy: ItemsShareAccountPolicy, recipients: list[str]
31+
) -> list[ValidRecipient]:
32+
response = await _invoke(
33+
{
34+
"invocation": {
35+
"clientId": self.client_id,
36+
"parameters": {
37+
"name": "ItemsShareValidateRecipients",
38+
"parameters": {
39+
"policy": policy.model_dump(by_alias=True),
40+
"recipients": recipients,
41+
},
42+
},
43+
}
44+
}
45+
)
46+
47+
response = loads(response)
48+
response = [ValidRecipient.model_validate(data) for data in response]
49+
return response
50+
51+
async def create(
52+
self, item: Item, policy: ItemsShareAccountPolicy, params: ItemsShareParams
53+
) -> str:
54+
response = await _invoke(
55+
{
56+
"invocation": {
57+
"clientId": self.client_id,
58+
"parameters": {
59+
"name": "ItemsShareCreate",
60+
"parameters": {
61+
"item": item.model_dump(by_alias=True),
62+
"policy": policy.model_dump(by_alias=True),
63+
"params": params.model_dump(by_alias=True),
64+
},
65+
},
66+
}
67+
}
68+
)
69+
return str(loads(response))
1.05 MB
Binary file not shown.

src/onepassword/secrets.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from .core import _invoke, _invoke_sync
44
from json import loads
55
from .iterator import SDKIterator
6-
from .types import GeneratePasswordResponse
6+
from .types import GeneratePasswordResponse, PasswordRecipe
77

88

99
class Secrets:
@@ -15,7 +15,7 @@ class Secrets:
1515
def __init__(self, client_id):
1616
self.client_id = client_id
1717

18-
async def resolve(self, secret_reference):
18+
async def resolve(self, secret_reference: str) -> str:
1919
"""
2020
Resolve returns the secret the provided secret reference points to.
2121
"""
@@ -33,7 +33,7 @@ async def resolve(self, secret_reference):
3333
return str(loads(response))
3434

3535
@staticmethod
36-
def validate_secret_reference(secret_reference):
36+
def validate_secret_reference(secret_reference: str):
3737
"""
3838
Validate the secret reference to ensure there are no syntax errors.
3939
"""
@@ -49,7 +49,7 @@ def validate_secret_reference(secret_reference):
4949
)
5050

5151
@staticmethod
52-
def generate_password(recipe):
52+
def generate_password(recipe: PasswordRecipe) -> GeneratePasswordResponse:
5353
response = _invoke_sync(
5454
{
5555
"invocation": {

0 commit comments

Comments
 (0)