Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/onepassword/items.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Code generated by op-codegen - DO NO EDIT MANUALLY

from .core import _invoke, _invoke_sync

Check failure on line 3 in src/onepassword/items.py

View workflow job for this annotation

GitHub Actions / Lint

src/onepassword/items.py:3:28: F401 `.core._invoke_sync` imported but unused

Check failure on line 3 in src/onepassword/items.py

View workflow job for this annotation

GitHub Actions / Lint

src/onepassword/items.py:3:28: F401 `.core._invoke_sync` imported but unused
from .iterator import SDKIterator
from typing import Optional, List

Check failure on line 5 in src/onepassword/items.py

View workflow job for this annotation

GitHub Actions / Lint

src/onepassword/items.py:5:20: F401 `typing.Optional` imported but unused

Check failure on line 5 in src/onepassword/items.py

View workflow job for this annotation

GitHub Actions / Lint

src/onepassword/items.py:5:20: F401 `typing.Optional` imported but unused
from pydantic import TypeAdapter
from .items_shares import ItemsShares
from .items_files import ItemsFiles
from .types import Item, ItemCreateParams, ItemOverview


Expand All @@ -17,6 +18,8 @@
self.client_id = client_id
self.shares = ItemsShares(client_id)

self.files = ItemsFiles(client_id)

async def create(self, params: ItemCreateParams) -> Item:
"""
Create a new item.
Expand Down Expand Up @@ -78,7 +81,7 @@
"""
Delete an item.
"""
response = await _invoke(

Check failure on line 84 in src/onepassword/items.py

View workflow job for this annotation

GitHub Actions / Lint

src/onepassword/items.py:84:9: F841 Local variable `response` is assigned to but never used

Check failure on line 84 in src/onepassword/items.py

View workflow job for this annotation

GitHub Actions / Lint

src/onepassword/items.py:84:9: F841 Local variable `response` is assigned to but never used
{
"invocation": {
"clientId": self.client_id,
Expand All @@ -96,7 +99,7 @@
"""
Archive an item.
"""
response = await _invoke(

Check failure on line 102 in src/onepassword/items.py

View workflow job for this annotation

GitHub Actions / Lint

src/onepassword/items.py:102:9: F841 Local variable `response` is assigned to but never used

Check failure on line 102 in src/onepassword/items.py

View workflow job for this annotation

GitHub Actions / Lint

src/onepassword/items.py:102:9: F841 Local variable `response` is assigned to but never used
{
"invocation": {
"clientId": self.client_id,
Expand Down
79 changes: 79 additions & 0 deletions src/onepassword/items_files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Code generated by op-codegen - DO NO EDIT MANUALLY

from .core import _invoke, _invoke_sync

Check failure on line 3 in src/onepassword/items_files.py

View workflow job for this annotation

GitHub Actions / Lint

src/onepassword/items_files.py:3:28: F401 `.core._invoke_sync` imported but unused

Check failure on line 3 in src/onepassword/items_files.py

View workflow job for this annotation

GitHub Actions / Lint

src/onepassword/items_files.py:3:28: F401 `.core._invoke_sync` imported but unused
from .iterator import SDKIterator

Check failure on line 4 in src/onepassword/items_files.py

View workflow job for this annotation

GitHub Actions / Lint

src/onepassword/items_files.py:4:23: F401 `.iterator.SDKIterator` imported but unused

Check failure on line 4 in src/onepassword/items_files.py

View workflow job for this annotation

GitHub Actions / Lint

src/onepassword/items_files.py:4:23: F401 `.iterator.SDKIterator` imported but unused
from typing import Optional, List

Check failure on line 5 in src/onepassword/items_files.py

View workflow job for this annotation

GitHub Actions / Lint

src/onepassword/items_files.py:5:20: F401 `typing.Optional` imported but unused

Check failure on line 5 in src/onepassword/items_files.py

View workflow job for this annotation

GitHub Actions / Lint

src/onepassword/items_files.py:5:20: F401 `typing.Optional` imported but unused
from pydantic import TypeAdapter
from .types import FileAttachParams, FileAttributes, Item


class ItemsFiles:
def __init__(self, client_id):
self.client_id = client_id

async def attach(self, item: Item, file_params: FileAttachParams) -> Item:
"""
Attach files to Items
"""
response = await _invoke(
{
"invocation": {
"clientId": self.client_id,
"parameters": {
"name": "ItemsFilesAttach",
"parameters": {
"item": item.model_dump(by_alias=True),
"file_params": file_params.model_dump(by_alias=True),
},
},
}
}
)

response = TypeAdapter(Item).validate_json(response)
return response

async def read(self, vault_id: str, item_id: str, attr: FileAttributes) -> bytes:
"""
Read file content from the Item
"""
response = await _invoke(
{
"invocation": {
"clientId": self.client_id,
"parameters": {
"name": "ItemsFilesRead",
"parameters": {
"vault_id": vault_id,
"item_id": item_id,
"attr": attr.model_dump(by_alias=True),
},
},
}
}
)

response = bytes(TypeAdapter(List[int]).validate_json(response))
return response

async def delete(self, item: Item, file_id: str) -> Item:
"""
Delete files from Item
"""
response = await _invoke(
{
"invocation": {
"clientId": self.client_id,
"parameters": {
"name": "ItemsFilesDelete",
"parameters": {
"item": item.model_dump(by_alias=True),
"file_id": file_id,
},
},
}
}
)

response = TypeAdapter(Item).validate_json(response)
return response
Binary file modified src/onepassword/lib/aarch64/libop_uniffi_core.dylib
Binary file not shown.
Binary file modified src/onepassword/lib/aarch64/libop_uniffi_core.so
Binary file not shown.
Binary file modified src/onepassword/lib/x86_64/libop_uniffi_core.dylib
Binary file not shown.
Binary file modified src/onepassword/lib/x86_64/libop_uniffi_core.so
Binary file not shown.
Binary file modified src/onepassword/lib/x86_64/op_uniffi_core.dll
Binary file not shown.
138 changes: 135 additions & 3 deletions src/onepassword/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,92 @@
from __future__ import annotations

from enum import Enum
from pydantic import BaseModel, ConfigDict, Field
from typing import List, Literal, Optional, Union
from pydantic import BaseModel, BeforeValidator, ConfigDict, Field, PlainSerializer
from typing import Annotated, List, Literal, Optional, Union


def serialize_binary_data(value: bytes) -> list[int]:
return list(value)


def deserialize_binary_data(value):
if isinstance(value, list):
if all(isinstance(x, int) and 0 <= x <= 255 for x in value):
return bytes(value)
raise ValueError("All elements must be integers in the range 0-255 (u8).")
elif isinstance(value, bytes):
return value
raise TypeError("Content must be a list of integers (0-255) or bytes.")


class FilePositionFieldFileInner(BaseModel):
"""
Generated type representing the anonymous struct variant `FieldFile` of the `FilePosition` Rust enum
"""

model_config = ConfigDict(populate_by_name=True)

section_id: str = Field(alias="sectionId")
field_id: str = Field(alias="fieldId")


class FilePositionTypes(str, Enum):
DOCUMENT = "Document"
FIELD_FILE = "FieldFile"


class FilePositionDocument(BaseModel):
"""
The document file saved in a Document item (can only be used with items of Document category)
"""

type: Literal[FilePositionTypes.DOCUMENT] = FilePositionTypes.DOCUMENT


class FilePositionFieldFile(BaseModel):
"""
A file stored as an item field
"""

type: Literal[FilePositionTypes.FIELD_FILE] = FilePositionTypes.FIELD_FILE
content: FilePositionFieldFileInner


FilePosition = Union[FilePositionDocument, FilePositionFieldFile]


class FileAttachParams(BaseModel):
name: str
"""
the name of the file
"""
content: Annotated[
bytes,
BeforeValidator(deserialize_binary_data),
PlainSerializer(serialize_binary_data),
]
"""
the content of the file
"""
position: FilePosition
"""
where the file is stored in the item
"""


class FileAttributes(BaseModel):
name: str
"""
The name of the file
"""
id: str
"""
The ID of the file retrieved from the server
"""
size: int
"""
The size of the file in bytes
"""


class GeneratePasswordResponse(BaseModel):
Expand Down Expand Up @@ -58,11 +142,14 @@ class ItemFieldType(str, Enum):
TOTP = "Totp"
EMAIL = "Email"
REFERENCE = "Reference"
SSHKEY = "SshKey"
MENU = "Menu"
UNSUPPORTED = "Unsupported"


class ItemFieldDetailsTypes(str, Enum):
OTP = "Otp"
SSH_KEY = "SshKey"


class ItemFieldDetailsOtp(BaseModel):
Expand All @@ -74,8 +161,17 @@ class ItemFieldDetailsOtp(BaseModel):
content: OtpFieldDetails


class ItemFieldDetailsSshKey(BaseModel):
"""
Computed SSH Key attributes
"""

type: Literal[ItemFieldDetailsTypes.SSH_KEY] = ItemFieldDetailsTypes.SSH_KEY
content: Optional[SshKeyAttributes]


# Field type-specific attributes.
ItemFieldDetails = ItemFieldDetailsOtp
ItemFieldDetails = Union[ItemFieldDetailsOtp, ItemFieldDetailsSshKey]


class ItemField(BaseModel):
Expand Down Expand Up @@ -167,6 +263,17 @@ class Website(BaseModel):
"""


class ItemFile(BaseModel):
attributes: FileAttributes
"""
the attributes of the file
"""
position: FilePosition
"""
where the file is stored in the item
"""


class Item(BaseModel):
"""
Represents a 1Password item.
Expand Down Expand Up @@ -214,6 +321,10 @@ class Item(BaseModel):
"""
The item's version
"""
files: List[ItemFile]
"""
The item's files
"""


class ItemCreateParams(BaseModel):
Expand Down Expand Up @@ -251,6 +362,10 @@ class ItemCreateParams(BaseModel):
"""
The websites used for autofilling for items of the Login and Password categories.
"""
files: Optional[List[FileAttachParams]] = Field(default=None)
"""
The item's files
"""


class ItemOverview(BaseModel):
Expand Down Expand Up @@ -453,6 +568,23 @@ class OtpFieldDetails(BaseModel):
"""


class SshKeyAttributes(BaseModel):
model_config = ConfigDict(populate_by_name=True)

public_key: str = Field(alias="publicKey")
"""
The public part of the SSH Key
"""
fingerprint: str
"""
The fingerprint of the SSH Key
"""
key_type: str = Field(alias="keyType")
"""
The key type ("Ed25519" or "RSA, {length}-bit")
"""


class VaultOverview(BaseModel):
"""
Represents a decrypted 1Password vault.
Expand Down
Loading