Skip to content

Commit fc180d5

Browse files
Update core to version 7e6c0600
1 parent ef6be31 commit fc180d5

File tree

9 files changed

+244
-3
lines changed

9 files changed

+244
-3
lines changed

src/onepassword/items.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from typing import Optional, List
66
from pydantic import TypeAdapter
77
from .items_shares import ItemsShares
8+
from .items_files import ItemsFiles
89
from .types import Item, ItemCreateParams, ItemOverview
910

1011

@@ -17,6 +18,8 @@ def __init__(self, client_id):
1718
self.client_id = client_id
1819
self.shares = ItemsShares(client_id)
1920

21+
self.files = ItemsFiles(client_id)
22+
2023
async def create(self, params: ItemCreateParams) -> Item:
2124
"""
2225
Create a new item.

src/onepassword/items_files.py

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Code generated by op-codegen - DO NO EDIT MANUALLY
2+
3+
from .core import _invoke, _invoke_sync
4+
from .iterator import SDKIterator
5+
from typing import Optional, List
6+
from pydantic import TypeAdapter
7+
from .types import DocumentCreateParams, FileAttributes, FileCreateParams, Item
8+
9+
10+
class ItemsFiles:
11+
def __init__(self, client_id):
12+
self.client_id = client_id
13+
14+
async def attach(self, item: Item, file_params: FileCreateParams) -> Item:
15+
"""
16+
Attach files to Items
17+
"""
18+
response = await _invoke(
19+
{
20+
"invocation": {
21+
"clientId": self.client_id,
22+
"parameters": {
23+
"name": "ItemsFilesAttach",
24+
"parameters": {
25+
"item": item.model_dump(by_alias=True),
26+
"file_params": file_params.model_dump(by_alias=True),
27+
},
28+
},
29+
}
30+
}
31+
)
32+
33+
response = TypeAdapter(Item).validate_json(response)
34+
return response
35+
36+
async def read(self, vault_id: str, item_id: str, attr: FileAttributes) -> bytes:
37+
"""
38+
Read file content from the Item
39+
"""
40+
response = await _invoke(
41+
{
42+
"invocation": {
43+
"clientId": self.client_id,
44+
"parameters": {
45+
"name": "ItemsFilesRead",
46+
"parameters": {
47+
"vault_id": vault_id,
48+
"item_id": item_id,
49+
"attr": attr.model_dump(by_alias=True),
50+
},
51+
},
52+
}
53+
}
54+
)
55+
56+
response = bytes(TypeAdapter(List[int]).validate_json(response))
57+
return response
58+
59+
async def delete(self, item: Item, section_id: str, field_id: str) -> Item:
60+
"""
61+
Delete a field file from Item using the section and field IDs
62+
"""
63+
response = await _invoke(
64+
{
65+
"invocation": {
66+
"clientId": self.client_id,
67+
"parameters": {
68+
"name": "ItemsFilesDelete",
69+
"parameters": {
70+
"item": item.model_dump(by_alias=True),
71+
"section_id": section_id,
72+
"field_id": field_id,
73+
},
74+
},
75+
}
76+
}
77+
)
78+
79+
response = TypeAdapter(Item).validate_json(response)
80+
return response
81+
82+
async def replace_document(
83+
self, item: Item, doc_params: DocumentCreateParams
84+
) -> Item:
85+
"""
86+
Replace the document file within a document item
87+
"""
88+
response = await _invoke(
89+
{
90+
"invocation": {
91+
"clientId": self.client_id,
92+
"parameters": {
93+
"name": "ItemsFilesReplaceDocument",
94+
"parameters": {
95+
"item": item.model_dump(by_alias=True),
96+
"doc_params": doc_params.model_dump(by_alias=True),
97+
},
98+
},
99+
}
100+
}
101+
)
102+
103+
response = TypeAdapter(Item).validate_json(response)
104+
return response

src/onepassword/iterator.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Code generated by op-codegen - DO NOT EDIT MANUALLY
2+
13
import asyncio
24
from typing import AsyncIterator, Iterable, TypeVar
35

1.21 MB
Binary file not shown.
1.37 MB
Binary file not shown.
1.34 MB
Binary file not shown.
1.5 MB
Binary file not shown.
1.37 MB
Binary file not shown.

src/onepassword/types.py

Lines changed: 135 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,77 @@
55
from __future__ import annotations
66

77
from enum import Enum
8-
from pydantic import BaseModel, ConfigDict, Field
9-
from typing import List, Literal, Optional, Union
8+
from pydantic import BaseModel, BeforeValidator, ConfigDict, Field, PlainSerializer
9+
from typing import Annotated, List, Literal, Optional, Union
10+
11+
12+
def serialize_binary_data(value: bytes) -> list[int]:
13+
return list(value)
14+
15+
16+
def deserialize_binary_data(value):
17+
if isinstance(value, list):
18+
if all(isinstance(x, int) and 0 <= x <= 255 for x in value):
19+
return bytes(value)
20+
raise ValueError("All elements must be integers in the range 0-255 (u8).")
21+
elif isinstance(value, bytes):
22+
return value
23+
raise TypeError("Content must be a list of integers (0-255) or bytes.")
24+
25+
26+
class DocumentCreateParams(BaseModel):
27+
name: str
28+
"""
29+
the name of the file
30+
"""
31+
content: Annotated[
32+
bytes,
33+
BeforeValidator(deserialize_binary_data),
34+
PlainSerializer(serialize_binary_data),
35+
]
36+
"""
37+
the content of the file
38+
"""
39+
40+
41+
class FileAttributes(BaseModel):
42+
name: str
43+
"""
44+
The name of the file
45+
"""
46+
id: str
47+
"""
48+
The ID of the file retrieved from the server
49+
"""
50+
size: int
51+
"""
52+
The size of the file in bytes
53+
"""
54+
55+
56+
class FileCreateParams(BaseModel):
57+
model_config = ConfigDict(populate_by_name=True)
58+
59+
name: str
60+
"""
61+
the name of the file
62+
"""
63+
content: Annotated[
64+
bytes,
65+
BeforeValidator(deserialize_binary_data),
66+
PlainSerializer(serialize_binary_data),
67+
]
68+
"""
69+
the content of the file
70+
"""
71+
section_id: str = Field(alias="sectionId")
72+
"""
73+
the section id where the file should be stored
74+
"""
75+
field_id: str = Field(alias="fieldId")
76+
"""
77+
the field id where the file should be stored
78+
"""
1079

1180

1281
class GeneratePasswordResponse(BaseModel):
@@ -58,11 +127,15 @@ class ItemFieldType(str, Enum):
58127
TOTP = "Totp"
59128
EMAIL = "Email"
60129
REFERENCE = "Reference"
130+
SSHKEY = "SshKey"
131+
MENU = "Menu"
132+
MONTHYEAR = "MonthYear"
61133
UNSUPPORTED = "Unsupported"
62134

63135

64136
class ItemFieldDetailsTypes(str, Enum):
65137
OTP = "Otp"
138+
SSH_KEY = "SshKey"
66139

67140

68141
class ItemFieldDetailsOtp(BaseModel):
@@ -74,8 +147,17 @@ class ItemFieldDetailsOtp(BaseModel):
74147
content: OtpFieldDetails
75148

76149

150+
class ItemFieldDetailsSshKey(BaseModel):
151+
"""
152+
Computed SSH Key attributes
153+
"""
154+
155+
type: Literal[ItemFieldDetailsTypes.SSH_KEY] = ItemFieldDetailsTypes.SSH_KEY
156+
content: Optional[SshKeyAttributes]
157+
158+
77159
# Field type-specific attributes.
78-
ItemFieldDetails = ItemFieldDetailsOtp
160+
ItemFieldDetails = Union[ItemFieldDetailsOtp, ItemFieldDetailsSshKey]
79161

80162

81163
class ItemField(BaseModel):
@@ -167,6 +249,23 @@ class Website(BaseModel):
167249
"""
168250

169251

252+
class ItemFile(BaseModel):
253+
model_config = ConfigDict(populate_by_name=True)
254+
255+
attributes: FileAttributes
256+
"""
257+
the attributes of the file
258+
"""
259+
section_id: str = Field(alias="sectionId")
260+
"""
261+
the section id where the file should be stored
262+
"""
263+
field_id: str = Field(alias="fieldId")
264+
"""
265+
the field id where the file should be stored
266+
"""
267+
268+
170269
class Item(BaseModel):
171270
"""
172271
Represents a 1Password item.
@@ -214,6 +313,14 @@ class Item(BaseModel):
214313
"""
215314
The item's version
216315
"""
316+
files: List[ItemFile]
317+
"""
318+
The item's file fields
319+
"""
320+
document: Optional[FileAttributes] = Field(default=None)
321+
"""
322+
The document file for the Document item category
323+
"""
217324

218325

219326
class ItemCreateParams(BaseModel):
@@ -251,6 +358,14 @@ class ItemCreateParams(BaseModel):
251358
"""
252359
The websites used for autofilling for items of the Login and Password categories.
253360
"""
361+
files: Optional[List[FileCreateParams]] = Field(default=None)
362+
"""
363+
The item's files stored as fields
364+
"""
365+
document: Optional[DocumentCreateParams] = Field(default=None)
366+
"""
367+
The document file for the Document item category
368+
"""
254369

255370

256371
class ItemOverview(BaseModel):
@@ -453,6 +568,23 @@ class OtpFieldDetails(BaseModel):
453568
"""
454569

455570

571+
class SshKeyAttributes(BaseModel):
572+
model_config = ConfigDict(populate_by_name=True)
573+
574+
public_key: str = Field(alias="publicKey")
575+
"""
576+
The public part of the SSH Key
577+
"""
578+
fingerprint: str
579+
"""
580+
The fingerprint of the SSH Key
581+
"""
582+
key_type: str = Field(alias="keyType")
583+
"""
584+
The key type ("Ed25519" or "RSA, {length}-bit")
585+
"""
586+
587+
456588
class VaultOverview(BaseModel):
457589
"""
458590
Represents a decrypted 1Password vault.

0 commit comments

Comments
 (0)