Config Module (hierachain/config/*)
Overview
The Config module is the control center of HieraChain, responsible for managing hundreds of operational parameters, ensuring the security of secret keys, and providing a standardized logging mechanism for both development and production environments.
Core Components
-
Settings Management
File:
settings.py- Environment-based configuration system (
HRC_ENV). - Automatic parameter validation.
- Configuration separated by group: Blockchain, Consensus, Storage, P2P, etc.
- Environment-based configuration system (
-
Secret Manager
File:
secret_manager.py- Retrieves secrets independently of infrastructure.
- Supports backends: Environment, HashiCorp Vault, AWS Secrets Manager.
- Automatic flexible fallback.
-
Structured Logging
File:
logging.py- Text format for developers (colored, readable).
- JSON format for Production environments (compatible with ELK, Cloud Logging).
- Supports embedding Request ID for error tracing.
Environment-based Configuration
HieraChain uses the HRC_ENV environment variable to automatically switch between optimized configurations:
| Environment | HRC_ENV Value |
Key Characteristics |
|---|---|---|
| Development | dev (Default) |
DEBUG log level, SQLite/Memory storage, CORS allowed from everywhere. |
| Production | product |
Enforces Auth, HSTS, P2P Strict Trust, JSON log format. |
| Testing | test |
Fast configuration, small block size, Memory storage by default. |
Secret Manager
This is a critical component for protecting sensitive keys such as HRC_CLUSTER_SECRET or IPFS_ENCRYPTION_KEY.
Usage Example in Code:
from hierachain.config.secret_manager import SecretManager
sm = SecretManager()
# Automatically retrieves from Vault, AWS, or Env depending on configuration
cluster_key = sm.get_secret("HRC_CLUSTER_SECRET")
Supported Backends:
- Environment (
env): Default, reads directly from environment variables. - Vault (
vault): Connects to HashiCorp Vault KV v2. - AWS (
aws): Connects to AWS Secrets Manager.
Standardized Logging (Observability)
You can change the log format via the HRC_LOG_FORMAT environment variable:
-
For Dev (
text): -
For Ops (
json):
Configuration Validation
HieraChain validates configuration at startup to prevent potential operational errors:
validate_config(): Checks logical values (e.g., Port must be 1-65535, Block size > 0).check_security_config(): Warns if security settings in Production are insufficient (e.g., Auth disabled or CORS-all enabled).