config-vault

Crates.ioconfig-vault
lib.rsconfig-vault
version0.2.0
created_at2025-05-04 10:27:48.656534+00
updated_at2025-06-12 20:27:46.867302+00
descriptionAn extension for the config crate that allows loading configurations from HashiCorp Vault
homepage
repositoryhttps://github.com/edugzlez/config-vault
max_upload_size
id1659520
size64,515
Eduardo González Vaquero (edugzlez)

documentation

https://docs.rs/config-vault

README

config-vault

Crates.io Documentation License: MIT

An extension for the config crate that allows loading configurations from HashiCorp Vault.

Features

  • Integration with the config crate through a custom VaultSource
  • Support for HashiCorp Vault's KV1 & 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
    );

    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(())
}

Documentation

For more information, check the complete documentation.

Requirements

  • Rust 1.60 or higher
  • An accessible HashiCorp Vault server or compatible like RustyVault

License

This project is licensed under the MIT License - see the LICENSE file for details.

Commit count: 0

cargo fmt