Reinhardt Configuration Framework
Django-inspired settings management for Rust with secrets, encryption, and audit logging.
Overview
The reinhardt-conf crate provides a comprehensive configuration management framework for Reinhardt applications, inspired by Django's settings system with additional security features.
Features
- Multiple configuration sources: Files, environment variables, command-line arguments
- Type-safe settings: Strong type validation with custom validators
- Secrets management: Integration with HashiCorp Vault, AWS Secrets Manager, Azure Key Vault
- Encryption: Built-in encryption for sensitive settings
- Dynamic backends: Redis and database-backed dynamic settings
- Secret rotation: Automatic secret rotation support
- Audit logging: Track all setting changes
Modules
This crate provides the following modules:
`settings`: Core settings management functionality
Installation
Add reinhardt to your Cargo.toml:
[]
= { = "0.1.2", = ["conf"] }
# Or use a preset:
# reinhardt = { version = "0.1.2", features = ["standard"] } # Recommended
# reinhardt = { version = "0.1.2", features = ["full"] } # All features
Then import configuration features:
use ;
use ConfigSource;
Note: Configuration features are included in the standard and full feature presets.
Optional Features
Enable specific features based on your needs:
# With async support
= { = "0.1.2", = ["conf", "async"] }
# With encryption
= { = "0.1.2", = ["conf", "encryption"] }
# With Vault integration
= { = "0.1.2", = ["conf", "vault"] }
Available features:
settings(default): Core settings functionalityasync: Asynchronous settings operationsdynamic-redis: Redis-backed dynamic settingsdynamic-database: Database-backed dynamic settingsvault: HashiCorp Vault integrationaws-secrets: AWS Secrets Manager integrationazure-keyvault: Azure Key Vault integrationsecret-rotation: Automatic secret rotationencryption: Built-in encryption for sensitive settings
Usage
use SettingsBuilder;
use ConfigSource;
// Basic usage
let settings = new
.add_source
.add_source
.build?;
// Access settings
let database_url = settings.?;
Configuration Sources
TOML Interpolation
Opt-in ${VAR} substitution for TOML string values.
| Token | Behavior |
|---|---|
${VAR} |
required — fails if VAR is unset OR empty |
${VAR:-default} |
substitutes default if VAR is unset OR empty |
${VAR:-} |
explicit empty fallback (special case of :-) |
${VAR:?message} |
fails with message if VAR is unset OR empty |
$$ |
escape — emits a literal $ |
Variable names follow POSIX conventions: [A-Za-z_][A-Za-z0-9_]*.
Interpolation is enabled by default since 0.1.0-rc.27. Call
.without_interpolation() if you need raw ${...} strings to survive
the load (for example, when the TOML is itself a template that
downstream code expands).
use SettingsBuilder;
use TomlFileSource;
let settings = new
// Interpolation is on by default — no builder method required.
.add_source
.build?;
// Opt out when literal `${...}` must survive:
// .add_source(TomlFileSource::new("settings/template.toml").without_interpolation())
Example TOML:
[]
= "${REINHARDT_DB_HOST:-localhost}"
= "${REINHARDT_DB_PORT:-5432}"
[]
= "${DB_PASSWORD:?Set DB_PASSWORD via direnv or 1Password CLI}"
Behavior Notes
-
Strict empty handling: an empty environment-variable value is treated identically to "unset". This catches typos like
export REINHARDT_DB_HOST=early. To allow an explicit empty fallback, write${VAR:-}. -
Single-pass: resolved values are not re-expanded, so
${OUTER}whose value happens to contain${INNER}resolves to literally${INNER}. -
String-only scope: only
toml::Value::Stringis rewritten, but every string in the TOML tree is scanned — strings inside nested tables and arrays are interpolated as well. Numeric, boolean, and datetime values pass through untouched. To inject a typed override useHighPriorityEnvSource(priority 60 — beats interpolated TOML at priority 50). -
Composition: interpolation runs at
TomlFileSource::load()time. The resolved value participates in the normal source-priority merge; later sources at higher priority still override. -
Typed coercion (since 0.1.0-rc.27, default ON): a resolved string value whose destination Rust type is non-
Stringis coerced into the target at deserialize time. Supported destinations:Target Source string format bool, integers, floats,charFromStr-parseable textenum unit variant variant name (matched via serde's normal rules) Option<T>empty string -> None, otherwise recurse intoTVec<T>JSON array literal: "[1, 2, 3]"HashMap<K, V>/BTreeMapJSON object literal: "{\"a\": 1}"Vec<u8>base64 (STANDARD) Coercion failures abort
SettingsBuilder::build_composed()withBuildError::Coercion, naming the TOML key path, target type, original value, and parser cause.Disable with
SettingsBuilder::with_typed_coercion(false)to fall back to the legacy serde-json passthrough. -
Nested struct from a single string is rejected with
CoercionError::UnsupportedShape. Use per-field interpolation instead:[] = "${HOST:-localhost}" = "${PORT:-5432}"
Field Status
The Settings struct contains fields that are either actively consumed by the framework or reserved for future implementation.
Active Fields
These fields are actively consumed by the framework and affect runtime behavior:
| Field | Description |
|---|---|
base_dir |
Base directory of the project |
secret_key |
Secret key for cryptographic signing |
debug |
Debug mode toggle |
allowed_hosts |
List of allowed host/domain names |
installed_apps |
List of installed applications |
middleware |
List of middleware classes |
root_urlconf |
Root URL configuration module |
databases |
Database configurations |
static_url |
Static files URL prefix |
static_root |
Static files root directory |
staticfiles_dirs |
Additional static files directories |
media_url |
Media files URL prefix |
media_root |
Media files root directory |
secure_proxy_ssl_header |
Proxy SSL header configuration |
secure_ssl_redirect |
HTTPS redirect toggle |
secure_hsts_seconds |
HSTS max-age header value |
secure_hsts_include_subdomains |
HSTS subdomain inclusion |
secure_hsts_preload |
HSTS preload directive |
session_cookie_secure |
Secure session cookie toggle |
csrf_cookie_secure |
Secure CSRF cookie toggle |
append_slash |
Trailing slash auto-append toggle |
admins |
Administrator contact list |
managers |
Manager contact list |
Reserved for Future Implementation
These fields exist for Django settings compatibility but are not yet consumed by the framework. Setting these values currently has no effect on framework behavior:
| Field | Description | Planned Feature |
|---|---|---|
language_code |
Language code (default: "en-us") |
i18n support |
time_zone |
Time zone (default: "UTC") |
Timezone-aware datetime handling |
use_i18n |
Enable i18n (default: true) |
i18n support |
use_tz |
Enable timezone-aware datetimes (default: true) |
Timezone-aware datetime handling |
templates |
Template engine configurations | Template engine integration |
default_auto_field |
Default auto field type for models | Auto field configuration |
Module Organization
`reinhardt-conf` is organized into the following modules:
`settings`- Core settings management (builder, validation, encryption)
Using Modules
use ;
License
Licensed under the BSD 3-Clause License.
Contributing
Contributions are welcome! Please see the main CONTRIBUTING.md for guidelines.