Skip to content

Commit 5d79a84

Browse files
Update core to version d54569e1
1 parent ef6be31 commit 5d79a84

File tree

8 files changed

+217
-3
lines changed

8 files changed

+217
-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: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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 FileAttachParams, FileAttributes, 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: FileAttachParams) -> 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, file_id: str) -> Item:
60+
"""
61+
Delete files from Item
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+
"file_id": file_id,
72+
},
73+
},
74+
}
75+
}
76+
)
77+
78+
response = TypeAdapter(Item).validate_json(response)
79+
return response
1.18 MB
Binary file not shown.
1.36 MB
Binary file not shown.
1.29 MB
Binary file not shown.
1.46 MB
Binary file not shown.
1.31 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,92 @@
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 FilePositionFieldFileInner(BaseModel):
27+
"""
28+
Generated type representing the anonymous struct variant `FieldFile` of the `FilePosition` Rust enum
29+
"""
30+
31+
model_config = ConfigDict(populate_by_name=True)
32+
33+
section_id: str = Field(alias="sectionId")
34+
field_id: str = Field(alias="fieldId")
35+
36+
37+
class FilePositionTypes(str, Enum):
38+
DOCUMENT = "Document"
39+
FIELD_FILE = "FieldFile"
40+
41+
42+
class FilePositionDocument(BaseModel):
43+
"""
44+
The document file saved in a Document item (can only be used with items of Document category)
45+
"""
46+
47+
type: Literal[FilePositionTypes.DOCUMENT] = FilePositionTypes.DOCUMENT
48+
49+
50+
class FilePositionFieldFile(BaseModel):
51+
"""
52+
A file stored as an item field
53+
"""
54+
55+
type: Literal[FilePositionTypes.FIELD_FILE] = FilePositionTypes.FIELD_FILE
56+
content: FilePositionFieldFileInner
57+
58+
59+
FilePosition = Union[FilePositionDocument, FilePositionFieldFile]
60+
61+
62+
class FileAttachParams(BaseModel):
63+
name: str
64+
"""
65+
the name of the file
66+
"""
67+
content: Annotated[
68+
bytes,
69+
BeforeValidator(deserialize_binary_data),
70+
PlainSerializer(serialize_binary_data),
71+
]
72+
"""
73+
the content of the file
74+
"""
75+
position: FilePosition
76+
"""
77+
where the file is stored in the item
78+
"""
79+
80+
81+
class FileAttributes(BaseModel):
82+
name: str
83+
"""
84+
The name of the file
85+
"""
86+
id: str
87+
"""
88+
The ID of the file retrieved from the server
89+
"""
90+
size: int
91+
"""
92+
The size of the file in bytes
93+
"""
1094

1195

1296
class GeneratePasswordResponse(BaseModel):
@@ -58,11 +142,14 @@ class ItemFieldType(str, Enum):
58142
TOTP = "Totp"
59143
EMAIL = "Email"
60144
REFERENCE = "Reference"
145+
SSHKEY = "SshKey"
146+
MENU = "Menu"
61147
UNSUPPORTED = "Unsupported"
62148

63149

64150
class ItemFieldDetailsTypes(str, Enum):
65151
OTP = "Otp"
152+
SSH_KEY = "SshKey"
66153

67154

68155
class ItemFieldDetailsOtp(BaseModel):
@@ -74,8 +161,17 @@ class ItemFieldDetailsOtp(BaseModel):
74161
content: OtpFieldDetails
75162

76163

164+
class ItemFieldDetailsSshKey(BaseModel):
165+
"""
166+
Computed SSH Key attributes
167+
"""
168+
169+
type: Literal[ItemFieldDetailsTypes.SSH_KEY] = ItemFieldDetailsTypes.SSH_KEY
170+
content: Optional[SshKeyAttributes]
171+
172+
77173
# Field type-specific attributes.
78-
ItemFieldDetails = ItemFieldDetailsOtp
174+
ItemFieldDetails = Union[ItemFieldDetailsOtp, ItemFieldDetailsSshKey]
79175

80176

81177
class ItemField(BaseModel):
@@ -167,6 +263,17 @@ class Website(BaseModel):
167263
"""
168264

169265

266+
class ItemFile(BaseModel):
267+
attributes: FileAttributes
268+
"""
269+
the attributes of the file
270+
"""
271+
position: FilePosition
272+
"""
273+
where the file is stored in the item
274+
"""
275+
276+
170277
class Item(BaseModel):
171278
"""
172279
Represents a 1Password item.
@@ -214,6 +321,10 @@ class Item(BaseModel):
214321
"""
215322
The item's version
216323
"""
324+
files: List[ItemFile]
325+
"""
326+
The item's files
327+
"""
217328

218329

219330
class ItemCreateParams(BaseModel):
@@ -251,6 +362,10 @@ class ItemCreateParams(BaseModel):
251362
"""
252363
The websites used for autofilling for items of the Login and Password categories.
253364
"""
365+
files: Optional[List[FileAttachParams]] = Field(default=None)
366+
"""
367+
The item's files
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)