#api-key #provider #secret-management #figment #values #key-file #configuration

figment_file_provider_adapter

A Figment provider wrapper to load config values from files

2 releases

0.1.1 Oct 31, 2023
0.1.0 Sep 13, 2022

#186 in Configuration

Download history 49/week @ 2023-12-12 14/week @ 2023-12-19 115/week @ 2023-12-26 43/week @ 2024-01-02 56/week @ 2024-01-09 87/week @ 2024-01-16 45/week @ 2024-01-23 55/week @ 2024-01-30 35/week @ 2024-02-06 81/week @ 2024-02-13 111/week @ 2024-02-20 93/week @ 2024-02-27 236/week @ 2024-03-05 266/week @ 2024-03-12 254/week @ 2024-03-19 123/week @ 2024-03-26

901 downloads per month

MIT license

26KB
388 lines

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).

Dependencies

~1–1.5MB
~32K SLoC