mirror of
https://github.com/telemt/telemt.git
synced 2026-11-22 23:36:36 +03:00
API: add dry-run validation with change preview and runtime guards
This commit is contained in:
@@ -38,15 +38,36 @@ pub(super) fn finish(mut parsed: ParsedConfigSource) -> Result<LoadedConfig> {
|
||||
|
||||
impl ParsedConfigSource {
|
||||
/// Resolves each unique decoy origin once, then builds a fully validated candidate.
|
||||
pub(crate) async fn prepare(mut self) -> Result<LoadedConfig> {
|
||||
decoy_dns::prepare(&mut self.config, |host, port| async move {
|
||||
tokio::net::lookup_host((host.as_str(), port))
|
||||
pub(crate) async fn prepare(self) -> Result<LoadedConfig> {
|
||||
self.prepare_guarded(Arc::new(())).await
|
||||
}
|
||||
|
||||
/// Retains a caller's preparation budget inside blocking work even if the
|
||||
/// request or DNS timeout drops its future. No worker publishes this data.
|
||||
pub(crate) async fn prepare_guarded<G: Send + Sync + 'static>(
|
||||
mut self,
|
||||
guard: Arc<G>,
|
||||
) -> Result<LoadedConfig> {
|
||||
decoy_dns::prepare(&mut self.config, |host, port| {
|
||||
let guard = guard.clone();
|
||||
async move {
|
||||
tokio::task::spawn_blocking(move || {
|
||||
use std::net::ToSocketAddrs;
|
||||
let _guard = guard;
|
||||
(host.as_str(), port)
|
||||
.to_socket_addrs()
|
||||
.map(|answers| answers.collect())
|
||||
})
|
||||
.await
|
||||
.map(|answers| answers.collect())
|
||||
.map_err(|_| std::io::Error::other("DNS preparation worker failed"))?
|
||||
}
|
||||
})
|
||||
.await?;
|
||||
tokio::task::spawn_blocking(move || finish(self))
|
||||
.await
|
||||
.map_err(|error| ProxyError::Config(format!("config preparation failed: {error}")))?
|
||||
tokio::task::spawn_blocking(move || {
|
||||
let _guard = guard;
|
||||
finish(self)
|
||||
})
|
||||
.await
|
||||
.map_err(|error| ProxyError::Config(format!("config preparation failed: {error}")))?
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
use std::sync::atomic::{AtomicU64, Ordering};
|
||||
|
||||
use super::ProxyConfig;
|
||||
|
||||
impl ProxyConfig {
|
||||
/// Identifies a publication, including a return to an earlier value. This is
|
||||
/// not a guarantee that asynchronous policy consumers have converged.
|
||||
pub(crate) fn with_publication_epoch(mut self) -> Self {
|
||||
static NEXT_EPOCH: AtomicU64 = AtomicU64::new(1);
|
||||
self.runtime_config_epoch = NEXT_EPOCH.fetch_add(1, Ordering::Relaxed);
|
||||
self
|
||||
}
|
||||
}
|
||||
@@ -505,6 +505,14 @@ const LOGGING_CONFIG_KEYS: &[&str] = &[
|
||||
// Recursive table traversal and key suggestion logic.
|
||||
mod check;
|
||||
|
||||
impl super::ProxyConfig {
|
||||
/// Checks sparse API input without permissive-mode logging or key suggestions.
|
||||
/// Dynamic map keys and accepted source aliases retain the source loader rules.
|
||||
pub(crate) fn unknown_source_paths(document: &toml::Value) -> Vec<String> {
|
||||
check::unknown_paths(document)
|
||||
}
|
||||
}
|
||||
|
||||
/// Rejects or reports unknown configuration keys according to strict mode.
|
||||
pub(super) fn handle_unknown_config_keys(parsed_toml: &toml::Value) -> Result<()> {
|
||||
let unknown = check::collect_unknown_config_keys(parsed_toml);
|
||||
|
||||
@@ -148,6 +148,20 @@ fn check_nested_table_value(
|
||||
/// Collects unknown keys across every supported nested configuration table.
|
||||
pub(super) fn collect_unknown_config_keys(parsed_toml: &toml::Value) -> Vec<UnknownConfigKey> {
|
||||
let known_for_suggestion = known_config_keys_for_suggestion();
|
||||
collect(parsed_toml, &known_for_suggestion)
|
||||
}
|
||||
|
||||
pub(super) fn unknown_paths(parsed_toml: &toml::Value) -> Vec<String> {
|
||||
collect(parsed_toml, &[])
|
||||
.into_iter()
|
||||
.map(|key| key.path)
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn collect(
|
||||
parsed_toml: &toml::Value,
|
||||
known_for_suggestion: &[&'static str],
|
||||
) -> Vec<UnknownConfigKey> {
|
||||
let mut unknown = Vec::new();
|
||||
|
||||
if let Some(root) = parsed_toml.as_table() {
|
||||
|
||||
Reference in New Issue
Block a user