openzeppelin_monitor/models/config/mod.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
//! Configuration loading and validation.
//!
//! This module provides traits and implementations for loading and validating
//! configuration files for networks, monitors, and triggers.
#![allow(clippy::result_large_err)]
use async_trait::async_trait;
use std::path::Path;
mod error;
mod monitor_config;
mod network_config;
mod trigger_config;
pub use error::ConfigError;
/// Common interface for loading configuration files
#[async_trait]
pub trait ConfigLoader: Sized {
/// Load all configuration files from a directory
///
/// If no path is provided, uses the default config directory.
async fn load_all<T>(path: Option<&Path>) -> Result<T, error::ConfigError>
where
T: FromIterator<(String, Self)>;
/// Load configuration from a specific file path
async fn load_from_path(path: &Path) -> Result<Self, error::ConfigError>;
/// Validate the configuration
///
/// Returns Ok(()) if valid, or an error message if invalid.
fn validate(&self) -> Result<(), error::ConfigError>;
/// Validate safety of the protocol
///
/// Returns if safe, or logs a warning message if unsafe.
fn validate_protocol(&self);
/// Check if a file is a JSON file based on extension
fn is_json_file(path: &Path) -> bool {
path.extension()
.map(|ext| ext.to_string_lossy().to_lowercase() == "json")
.unwrap_or(false)
}
/// Resolve all secrets in the configuration
async fn resolve_secrets(&self) -> Result<Self, ConfigError>;
}