Config hot reloading API
This commit is contained in:
@@ -380,29 +380,77 @@ impl JMAP {
|
||||
.into_http_response(),
|
||||
}
|
||||
}
|
||||
("reload", Some("settings"), &Method::GET) => {
|
||||
/*let _ = self
|
||||
.inner
|
||||
.housekeeper_tx
|
||||
.send(housekeeper::Event::ReloadConfig)
|
||||
.await;*/
|
||||
("reload", Some("lookup"), &Method::GET) => {
|
||||
match self.core.reload_lookups().await {
|
||||
Ok(result) => {
|
||||
// Update core
|
||||
if let Some(core) = result.new_core {
|
||||
self.shared_core.store(core.into());
|
||||
}
|
||||
|
||||
JsonResponse::new(json!({
|
||||
"data": (),
|
||||
}))
|
||||
.into_http_response()
|
||||
JsonResponse::new(json!({
|
||||
"data": result.config,
|
||||
}))
|
||||
.into_http_response()
|
||||
}
|
||||
Err(err) => RequestError::blank(
|
||||
StatusCode::INTERNAL_SERVER_ERROR.as_u16(),
|
||||
"Database error",
|
||||
err.to_string(),
|
||||
)
|
||||
.into_http_response(),
|
||||
}
|
||||
}
|
||||
("reload", Some("certificates"), &Method::GET) => {
|
||||
/*let _ = self
|
||||
.inner
|
||||
.housekeeper_tx
|
||||
.send(housekeeper::Event::ReloadCertificates)
|
||||
.await;*/
|
||||
("reload", Some("certificate"), &Method::GET) => {
|
||||
match self.core.reload_certificates().await {
|
||||
Ok(result) => JsonResponse::new(json!({
|
||||
"data": result.config,
|
||||
}))
|
||||
.into_http_response(),
|
||||
Err(err) => RequestError::blank(
|
||||
StatusCode::INTERNAL_SERVER_ERROR.as_u16(),
|
||||
"Database error",
|
||||
err.to_string(),
|
||||
)
|
||||
.into_http_response(),
|
||||
}
|
||||
}
|
||||
("reload", Some("server.blocked-ip"), &Method::GET) => {
|
||||
match self.core.reload_blocked_ips().await {
|
||||
Ok(result) => JsonResponse::new(json!({
|
||||
"data": result.config,
|
||||
}))
|
||||
.into_http_response(),
|
||||
Err(err) => RequestError::blank(
|
||||
StatusCode::INTERNAL_SERVER_ERROR.as_u16(),
|
||||
"Database error",
|
||||
err.to_string(),
|
||||
)
|
||||
.into_http_response(),
|
||||
}
|
||||
}
|
||||
("reload", _, &Method::GET) => {
|
||||
match self.core.reload().await {
|
||||
Ok(result) => {
|
||||
if !UrlParams::new(req.uri().query()).has_key("dry-run") {
|
||||
// Update core
|
||||
if let Some(core) = result.new_core {
|
||||
self.shared_core.store(core.into());
|
||||
}
|
||||
}
|
||||
|
||||
JsonResponse::new(json!({
|
||||
"data": (),
|
||||
}))
|
||||
.into_http_response()
|
||||
JsonResponse::new(json!({
|
||||
"data": result.config,
|
||||
}))
|
||||
.into_http_response()
|
||||
}
|
||||
Err(err) => RequestError::blank(
|
||||
StatusCode::INTERNAL_SERVER_ERROR.as_u16(),
|
||||
"Database error",
|
||||
err.to_string(),
|
||||
)
|
||||
.into_http_response(),
|
||||
}
|
||||
}
|
||||
("settings", Some("group"), &Method::GET) => {
|
||||
// List settings
|
||||
|
||||
@@ -82,6 +82,7 @@ pub const LONG_SLUMBER: Duration = Duration::from_secs(60 * 60 * 24);
|
||||
#[derive(Clone)]
|
||||
pub struct JMAP {
|
||||
pub core: Arc<Core>,
|
||||
pub shared_core: SharedCore,
|
||||
pub inner: Arc<Inner>,
|
||||
pub smtp: SMTP,
|
||||
}
|
||||
@@ -571,6 +572,7 @@ impl JMAP {
|
||||
|
||||
impl From<JmapInstance> for JMAP {
|
||||
fn from(value: JmapInstance) -> Self {
|
||||
let shared_core = value.core.clone();
|
||||
let core = value.core.load().clone();
|
||||
JMAP {
|
||||
smtp: SMTP {
|
||||
@@ -578,6 +580,7 @@ impl From<JmapInstance> for JMAP {
|
||||
inner: value.smtp_inner,
|
||||
},
|
||||
core,
|
||||
shared_core,
|
||||
inner: value.jmap_inner,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user