-
Notifications
You must be signed in to change notification settings - Fork 20
Python SDK 0.2.0 RC #156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python SDK 0.2.0 RC #156
Changes from all commits
fc180d5
70c9660
8a5af19
1aed96f
2158f32
10ef4e6
48a030d
5876256
499a28b
fc2b260
fe42c8d
a1c4ade
32eb5bf
89ddd7e
936f51e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Hello World! |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Hello again, world! |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| SDK_BUILD_NUMBER = "0010701" | ||
| SDK_BUILD_NUMBER = "0020001" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,10 @@ | |
|
|
||
| from onepassword.errors import raise_typed_exception | ||
|
|
||
| # In empirical tests, we determined that maximum message size that can cross the FFI boundary | ||
| # is ~128MB. Past this limit, FFI will throw an error and the program will crash. | ||
| # 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 | ||
| MESSAGE_LIMIT = 50 * 1024 * 1024 | ||
|
|
||
| machine_arch = platform.machine().lower() | ||
|
|
||
|
|
@@ -26,16 +30,24 @@ async def _init_client(client_config): | |
|
|
||
| # Invoke calls specified business logic from the SDK core. | ||
| async def _invoke(invoke_config): | ||
| serialized_config = json.dumps(invoke_config) | ||
| if len(serialized_config.encode()) > MESSAGE_LIMIT: | ||
| raise ValueError( | ||
| 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.") | ||
| try: | ||
| return await core.invoke(json.dumps(invoke_config)) | ||
| return await core.invoke(serialized_config) | ||
| except Exception as e: | ||
| raise_typed_exception(e) | ||
|
|
||
|
|
||
| # Invoke calls specified business logic from the SDK core. | ||
| def _invoke_sync(invoke_config): | ||
| serialized_config = json.dumps(invoke_config) | ||
| if len(serialized_config.encode()) > MESSAGE_LIMIT: | ||
| raise ValueError( | ||
| 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.") | ||
| try: | ||
| return core.invoke_sync(json.dumps(invoke_config)) | ||
| return core.invoke_sync(serialized_config) | ||
| except Exception as e: | ||
| raise_typed_exception(e) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| # 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
|
||
| from .iterator import SDKIterator | ||
|
Check failure on line 4 in src/onepassword/items_files.py
|
||
| from typing import Optional, List | ||
|
Check failure on line 5 in src/onepassword/items_files.py
|
||
| from pydantic import TypeAdapter | ||
| from .types import DocumentCreateParams, FileAttributes, FileCreateParams, Item | ||
|
|
||
|
|
||
| class ItemsFiles: | ||
| def __init__(self, client_id): | ||
| self.client_id = client_id | ||
|
|
||
| async def attach(self, item: Item, file_params: FileCreateParams) -> 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, section_id: str, field_id: str) -> Item: | ||
| """ | ||
| Delete a field file from Item using the section and field IDs | ||
| """ | ||
| response = await _invoke( | ||
| { | ||
| "invocation": { | ||
| "clientId": self.client_id, | ||
| "parameters": { | ||
| "name": "ItemsFilesDelete", | ||
| "parameters": { | ||
| "item": item.model_dump(by_alias=True), | ||
| "section_id": section_id, | ||
| "field_id": field_id, | ||
| }, | ||
| }, | ||
| } | ||
| } | ||
| ) | ||
|
|
||
| response = TypeAdapter(Item).validate_json(response) | ||
| return response | ||
|
|
||
| async def replace_document( | ||
| self, item: Item, doc_params: DocumentCreateParams | ||
| ) -> Item: | ||
| """ | ||
| Replace the document file within a document item | ||
| """ | ||
| response = await _invoke( | ||
| { | ||
| "invocation": { | ||
| "clientId": self.client_id, | ||
| "parameters": { | ||
| "name": "ItemsFilesReplaceDocument", | ||
| "parameters": { | ||
| "item": item.model_dump(by_alias=True), | ||
| "doc_params": doc_params.model_dump(by_alias=True), | ||
| }, | ||
| }, | ||
| } | ||
| } | ||
| ) | ||
|
|
||
| response = TypeAdapter(Item).validate_json(response) | ||
| return response | ||
Uh oh!
There was an error while loading. Please reload this page.