Implement HashiCorp Vault integration #8
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit introduces significant new functionality by adding support for HashiCorp Vault secret fetching and completely refactors the library's error handling mechanisms for improved robustness and clarity. Documentation and tests have been updated accordingly.
Key Changes:
HashiCorp Vault Integration:
!VAULTYAML tag, allowing users to seamlessly fetch secrets directly from HashiCorp Vault within their YAML configuration files.vault_constructorfor the YAML loader to process the!VAULTtag, handling path and key parsing._get_vault_clienthelper function for robust Vault client initialization, including authentication usingVAULT_TOKEN.VAULT_ADDRandVAULT_TOKENenvironment variables.hvaclibrary has been added as a new core dependency for Vault communication.Explicit Error Handling with Custom Exceptions:
_load_fernet_key,_get_vault_client,encrypt_string_value,load_yaml_secrets, YAML tag constructors likesec_constructor&vault_constructor, andsec_representerin the dumper) have been refactored.KeylockerFileError,KeylockerEncryptionError,KeylockerConfigError,KeylockerVaultError,VaultClientNotInitializedError,VaultKeyNotFoundError,VaultInvalidPathError) instead of printing error messages and returningNoneor directly callingsys.exit(). This makes the library's error contract clearer and facilitates better error handling by calling code.vault_constructorwas fixed where custom exceptions likeVaultKeyNotFoundErrorwere being incorrectly caught and re-wrapped by a genericexcept Exceptionblock. Thetry-exceptstructure withinvault_constructorhas been refined for correct propagation of specific custom exceptions.CLI Enhancements (
Managerclass):view,encrypt) within theManagerclass have been updated to catch the newly introduced specific exceptions from the core library functions.stderrand exit with appropriate non-zero status codes, adhering to standard CLI best practices.Testing (
pytest):pytestunit tests (tests/test_keylocker_vault.py) has been developed to cover the HashiCorp Vault integration, including various success and failure scenarios.!SECtag processing, and!ENVtag resolution (tests/test_keylocker_yaml.py) have been updated and refactored to align with the new exception-based error handling paradigm (e.g., usingpytest.raisesto assert specific exceptions).Fernetin test files), have been resolved.Documentation (
README.md):README.mdfile has been extensively updated to accurately reflect all new features and significant changes.!VAULTtag syntax and the requiredVAULT_ADDRandVAULT_TOKENenvironment variables.README.mdhave been revised to demonstrate best practices fortry-exceptblocks to handle the new specificKeylockerErrorexceptions.README.mdcontent has been translated into English.Dependencies:
hvachas been added torequirements.txtas a runtime dependency.pytestandpytest-mockare confirmed as development dependencies for the test suite.