This commit is contained in:
Mateusz Gruszczyński committed 2026-11-14 21:52:48 +01:00
1 parent f48843e934
commit e2c8099d9c
64 files changed
+5354 -673

No files matched your search

+28 -4
View File
@@ -72,10 +72,10 @@ async fn cache_rules_test(
|error: anyhow::Error| ApiError(StatusCode::UNPROCESSABLE_ENTITY, error.to_string());
let snapshot = state.config.load_full();
let config = &snapshot.envelope.config;
let vhosts = cache_rule_vhosts(&state);
let vhost = match input.vhost_id.as_deref().filter(|id| !id.is_empty()) {
Some(id) => Some(
config
.vhosts
vhosts
.iter()
.find(|vhost| vhost.id == id)
.ok_or_else(|| ApiError(StatusCode::NOT_FOUND, "unknown vhost".into()))?,
@@ -212,8 +212,7 @@ async fn cache_rules_test(
"reason": store_reason,
});
let deliver = rules.evaluate_deliver(&request, status, &response_headers, false);
deliver_value =
json!({"matched": deliver.matched, "set": deliver.set, "remove": deliver.remove});
deliver_value = json!({"matched": deliver.matched, "set": deliver.set, "remove": deliver.remove, "defaults": deliver.defaults});
}
Ok(Json(json!({
"host": host,
@@ -246,6 +245,31 @@ async fn cache_rules_import_vcl(
Ok(Json(json!(result)))
}
fn cache_rule_vhosts(state: &Arc<App>) -> Vec<crate::vhost::Vhost> {
let snapshot = state.config.load_full();
let config = &snapshot.envelope.config;
if config.docker_agents.agents.is_empty() {
return config.vhosts.clone();
}
crate::docker::effective_config(config.clone(), &state.docker.latest())
.map(|effective| effective.vhosts)
.unwrap_or_else(|_| config.vhosts.clone())
}
async fn cache_rules_targets(State(state): State<Arc<App>>) -> Json<Value> {
let targets: Vec<Value> = cache_rule_vhosts(&state)
.iter()
.map(|vhost| {
json!({
"id": &vhost.id,
"hosts": vhost.frontend.hosts.iter().take(4).collect::<Vec<_>>(),
"docker": vhost.id.starts_with("docker-"),
})
})
.collect();
Json(json!({ "targets": targets }))
}
async fn cache_rules_stats() -> Json<Value> {
Json(json!({"hits": crate::cache::rule_hit_counts()}))
}