Skip to content
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-pyo3: add library interface #566

Merged
merged 40 commits into from
Nov 14, 2024
Merged

Python-pyo3: add library interface #566

merged 40 commits into from
Nov 14, 2024

Conversation

Esgrove
Copy link
Contributor

@Esgrove Esgrove commented Nov 12, 2024

Enable using python-pyo3 vault version as a python library. Adds wrappers for accessing most vault functions:
all, delete, delete_many, direct_encrypt, direct_decrypt, exists, list_all, lookup, store, init, update, and stack_status
(Some of these are new compared to the old python version)

  • Re-organize pyo3 package to match old python version:
    • rename p_vault to n_vault
    • put Python CLI under cli.py and library in vault.py
  • Add integration tests for Python library usage
  • Update python readme with vault library usage instructions

The Vault class in the new library is a dummy class that is only there to make the interface the same as before, so you can use it like before but it does not actually construct a vault instance:

from n_vault import Vault

Vault().store("key", "value")

vault = Vault()
value = vault.lookup("key")

Parameters and names are mostly the same, the vault class has some differences due to the Rust vault doing things a bit differently:

# OLD
def __init__(
    self,
    vault_stack="",
    vault_key="",
    vault_bucket="",
    vault_iam_id="",
    vault_iam_secret="",
    vault_prefix="",
    vault_region=None,
    vault_init=False,
):
    
# NEW
def __init__(
    self,
    vault_stack: str = None,
    vault_key: str = None,
    vault_bucket: str = None,
    vault_prefix: str = None,
    vault_region: str = None,
    profile: str = None,
):

init, update, and stack_status return dataclasses so data is nicely typed and accessible:

python-pyo3 git:(pyo3-library) ✗ nep nitor-corepython-pyo3 git:(pyo3-library) ✗ python
Python 3.13.0 (main, Oct  7 2024, 05:02:14) [Clang 16.0.0 (clang-1600.0.26.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from n_vault import Vault
>>> Vault().init()
CloudFormationStackData(result='EXISTS', bucket='nitor-core-vault', key='arn:aws:kms:eu-west-1:293246570391:key/726c1aeb-ba7d-4616-ac9f-d67e72774d88', status='UPDATE_COMPLETE', status_reason=None, version=27)
>>> result = Vault().update()
>>> print(result)
CloudFormationStackData(result='UP_TO_DATE', bucket='nitor-core-vault', key='arn:aws:kms:eu-west-1:293246570391:key/726c1aeb-ba7d-4616-ac9f-d67e72774d88', status='UPDATE_COMPLETE', status_reason=None, version=27)
>>> result.bucket
'nitor-core-vault'
>>> Vault(vault_stack="testing-new-library").init()
StackCreated(result='CREATED', stack_name='testing-new-library', stack_id='arn:aws:cloudformation:eu-west-1:293246570391:stack/testing-new-library/01102700-a1d0-11ef-84d1-06ed5a90571f', region='eu-west-1')

@Esgrove Esgrove requested a review from psiniemi November 13, 2024 13:59
Copy link
Contributor

@kahlstrm kahlstrm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't tested it but looks good 👍

@Esgrove Esgrove merged commit 6586709 into master Nov 14, 2024
18 checks passed
@Esgrove Esgrove deleted the pyo3-library branch November 14, 2024 09:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants