use crate::serve::error::ServeError;
use crate::serve::rbac::AuthContext;
use crate::serve::state::ServerState;
use axum::Json;
use axum::extract::{Extension, State};
use serde_json::{Value, json};
pub async fn reload(
State(state): State<ServerState>,
Extension(actor): Extension<AuthContext>,
) -> Result<Json<Value>, ServeError> {
let Some(path) = state.default_config_path().cloned() else {
crate::serve::audit::write(&state, &actor, "config.reload", None, None, "noop").await;
return Ok(Json(json!({
"reloaded": false,
"reason": "no --default-config configured; nothing to reload",
})));
};
let profile = std::env::var("FAUCET_PROFILE").ok();
match crate::config::PipelineConfig::from_path_async(&path, profile.as_deref()).await {
Ok(cfg) => {
let value = serde_json::to_value(&cfg).map_err(|e| {
ServeError::Internal(format!("serializing reloaded --default-config: {e}"))
})?;
state.set_default_base(Some(value));
tracing::info!(path = %path.display(), "reloaded --default-config (POST /v1/reload)");
crate::serve::audit::write(&state, &actor, "config.reload", None, None, "ok").await;
Ok(Json(json!({
"reloaded": true,
"path": path.display().to_string(),
})))
}
Err(e) => {
crate::serve::audit::write(&state, &actor, "config.reload", None, None, "rejected")
.await;
Err(ServeError::Unprocessable {
message: format!("reload rejected — keeping previous config: {e}"),
details: None,
})
}
}
}