1 unstable release
new 0.1.0 | May 4, 2025 |
---|
#470 in Configuration
18KB
71 lines
config-vault
An extension for the config
crate that allows loading configurations from HashiCorp Vault.
Features
- Integration with the
config
crate through a customVaultSource
- Support for HashiCorp Vault's KV2 engine
- Secure loading of secrets through Vault's REST API
Installation
Add the dependency to your Cargo.toml
:
[dependencies]
config-vault = "0.1.0"
config = "0.15.11" # The version compatible with config-vault
Basic Usage
use config::{Config, ConfigError};
use config_vault::VaultSource;
fn load_config() -> Result<Config, ConfigError> {
let vault_source = VaultSource::new(
"http://127.0.0.1:8200".to_string(), // Vault address
"hvs.EXAMPLE_TOKEN".to_string(), // Vault token
"secret".to_string(), // KV mount name
"dev".to_string(), // Secret path
);
// Build configuration incorporating Vault and other sources
Config::builder()
.add_source(vault_source)
// You can add other configuration sources
// .add_source(config::File::with_name("config/default"))
// .add_source(config::Environment::with_prefix("APP"))
.build()
}
fn main() -> Result<(), ConfigError> {
let config = load_config()?;
// Use the configuration as usual
let db_url = config.get_string("database.url")?;
println!("Database URL: {}", db_url);
Ok(())
}
Documentation
For more information, check the complete documentation.
Requirements
- Rust 1.60 or higher
- An accessible HashiCorp Vault server
License
This project is licensed under the MIT License - see the LICENSE file for details.
Dependencies
~7–19MB
~261K SLoC