figment_file_provider_adapter

Crates.iofigment_file_provider_adapter
lib.rsfigment_file_provider_adapter
version0.1.1
sourcesrc
created_at2022-09-13 13:40:53.227474
updated_at2023-10-31 19:59:49.364555
descriptionA Figment provider wrapper to load config values from files
homepagehttps://github.com/nitnelave/figment_file_provider_adapter
repositoryhttps://github.com/nitnelave/figment_file_provider_adapter
max_upload_size
id664588
size25,604
nitnelave (nitnelave)

documentation

https://docs.rs/figment_file_provider_adapter

README

Figment File Provider Adapter   ci.svg crates.io docs.rs

Figment provider for optionally file-based config values, working with any provider.

use serde::Deserialize;
use figment::{Figment, providers::{Env, Format, Toml}};
use figment_file_provider_adapter::FileAdapter;

#[derive(Deserialize)]
struct Config {
  frobnicate: String,
  foo: u64,
}

let config: Config = Figment::new()
    .merge(FileAdapter::wrap(Env::prefixed("APP_")))
    .merge(FileAdapter::wrap(Toml::file("config.toml")))
    .extract()?;

Overview

This crate contains the FileAdapter provider for Figment, to allow loading configuration values from either direct values or files. It wraps around an existing provider, and for every key that ends in "_FILE" it replaces the value with reading the file mentioned. This is especially useful for secret management in combination with containers.

For instance, to pass an API key to the configuration, you could use either the config value API_KEY=abc123deadbeef, or you could write that API key to a file /secrets/api_key and pass the config value API_KEY_FILE=/secrets/api_key.

See the documentation for a detailed usage guide and more information.

Usage

Add the following to your Cargo.toml:

[dependencies]
figment = { version = "0.10" }
figment_file_provider_adapter = { version = "0.1" }

License

figment_file_provider_adapter is licensed under either of the MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT).

Commit count: 5

cargo fmt