-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Python-pyo3: add library interface (#566)
* cargo update * rename p_vault to n_vault again and move cli to cli.py * expose list_all and lookup from rust library * output binary data in base64 * rust fixes * add license texts * implement store, exists, and delete * update pyproject information * add integration test cases for python library * tweak comment * fix integration test trigger for PRs * cancel previous runs for PR wheel build * fix store when input argument is a string * fix empty string for print end arg * add extra rust cache key for release build * convert lookup bytes output to string * workaround list all case since there seems to be unexpected extra keys * remove unneeded decode from python rust lib test * add `delete_many` to library * fix wc -l to not count empty lines * remove extra list all * add readme section for python library usage * support specifying vault parameters * add init and update * add stack status * return python dict * update docstrings for library functions * docstrings for all public library methods * match parameter names to old python library * fix variable rename * make type hinting compatible with python 3.9 * fix help output when no arguments are given * rename and reorder vault class parameters to match previous version * add direct encrypt and decrypt * return bytes from direct encrypt and decrypt * fix type hints for 3.9 :( * ignore all venvs * match parameter name for direct decrypt * cargo update * fix typo in helper function name
- Loading branch information
Showing
21 changed files
with
837 additions
and
78 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,8 +8,6 @@ on: | |
paths: | ||
- "!**/README.md" | ||
pull_request: | ||
paths: | ||
- "!**/README.md" | ||
|
||
permissions: | ||
id-token: write | ||
|
@@ -37,6 +35,9 @@ jobs: | |
|
||
- uses: Swatinem/[email protected] | ||
if: ${{ matrix.lang == 'rust'}} | ||
with: | ||
# The build script creates a `release` build so use separate cache | ||
key: "release" | ||
|
||
- uses: actions/setup-go@v5 | ||
if: ${{ matrix.lang == 'go'}} | ||
|
@@ -218,9 +219,6 @@ jobs: | |
- name: Delete secret with Rust | ||
run: bin/rust/vault -d "secret-${{github.sha}}.zip" | ||
|
||
- name: Verify that key has been deleted with Rust | ||
run: bin/rust/vault exists secret-${{github.sha}}.zip | grep -q "does not exist" | ||
|
||
- name: Verify that keys have been deleted using Rust | ||
run: | | ||
bin/rust/vault exists secret-python | grep -q "key 'secret-python' does not exist" | ||
|
@@ -229,6 +227,33 @@ jobs: | |
bin/rust/vault exists secret-rust | grep -q "key 'secret-rust' does not exist" | ||
bin/rust/vault exists secret-nodejs | grep -q "key 'secret-nodejs' does not exist" | ||
- name: Check Python vault package | ||
run: python -m pip show nitor-vault | ||
|
||
- name: Store secret using Python library | ||
run: | | ||
python -c "from n_vault import Vault; Vault().store('secret-python-library', 'sha-${{github.sha}}')" | ||
- name: Verify secret using Python library | ||
run: | | ||
python -c "from n_vault import Vault; print('true') if Vault().exists('secret-python-library') else print('false')" | grep -q "true" | ||
- name: Validate storing worked with Rust | ||
run: diff <(bin/rust/vault -l secret-python-library) <(echo -n sha-${{github.sha}}) | ||
|
||
- name: Lookup with Python library | ||
run: | | ||
diff <(python -c "from n_vault import Vault; print(Vault().lookup('secret-python-library').decode('utf-8'), end='', flush=True)") <(echo -n sha-${{github.sha}}) | ||
- name: List with Python library | ||
run: python -c "from n_vault import Vault; print('\n'.join(Vault().list_all()))" | ||
|
||
- name: Delete with Python library | ||
run: python -c "from n_vault import Vault; Vault().delete('secret-python-library')" | ||
|
||
- name: Verify that key has been deleted with Rust | ||
run: bin/rust/vault exists secret-python-library | grep -q "key 'secret-python-library' does not exist" | ||
|
||
- name: Install Python PyO3 vault | ||
run: python -m pip install --force-reinstall . | ||
working-directory: python-pyo3 | ||
|
@@ -310,3 +335,36 @@ jobs: | |
|
||
- name: Verify that key has been deleted with Python-pyo3 | ||
run: vault exists secret-${{github.sha}}.zip | grep -q "does not exist" | ||
|
||
- name: Check Python vault package | ||
run: python -m pip show nitor-vault | ||
|
||
- name: Delete all keys with Python library | ||
run: python -c "from n_vault import Vault; Vault().delete_many(Vault().list_all())" | ||
|
||
- name: List with Python library | ||
run: python -c "from n_vault import Vault; print('\n'.join(Vault().list_all()))" | grep -ve '^\s*$' | wc -l | grep -q "0" | ||
|
||
- name: Store secret using Python library | ||
run: | | ||
python -c "from n_vault import Vault; Vault().store('secret-python-library', 'sha-${{github.sha}}')" | ||
- name: Verify secret using Python library | ||
run: | | ||
python -c "from n_vault import Vault; print('true') if Vault().exists('secret-python-library') else print('false')" | grep -q "true" | ||
- name: Validate storing worked with Rust | ||
run: diff <(bin/rust/vault -l secret-python-library) <(echo -n sha-${{github.sha}}) | ||
|
||
- name: Lookup with Python library | ||
run: | | ||
diff <(python -c "from n_vault import Vault; print(Vault().lookup('secret-python-library'), end='', flush=True)") <(echo -n sha-${{github.sha}}) | ||
- name: List with Python library | ||
run: python -c "from n_vault import Vault; print('\n'.join(Vault().list_all()))" | wc -l | grep -q "1" | ||
|
||
- name: Delete with Python library | ||
run: python -c "from n_vault import Vault; Vault().delete('secret-python-library')" | ||
|
||
- name: Verify that key has been deleted with Rust | ||
run: bin/rust/vault exists secret-python-library | grep -q "key 'secret-python-library' does not exist" |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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 |
---|---|---|
|
@@ -22,22 +22,23 @@ authors = [ | |
{ name = "Pasi Niemi", email = "[email protected]" }, | ||
{ name = "Akseli Lukkarila", email = "[email protected]" }, | ||
] | ||
license = { text = "Apache 2.0" } | ||
license = { text = "Apache-2.0" } | ||
classifiers = [ | ||
"Programming Language :: Rust", | ||
"Programming Language :: Python :: Implementation :: CPython", | ||
] | ||
dependencies = [] | ||
|
||
[project.optional-dependencies] | ||
build = ["maturin", "twine", "wheel"] | ||
dev = ["ruff"] | ||
build = ["maturin", "wheel"] | ||
dev = ["maturin", "ruff"] | ||
|
||
[project.urls] | ||
Repository = "https://github.com/NitorCreations/vault" | ||
Homepage = "https://github.com/NitorCreations/vault" | ||
|
||
[project.scripts] | ||
vault = "p_vault.vault:main" | ||
vault = "n_vault.cli:main" | ||
|
||
[build-system] | ||
requires = ["maturin>=1.7,<2.0"] | ||
|
@@ -46,9 +47,9 @@ build-backend = "maturin" | |
[tool.maturin] | ||
bindings = "pyo3" | ||
features = ["pyo3/extension-module"] | ||
module-name = "p_vault.nitor_vault_rs" | ||
module-name = "n_vault.nitor_vault_rs" | ||
profile = "release" | ||
python-packages = ["p_vault"] | ||
python-packages = ["n_vault"] | ||
python-source = "python" | ||
strip = true | ||
|
||
|
@@ -59,7 +60,7 @@ venv = ".venv" | |
[tool.ruff] | ||
# https://docs.astral.sh/ruff/configuration/ | ||
include = ["*.py", "*.pyi", "**/pyproject.toml"] | ||
target-version = "py311" | ||
target-version = "py39" | ||
line-length = 120 | ||
|
||
[tool.ruff.lint] | ||
|
Oops, something went wrong.