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
5 changes: 4 additions & 1 deletion src/onepassword/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# Code generated by op-codegen - DO NO EDIT MANUALLY

from .client import Client
from .client import Client, DesktopAuth
from .defaults import DEFAULT_INTEGRATION_NAME, DEFAULT_INTEGRATION_VERSION
from .types import * # noqa F403
from .errors import * # noqa F403
from .secrets import Secrets
from .items import Items
from .vaults import Vaults
from .groups import Groups


import sys
Expand All @@ -18,6 +19,8 @@
"Secrets",
"Items",
"Vaults",
"Groups",
"DesktopAuth",
"DEFAULT_INTEGRATION_NAME",
"DEFAULT_INTEGRATION_VERSION",
]
Expand All @@ -30,7 +33,7 @@
and inspect.getmodule(obj) == sys.modules["onepassword.types"]
)
or isinstance(obj, int)
or type(obj) == typing._LiteralGenericAlias

Check failure on line 36 in src/onepassword/__init__.py

View workflow job for this annotation

GitHub Actions / Lint

Ruff (E721)

src/onepassword/__init__.py:36:12: E721 Use `is` and `is not` for type comparisons, or `isinstance()` for isinstance checks
):
__all__.append(name)

Expand Down
29 changes: 20 additions & 9 deletions src/onepassword/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,48 @@

from __future__ import annotations
import weakref
from .core import _init_client, _release_client
from .defaults import new_default_config
from .core import UniffiCore, InnerClient
from .desktop_core import DesktopCore
from .defaults import new_default_config, DesktopAuth
from .secrets import Secrets
from .items import Items
from .vaults import Vaults
from .groups import Groups


class Client:
secrets: Secrets
items: Items
vaults: Vaults
groups: Groups

@classmethod
async def authenticate(
cls, auth: str, integration_name: str, integration_version: str
cls, auth: str | DesktopAuth, integration_name: str, integration_version: str
) -> Client:
config = new_default_config(
auth=auth or "",
auth=auth,
integration_name=integration_name,
integration_version=integration_version,
)

client_id = int(await _init_client(config))
if isinstance(auth, DesktopAuth):
core = DesktopCore(auth.account_name)
else:
core = UniffiCore()

client_id = int(await core.init_client(config))

inner_client = InnerClient(client_id, core, config)

authenticated_client = cls()

authenticated_client.secrets = Secrets(client_id)
authenticated_client.items = Items(client_id)
authenticated_client.vaults = Vaults(client_id)
authenticated_client.secrets = Secrets(inner_client)
authenticated_client.items = Items(inner_client)
authenticated_client.vaults = Vaults(inner_client)
authenticated_client.groups = Groups(inner_client)
authenticated_client._finalizer = weakref.finalize(
cls, _release_client, client_id
cls, core.release_client, client_id
)

return authenticated_client
10 changes: 9 additions & 1 deletion src/onepassword/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
import json


class DesktopSessionExpiredException(Exception):
def __init__(self, message):
self.message = message
super().__init__(self.message)


class RateLimitExceededException(Exception):
def __init__(self, message):
self.message = message
Expand All @@ -18,7 +24,9 @@ def raise_typed_exception(e: Exception):
error_name = typed_error.get("name")
message = typed_error.get("message")

if error_name == "RateLimitExceeded":
if error_name == "DesktopSessionExpired":
raise DesktopSessionExpiredException(message)
elif error_name == "RateLimitExceeded":
raise RateLimitExceededException(message)
elif message is not None:
raise Exception(message)
Expand Down
36 changes: 36 additions & 0 deletions src/onepassword/groups.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Code generated by op-codegen - DO NO EDIT MANUALLY

from .core import InnerClient
from pydantic import TypeAdapter
from .types import Group, GroupGetParams


class Groups:
"""
The Groups API holds all the operations the SDK client can perform on 1Password groups.
"""

def __init__(self, inner_client: InnerClient):
self.inner_client = inner_client

async def get(self, group_id: str, group_params: GroupGetParams) -> Group:
"""
Get a group by its ID and parameters.
"""
response = await self.inner_client.invoke(
{
"invocation": {
"clientId": self.inner_client.client_id,
"parameters": {
"name": "GroupsGet",
"parameters": {
"group_id": group_id,
"group_params": group_params.model_dump(by_alias=True),
},
},
}
}
)

response = TypeAdapter(Group).validate_json(response)
return response
113 changes: 92 additions & 21 deletions src/onepassword/items.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,39 @@
# Code generated by op-codegen - DO NO EDIT MANUALLY

from .core import _invoke, _invoke_sync
from typing import Optional, List
from .core import InnerClient
from typing import List
from pydantic import TypeAdapter
from .items_shares import ItemsShares
from .items_files import ItemsFiles
from .types import Item, ItemCreateParams, ItemListFilter, ItemOverview
from .types import (
Item,
ItemCreateParams,
ItemListFilter,
ItemOverview,
ItemsDeleteAllResponse,
ItemsGetAllResponse,
ItemsUpdateAllResponse,
)


class Items:
"""
The Items API holds all operations the SDK client can perform on 1Password items.
"""

def __init__(self, client_id):
self.client_id = client_id
self.shares = ItemsShares(client_id)

self.files = ItemsFiles(client_id)
def __init__(self, inner_client: InnerClient):
self.inner_client = inner_client
self.shares = ItemsShares(inner_client)
self.files = ItemsFiles(inner_client)

async def create(self, params: ItemCreateParams) -> Item:
"""
Create a new item.
"""
response = await _invoke(
response = await self.inner_client.invoke(
{
"invocation": {
"clientId": self.client_id,
"clientId": self.inner_client.client_id,
"parameters": {
"name": "ItemsCreate",
"parameters": {"params": params.model_dump(by_alias=True)},
Expand All @@ -38,14 +45,38 @@
response = TypeAdapter(Item).validate_json(response)
return response

async def create_all(
self, vault_id: str, params: List[ItemCreateParams]
) -> ItemsUpdateAllResponse:
"""
Create items in batch, within a single vault.
"""
response = await self.inner_client.invoke(
{
"invocation": {
"clientId": self.inner_client.client_id,
"parameters": {
"name": "ItemsCreateAll",
"parameters": {
"vault_id": vault_id,
"params": [o.model_dump(by_alias=True) for o in params],
},
},
}
}
)

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

async def get(self, vault_id: str, item_id: str) -> Item:
"""
Get an item by vault and item ID
Get an item by vault and item ID.
"""
response = await _invoke(
response = await self.inner_client.invoke(
{
"invocation": {
"clientId": self.client_id,
"clientId": self.inner_client.client_id,
"parameters": {
"name": "ItemsGet",
"parameters": {"vault_id": vault_id, "item_id": item_id},
Expand All @@ -57,14 +88,33 @@
response = TypeAdapter(Item).validate_json(response)
return response

async def get_all(self, vault_id: str, item_ids: List[str]) -> ItemsGetAllResponse:
"""
Get items by vault and their item IDs.
"""
response = await self.inner_client.invoke(
{
"invocation": {
"clientId": self.inner_client.client_id,
"parameters": {
"name": "ItemsGetAll",
"parameters": {"vault_id": vault_id, "item_ids": item_ids},
},
}
}
)

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

async def put(self, item: Item) -> Item:
"""
Update an existing item.
"""
response = await _invoke(
response = await self.inner_client.invoke(
{
"invocation": {
"clientId": self.client_id,
"clientId": self.inner_client.client_id,
"parameters": {
"name": "ItemsPut",
"parameters": {"item": item.model_dump(by_alias=True)},
Expand All @@ -80,10 +130,10 @@
"""
Delete an item.
"""
response = await _invoke(
response = await self.inner_client.invoke(

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

View workflow job for this annotation

GitHub Actions / Lint

Ruff (F841)

src/onepassword/items.py:133:9: F841 Local variable `response` is assigned to but never used
{
"invocation": {
"clientId": self.client_id,
"clientId": self.inner_client.client_id,
"parameters": {
"name": "ItemsDelete",
"parameters": {"vault_id": vault_id, "item_id": item_id},
Expand All @@ -94,14 +144,35 @@

return None

async def delete_all(
self, vault_id: str, item_ids: List[str]
) -> ItemsDeleteAllResponse:
"""
Delete items in batch, within a single vault.
"""
response = await self.inner_client.invoke(
{
"invocation": {
"clientId": self.inner_client.client_id,
"parameters": {
"name": "ItemsDeleteAll",
"parameters": {"vault_id": vault_id, "item_ids": item_ids},
},
}
}
)

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

async def archive(self, vault_id: str, item_id: str) -> None:
"""
Archive an item.
"""
response = await _invoke(
response = await self.inner_client.invoke(

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

View workflow job for this annotation

GitHub Actions / Lint

Ruff (F841)

src/onepassword/items.py:172:9: F841 Local variable `response` is assigned to but never used
{
"invocation": {
"clientId": self.client_id,
"clientId": self.inner_client.client_id,
"parameters": {
"name": "ItemsArchive",
"parameters": {"vault_id": vault_id, "item_id": item_id},
Expand All @@ -116,10 +187,10 @@
"""
List items based on filters.
"""
response = await _invoke(
response = await self.inner_client.invoke(
{
"invocation": {
"clientId": self.client_id,
"clientId": self.inner_client.client_id,
"parameters": {
"name": "ItemsList",
"parameters": {
Expand Down
Loading
Loading