| Crates.io | config-vault |
| lib.rs | config-vault |
| version | 0.2.0 |
| created_at | 2025-05-04 10:27:48.656534+00 |
| updated_at | 2025-06-12 20:27:46.867302+00 |
| description | An extension for the config crate that allows loading configurations from HashiCorp Vault |
| homepage | |
| repository | https://github.com/edugzlez/config-vault |
| max_upload_size | |
| id | 1659520 |
| size | 64,515 |
An extension for the config crate that allows loading configurations from HashiCorp Vault.
config crate through a custom VaultSourceAdd the dependency to your Cargo.toml:
[dependencies]
config-vault = "0.1.0"
config = "0.15.11" # The version compatible with config-vault
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
);
vault_source.set_kv_version(KvVersion::V1); // change kv_version to KV1 if required
// 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(())
}
For more information, check the complete documentation.
This project is licensed under the MIT License - see the LICENSE file for details.