Config Resolver
A modular, lightweight, and extensible configuration resolver for Rust that allows auto-detecting and resolving configuration values (such as IP addresses, port numbers, peer IDs, and socket addresses) at runtime.
This is particularly useful for containerized applications, cloud environments (AWS, DigitalOcean), or P2P/distributed systems where static configuration files are insufficient, and bindings must adapt dynamically to the environment.
Features
- Recursive Parsing & Resolution:
- Static values: Supports standard Rust parser values like
127.0.0.1,3000, or127.0.0.1:8080. - Dynamic Lookups: Resolves variables like
DO_PUBLIC_IPorAWS_PRIVATE_IPby querying metadata services. - Combined Addresses: Construct complex Socket addresses dynamically, e.g.,
DO_PUBLIC_IP:3000orIPIFY:8080. - Offset Calculations: Performs mathematical calculations directly on IP addresses (converting IPv4 to a unique
u64base and adding an offset), e.g.,CALC(DO_PUBLIC_IP+10000). Useful for generating unique Peer IDs in distributed protocols.
- Static values: Supports standard Rust parser values like
- Type-Safe: Clean parsing into standard library types like
IpAddr,SocketAddr,u32, andu64via theConfigUnittrait. - Feature-Gated Providers: AWS, DigitalOcean, and Ipify HTTP-based lookups can be compiled conditionally, keeping the crate extremely lightweight when only static resolution or custom providers are needed.
- Extensible: Define your own custom provider by implementing the
ConfigProvidertrait and registering it with theConfigRegistry.
Installation
Add config-resolver to your Cargo.toml:
[]
= "0.1"
If you only need static resolution or custom providers (no remote metadata calls over HTTP), disable the default features to eliminate the dependency on reqwest and TLS:
[]
= { = "0.1", = false }
Cargo Features
By default, all cloud metadata and external providers are enabled. You can disable them or select only what you need:
| Feature | Description | Dependencies | Enabled by Default |
|---|---|---|---|
aws |
AWS EC2 Instance Metadata Service (IMDSv2) provider (AWS_PUBLIC_IP, AWS_PRIVATE_IP) |
reqwest |
Yes |
digital-ocean |
DigitalOcean Droplet metadata provider (DO_PUBLIC_IP, DO_PRIVATE_IP) |
reqwest |
Yes |
ipify |
Public IP lookup via api.ipify.org (IPIFY) |
reqwest |
Yes |
Usage
1. Basic Resolution
use ;
use create_default_registry;
async
2. Integration with clap
You can take configuration strings directly from CLI flags or environment variables, and resolve them at startup:
use Parser;
use ;
use create_default_registry;
async
3. Custom Providers
You can easily register your own resolution providers:
use async_trait;
use ;
use IpAddr;
;
async
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.