Skip to content

Commit be5e7d4

Browse files
Update core to version ec27c5a1
1 parent 0a5935b commit be5e7d4

18 files changed

+285
-81
lines changed

example/desktop_app.py

Lines changed: 49 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -33,88 +33,85 @@ async def main():
3333
# [developer-docs.sdk.python.list-items]-end
3434

3535
# [developer-docs.sdk.python.get-vault-overview]-start
36-
# Get vault overview
36+
# Get vault overview
3737
vaultOverview = await client.vaults.get_overview(vault_id)
3838
print(vaultOverview)
3939
# [developer-docs.sdk.python.get-vault-overview]-end
4040

4141
# [developer-docs.sdk.python.get-vault-details]-start
42-
# Get vault details
42+
# Get vault details
4343
vault = await client.vaults.get(vaultOverview.id, VaultGetParams(accessors=False))
4444
print(vault)
4545
# [developer-docs.sdk.python.get-vault-details]-end
4646

47-
# [developer-docs.sdk.python.batch-create-items]-start
47+
# [developer-docs.sdk.python.batch-create-items]-start
4848
items_to_create = []
4949
for i in range(1, 4):
50-
items_to_create.append(ItemCreateParams(
51-
title="My Login Item {}".format(i),
52-
category=ItemCategory.LOGIN,
53-
vault_id=vault.id,
54-
fields=[
55-
ItemField(
56-
id="username",
57-
title="username",
58-
field_type=ItemFieldType.TEXT,
59-
value="mynameisjeff",
60-
),
61-
ItemField(
62-
id="password",
63-
title="password",
64-
field_type=ItemFieldType.CONCEALED,
65-
value="jeff",
66-
),
67-
ItemField(
68-
id="onetimepassword",
69-
title="one-time-password",
70-
field_type=ItemFieldType.TOTP,
71-
section_id="totpsection",
72-
value="otpauth://totp/my-example-otp?secret=jncrjgbdjnrncbjsr&issuer=1Password",
73-
),
74-
],
75-
sections=[
76-
ItemSection(
77-
id="", title=""),
78-
ItemSection(
79-
id="totpsection", title=""),
80-
],
81-
tags=[
82-
"test tag 1", "test tag 2"],
83-
websites=[
84-
Website(
85-
label="my custom website",
86-
url="https://example.com",
87-
autofill_behavior=AutofillBehavior.NEVER,
88-
)
89-
],
90-
))
91-
92-
# Create all items in the same vault in a single batch
50+
items_to_create.append(
51+
ItemCreateParams(
52+
title="My Login Item {}".format(i),
53+
category=ItemCategory.LOGIN,
54+
vault_id=vault.id,
55+
fields=[
56+
ItemField(
57+
id="username",
58+
title="username",
59+
field_type=ItemFieldType.TEXT,
60+
value="mynameisjeff",
61+
),
62+
ItemField(
63+
id="password",
64+
title="password",
65+
field_type=ItemFieldType.CONCEALED,
66+
value="jeff",
67+
),
68+
ItemField(
69+
id="onetimepassword",
70+
title="one-time-password",
71+
field_type=ItemFieldType.TOTP,
72+
section_id="totpsection",
73+
value="otpauth://totp/my-example-otp?secret=jncrjgbdjnrncbjsr&issuer=1Password",
74+
),
75+
],
76+
sections=[
77+
ItemSection(id="", title=""),
78+
ItemSection(id="totpsection", title=""),
79+
],
80+
tags=["test tag 1", "test tag 2"],
81+
websites=[
82+
Website(
83+
label="my custom website",
84+
url="https://example.com",
85+
autofill_behavior=AutofillBehavior.NEVER,
86+
)
87+
],
88+
)
89+
)
90+
91+
# Create all items in the same vault in a single batch
9392
batchCreateResponse = await client.items.create_all(vault.id, items_to_create)
9493

9594
item_ids = []
9695
for res in batchCreateResponse.individual_responses:
9796
if res.content is not None:
98-
print('Created item "{}" ({})'.format(
99-
res.content.title, res.content.id))
97+
print('Created item "{}" ({})'.format(res.content.title, res.content.id))
10098
item_ids.append(res.content.id)
10199
elif res.error is not None:
102100
print("[Batch create] Something went wrong: {}".format(res.error))
103101
# [developer-docs.sdk.python.batch-create-items]-end
104102

105103
# [developer-docs.sdk.python.batch-get-items]-start
106-
# Get multiple items form the same vault in a single batch
104+
# Get multiple items form the same vault in a single batch
107105
batchGetReponse = await client.items.get_all(vault.id, item_ids)
108106
for res in batchGetReponse.individual_responses:
109107
if res.content is not None:
110-
print('Obtained item "{}" ({})'.format(
111-
res.content.title, res.content.id))
108+
print('Obtained item "{}" ({})'.format(res.content.title, res.content.id))
112109
elif res.error is not None:
113110
print("[Batch get] Something went wrong: {}".format(res.error))
114111
# [developer-docs.sdk.python.batch-get-items]-end
115112

116113
# [developer-docs.sdk.python.batch-delete-items]-start
117-
# Delete multiple items from the same vault in a single batch
114+
# Delete multiple items from the same vault in a single batch
118115
batchDeleteResponse = await client.items.delete_all(vault.id, item_ids)
119116
for id, res in batchDeleteResponse.individual_responses.items():
120117
if res.error is not None:

src/onepassword/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from .secrets import Secrets
88
from .items import Items
99
from .vaults import Vaults
10+
from .environments import Environments
1011
from .groups import Groups
1112

1213

@@ -19,10 +20,11 @@
1920
"Secrets",
2021
"Items",
2122
"Vaults",
23+
"Environments",
2224
"Groups",
25+
"DesktopAuth",
2326
"DEFAULT_INTEGRATION_NAME",
2427
"DEFAULT_INTEGRATION_VERSION",
25-
"DesktopAuth",
2628
]
2729

2830
for name, obj in inspect.getmembers(sys.modules["onepassword.types"]):

src/onepassword/client.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88
from .secrets import Secrets
99
from .items import Items
1010
from .vaults import Vaults
11+
from .environments import Environments
1112
from .groups import Groups
1213

1314

1415
class Client:
1516
secrets: Secrets
1617
items: Items
1718
vaults: Vaults
19+
environments: Environments
1820
groups: Groups
1921

2022
@classmethod
@@ -41,8 +43,8 @@ async def authenticate(
4143
authenticated_client.secrets = Secrets(inner_client)
4244
authenticated_client.items = Items(inner_client)
4345
authenticated_client.vaults = Vaults(inner_client)
46+
authenticated_client.environments = Environments(inner_client)
4447
authenticated_client.groups = Groups(inner_client)
45-
4648
authenticated_client._finalizer = weakref.finalize(
4749
cls, core.release_client, client_id
4850
)

src/onepassword/core.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ class InnerClient:
2323
core: DesktopCore | UniffiCore
2424
config: dict[str, Any]
2525

26-
def __init__(self, client_id: int, core: "DesktopCore | UniffiCore", config: dict[str, any]):
26+
def __init__(
27+
self, client_id: int, core: "DesktopCore | UniffiCore", config: dict[str, any]
28+
):
2729
self.client_id = client_id
2830
self.core = core
2931
self.config = config

src/onepassword/defaults.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
DEFAULT_REQUEST_LIBRARY_VERSION = "0.11.24"
1010
DEFAULT_OS_VERSION = "0.0.0"
1111

12+
1213
class DesktopAuth:
1314
def __init__(self, account_name: str):
1415
"""
@@ -19,6 +20,7 @@ def __init__(self, account_name: str):
1920
"""
2021
self.account_name = account_name
2122

23+
2224
# Generates a configuration dictionary with the user's parameters
2325
def new_default_config(auth: DesktopAuth | str, integration_name, integration_version):
2426
client_config_dict = {

src/onepassword/desktop_core.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,22 @@ def find_1password_lib_path():
1616
if os_name == "Darwin": # macOS
1717
locations = [
1818
"/Applications/1Password.app/Contents/Frameworks/libop_sdk_ipc_client.dylib",
19-
str(Path.home() / "Applications/1Password.app/Contents/Frameworks/libop_sdk_ipc_client.dylib"),
19+
str(
20+
Path.home()
21+
/ "Applications/1Password.app/Contents/Frameworks/libop_sdk_ipc_client.dylib"
22+
),
2023
]
2124
elif os_name == "Linux":
2225
locations = [
2326
"/usr/bin/1password/libop_sdk_ipc_client.so",
24-
"/opt/1Password/libop_sdk_ipc_client.so",
25-
"/snap/bin/1password/libop_sdk_ipc_client.so",
27+
"/opt/1Password/libop_sdk_ipc_client.so",
28+
"/snap/bin/1password/libop_sdk_ipc_client.so",
2629
]
2730
elif os_name == "Windows":
2831
locations = [
2932
str(Path.home() / r"AppData\Local\1Password\op_sdk_ipc_client.dll"),
3033
r"C:\Program Files\1Password\app\8\op_sdk_ipc_client.dll",
31-
r"C:\Program Files (x86)\1Password\app\8\op_sdk_ipc_client.dll",
34+
r"C:\Program Files (x86)\1Password\app\8\op_sdk_ipc_client.dll",
3235
str(Path.home() / r"AppData\Local\1Password\app\8\op_sdk_ipc_client.dll"),
3336
]
3437
else:
@@ -40,6 +43,7 @@ def find_1password_lib_path():
4043

4144
raise FileNotFoundError("1Password desktop application not found")
4245

46+
4347
class DesktopCore:
4448
def __init__(self, account_name: str):
4549
# Determine the path to the desktop app.
@@ -51,11 +55,11 @@ def __init__(self, account_name: str):
5155
# Bind the Rust-exported functions
5256
self.send_message = self.lib.op_sdk_ipc_send_message
5357
self.send_message.argtypes = [
54-
POINTER(c_uint8), # msg_ptr
55-
c_size_t, # msg_len
56-
POINTER(POINTER(c_uint8)), # out_buf
57-
POINTER(c_size_t), # out_len
58-
POINTER(c_size_t), # out_cap
58+
POINTER(c_uint8), # msg_ptr
59+
c_size_t, # msg_len
60+
POINTER(POINTER(c_uint8)), # out_buf
61+
POINTER(c_size_t), # out_len
62+
POINTER(c_size_t), # out_cap
5963
]
6064
self.send_message.restype = c_int32
6165

@@ -123,6 +127,7 @@ def release_client(self, client_id: int):
123127
except Exception as e:
124128
print(f"failed to release client: {e}")
125129

130+
126131
ERR_CHANNEL_CLOSED = (
127132
"desktop app connection channel is closed. "
128133
"Make sure Settings > Developer > Integrate with other apps is enabled, "

src/onepassword/environments.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Code generated by op-codegen - DO NO EDIT MANUALLY
2+
3+
from .core import InnerClient
4+
from pydantic import TypeAdapter
5+
from .types import GetVariablesResponse
6+
7+
8+
class Environments:
9+
"""
10+
The Environments API holds all the operations the SDK client can perform on 1Password Environments (Vault Type = 'D').
11+
"""
12+
13+
def __init__(self, inner_client: InnerClient):
14+
self.inner_client = inner_client
15+
16+
async def get_variables(self, environment_id: str) -> GetVariablesResponse:
17+
"""
18+
Get environment variables belonging to an Environment.
19+
"""
20+
response = await self.inner_client.invoke(
21+
{
22+
"invocation": {
23+
"clientId": self.inner_client.client_id,
24+
"parameters": {
25+
"name": "EnvironmentsGetVariables",
26+
"parameters": {"environment_id": environment_id},
27+
},
28+
}
29+
}
30+
)
31+
32+
response = TypeAdapter(GetVariablesResponse).validate_json(response)
33+
return response

src/onepassword/groups.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ def __init__(self, inner_client: InnerClient):
1414
self.inner_client = inner_client
1515

1616
async def get(self, group_id: str, group_params: GroupGetParams) -> Group:
17+
"""
18+
Get a group by its ID and parameters.
19+
"""
1720
response = await self.inner_client.invoke(
1821
{
1922
"invocation": {

src/onepassword/items.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ async def create_all(
7171

7272
async def get(self, vault_id: str, item_id: str) -> Item:
7373
"""
74-
Get an item by vault and item ID
74+
Get an item by vault and item ID.
7575
"""
7676
response = await self.inner_client.invoke(
7777
{

src/onepassword/items_files.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def __init__(self, inner_client: InnerClient):
1212

1313
async def attach(self, item: Item, file_params: FileCreateParams) -> Item:
1414
"""
15-
Attach files to Items
15+
Attach files to Items.
1616
"""
1717
response = await self.inner_client.invoke(
1818
{
@@ -34,7 +34,7 @@ async def attach(self, item: Item, file_params: FileCreateParams) -> Item:
3434

3535
async def read(self, vault_id: str, item_id: str, attr: FileAttributes) -> bytes:
3636
"""
37-
Read file content from the Item
37+
Read file content from the Item.
3838
"""
3939
response = await self.inner_client.invoke(
4040
{
@@ -57,7 +57,7 @@ async def read(self, vault_id: str, item_id: str, attr: FileAttributes) -> bytes
5757

5858
async def delete(self, item: Item, section_id: str, field_id: str) -> Item:
5959
"""
60-
Delete a field file from Item using the section and field IDs
60+
Delete a field file from Item using the section and field IDs.
6161
"""
6262
response = await self.inner_client.invoke(
6363
{
@@ -82,7 +82,7 @@ async def replace_document(
8282
self, item: Item, doc_params: DocumentCreateParams
8383
) -> Item:
8484
"""
85-
Replace the document file within a document item
85+
Replace the document file within a document item.
8686
"""
8787
response = await self.inner_client.invoke(
8888
{

0 commit comments

Comments
 (0)