-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #178 from zcutlip/development
merge development into main: v4.1.0
- Loading branch information
Showing
132 changed files
with
1,441 additions
and
327 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# PYONEPASSWORD DOCUMENT EDITING | ||
|
||
## Description | ||
As of version 4.1.0, `pyonepassword` supports in-place document editing. There is API to match the operations supported by the `op document edit` command. | ||
|
||
The API for document editing is the `OP.docuemnt_edit()` method. This method replaces the bytes of an existing document item with the contents of a new file. | ||
|
||
|
||
## Use and arguments | ||
The `document_edit()` method takes two mandatory arguments: | ||
|
||
- `document_identitifer`: A string representing the title or unique ID of a document item | ||
- `file_path_or_document_bytes`: This is what the document should be replaced with. It may be either: | ||
- A `str` or `Path` object referencing existing file on disk to read | ||
- A `bytes` object that is the new file's contents | ||
|
||
Additionally, you may *also* change the document item's: | ||
|
||
- filename via the `file_name=` kwarg | ||
- title via the `new_title=` kwarg | ||
|
||
**Note**: You may not set a new filename or document item title via document_edit() without also specifying a path or bytes to set the document's contents to. This is not supported by `op document edit`. If this behavior is required, the equivalent would be to provide the original document's contents | ||
|
||
### Return value | ||
|
||
If successful, the `document_edit()` function returns a string representing the unique ID of the document item edited. This may be useful for confirming the expected document item is the one that was edited, in the event a document title was provided. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from pathlib import Path | ||
|
||
from pyonepassword import OP | ||
|
||
|
||
def replace_document(): | ||
op = OP() | ||
document_title = "example document 01" | ||
replacement_file_path = "path/to/replacement_image_01.png" | ||
|
||
op.document_edit(document_title, replacement_file_path) | ||
|
||
# or replacmenet document can be bytes instead of str/Path: | ||
replacement_bytes = open(replacement_file_path, "rb").read() | ||
|
||
op.document_edit(document_title, replacement_bytes) | ||
|
||
|
||
def replace_document_set_title(): | ||
op = OP() | ||
document_title = "example document 01" | ||
replacement_file_path = "path/to/replacement_image_01.png" | ||
new_document_title = "updated example document 01" | ||
op.document_edit(document_title, replacement_file_path, | ||
new_title=new_document_title) | ||
|
||
|
||
def replace_document_set_filename(): | ||
op = OP() | ||
document_title = "example document 01" | ||
|
||
# replacement path may be Path or str | ||
replacement_file_path = Path("path/to/replacement_image_01.png") | ||
|
||
# get basename: "replacement_image_01.png" | ||
new_document_filename = replacement_file_path.name | ||
op.document_edit(document_title, replacement_file_path, | ||
file_name=new_document_filename) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from _util.functions import get_op | ||
from dotenv import load_dotenv | ||
|
||
from pyonepassword.api.exceptions import OPCmdFailedException # noqa: F401 | ||
|
||
load_dotenv("./dot_env_files/.env_pyonepassword_test_rw") | ||
|
||
print("run: op = get_op(\"document-edit\")") | ||
|
||
vault = "Test Data 2" | ||
document_name = "example document 10" | ||
new_file_path = "working_data/images/replacement_image_10.png" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.