Skip to content

Commit 32eb5bf

Browse files
committed
clean up example, update error msg for limit and ensure we are checking for bytes not characaters on invocation size check
1 parent a1c4ade commit 32eb5bf

File tree

3 files changed

+13
-21
lines changed

3 files changed

+13
-21
lines changed

example/example.py

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
# [developer-docs.sdk.python.sdk-import]-end
88
from cryptography.hazmat.primitives.asymmetric import rsa
99
from cryptography.hazmat.primitives import serialization
10-
from cryptography.hazmat.primitives import hashes
11-
from cryptography.hazmat.primitives.asymmetric import padding
1210

1311
async def main():
1412
# [developer-docs.sdk.python.client-initialization]-start
@@ -267,6 +265,7 @@ async def create_ssh_key_item(client: Client):
267265
print(created_item.fields[0].details.content.fingerprint)
268266
print(created_item.fields[0].details.content.key_type)
269267
# [developer-docs.sdk.python.create-sshkey-item]-end
268+
await client.items.delete(created_item.vault_id, created_item.id)
270269

271270

272271
async def create_and_replace_document_item(client: Client):
@@ -276,20 +275,9 @@ async def create_and_replace_document_item(client: Client):
276275
title="Document Item Created with Python SDK",
277276
category=ItemCategory.DOCUMENT,
278277
vault_id="7turaasywpymt3jecxoxk5roli",
279-
fields=[
280-
ItemField(
281-
id="onetimepassword",
282-
title="one-time-password",
283-
field_type=ItemFieldType.TOTP,
284-
section_id="totpsection",
285-
value="otpauth://totp/my-example-otp?secret=jncrjgbdjnrncbjsr&issuer=1Password",
286-
),
287-
],
288278
sections=[
289279
ItemSection(id="", title=""),
290-
ItemSection(id="totpsection", title=""),
291280
],
292-
tags=["test tag 1", "test tag 2"],
293281
document=DocumentCreateParams(name="file.txt",content=Path("./example/file.txt").read_bytes())
294282
)
295283
created_item = await client.items.create(to_create)
@@ -307,6 +295,9 @@ async def create_and_replace_document_item(client: Client):
307295

308296
print(content)
309297

298+
await client.items.delete(replaced_item.vault_id, replaced_item.id)
299+
300+
310301
async def create_attach_and_delete_file_field_item(client: Client):
311302
# [developer-docs.sdk.python.create-item-with-file-field]-start
312303
# Create a File Field Item
@@ -331,7 +322,6 @@ async def create_attach_and_delete_file_field_item(client: Client):
331322
sections=[
332323
ItemSection(id="", title=""),
333324
],
334-
tags=["test tag 1", "test tag 2"],
335325
files=[FileCreateParams(name="file.txt",content=Path("./example/file.txt").read_bytes(),sectionId="",fieldId="file_field")]
336326
)
337327

@@ -345,10 +335,12 @@ async def create_attach_and_delete_file_field_item(client: Client):
345335

346336
# [developer-docs.sdk.python.delete-file-field-item]-start
347337
# Delete a file field from an item
348-
deleted_item = await client.items.files.delete(attached_item, attached_item.files[0].section_id, attached_item.files[0].field_id)
338+
deleted_file_item = await client.items.files.delete(attached_item, attached_item.files[0].section_id, attached_item.files[0].field_id)
349339
# [developer-docs.sdk.python.delete-file-field-item]-end
350340

351-
print(len(deleted_item.files))
341+
print(len(deleted_file_item.files))
342+
343+
await client.items.delete(deleted_file_item.vault_id, deleted_file_item.id)
352344

353345
if __name__ == "__main__":
354346
asyncio.run(main())

src/onepassword/core.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
# In empirical tests, we determined that maximum message size that can cross the FFI boundary
77
# is ~128MB. Past this limit, FFI will throw an error and the program will crash.
8-
# We set the limit to 50MB to be safe and consistent with the other SDKs, to be reconsidered upon further testing
8+
# We set the limit to 50MB to be safe and consistent with the other SDKs (where this limit is 64MB), to be reconsidered upon further testing
99
MESSAGE_LIMIT = 50 * 1024 * 1024
1010

1111
machine_arch = platform.machine().lower()
@@ -31,9 +31,9 @@ async def _init_client(client_config):
3131
# Invoke calls specified business logic from the SDK core.
3232
async def _invoke(invoke_config):
3333
serialized_config = json.dumps(invoke_config)
34-
if len(serialized_config) > MESSAGE_LIMIT:
34+
if len(serialized_config.encode()) > MESSAGE_LIMIT:
3535
raise ValueError(
36-
f"Message size exceeds the limit of {MESSAGE_LIMIT} bytes.")
36+
f"message size exceeds the limit of {MESSAGE_LIMIT} bytes, please contact 1Password at [email protected] or https://developer.1password.com/joinslack if you need help.")
3737
try:
3838
return await core.invoke(serialized_config)
3939
except Exception as e:
@@ -43,7 +43,7 @@ async def _invoke(invoke_config):
4343
# Invoke calls specified business logic from the SDK core.
4444
def _invoke_sync(invoke_config):
4545
serialized_config = json.dumps(invoke_config)
46-
if len(serialized_config) > MESSAGE_LIMIT:
46+
if len(serialized_config.encode()) > MESSAGE_LIMIT:
4747
raise ValueError(
4848
f"Message size exceeds the limit of {MESSAGE_LIMIT} bytes.")
4949
try:

src/release/RELEASE-NOTES

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
- **Read SSH keys in Open SSH format**: You can now use a secret reference to fetch a private key in OpenSSH format. For example: `op://vault/<SSH item>/private key?ssh-format=openssh`
1111
- **Support for more item field types**: You can now create, retrieve, and edit items containing SSH keys, Month-Year and Menu-type fields using the SDK.
1212
- **Read more field types using secret references**: You can now resolve secret references that point to information stored in Date, Month/Year, Address, and Reference field types.
13-
- **Improved error messages**: The error messages returned by the SDK were improved to be more clear and actionable.
13+
- **Improved error messages**: The error messages returned by the SDK were improved to be more clear and actionable.

0 commit comments

Comments
 (0)