fix/simplify emergency access initialization
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
b2e56777af
commit
dd49b3c3a1
2 changed files with 19 additions and 34 deletions
|
@ -1,9 +1,6 @@
|
||||||
use conduit::Result;
|
use conduit::Result;
|
||||||
use ruma::{
|
use ruma::{
|
||||||
events::{
|
events::{push_rules::PushRulesEventContent, GlobalAccountDataEvent, GlobalAccountDataEventType},
|
||||||
push_rules::PushRulesEventContent, room::message::RoomMessageEventContent, GlobalAccountDataEvent,
|
|
||||||
GlobalAccountDataEventType,
|
|
||||||
},
|
|
||||||
push::Ruleset,
|
push::Ruleset,
|
||||||
UserId,
|
UserId,
|
||||||
};
|
};
|
||||||
|
@ -11,28 +8,11 @@ use tracing::{error, warn};
|
||||||
|
|
||||||
use crate::services;
|
use crate::services;
|
||||||
|
|
||||||
pub(crate) async fn init_emergency_access() {
|
/// Set emergency access for the conduit user
|
||||||
// Set emergency access for the conduit user
|
pub(crate) fn init_emergency_access() {
|
||||||
match set_emergency_access() {
|
if let Err(e) = set_emergency_access() {
|
||||||
Ok(pwd_set) => {
|
error!("Could not set the configured emergency password for the conduit user: {e}");
|
||||||
if pwd_set {
|
}
|
||||||
warn!(
|
|
||||||
"The Conduit account emergency password is set! Please unset it as soon as you finish admin \
|
|
||||||
account recovery!"
|
|
||||||
);
|
|
||||||
services()
|
|
||||||
.admin
|
|
||||||
.send_message(RoomMessageEventContent::text_plain(
|
|
||||||
"The Conduit account emergency password is set! Please unset it as soon as you finish admin \
|
|
||||||
account recovery!",
|
|
||||||
))
|
|
||||||
.await;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Err(e) => {
|
|
||||||
error!("Could not set the configured emergency password for the conduit user: {}", e);
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the emergency password and push rules for the @conduit account in case
|
/// Sets the emergency password and push rules for the @conduit account in case
|
||||||
|
@ -45,9 +25,9 @@ fn set_emergency_access() -> Result<bool> {
|
||||||
.users
|
.users
|
||||||
.set_password(&conduit_user, services().globals.emergency_password().as_deref())?;
|
.set_password(&conduit_user, services().globals.emergency_password().as_deref())?;
|
||||||
|
|
||||||
let (ruleset, res) = match services().globals.emergency_password() {
|
let (ruleset, pwd_set) = match services().globals.emergency_password() {
|
||||||
Some(_) => (Ruleset::server_default(&conduit_user), Ok(true)),
|
Some(_) => (Ruleset::server_default(&conduit_user), true),
|
||||||
None => (Ruleset::new(), Ok(false)),
|
None => (Ruleset::new(), false),
|
||||||
};
|
};
|
||||||
|
|
||||||
services().account_data.update(
|
services().account_data.update(
|
||||||
|
@ -62,5 +42,12 @@ fn set_emergency_access() -> Result<bool> {
|
||||||
.expect("to json value always works"),
|
.expect("to json value always works"),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
res
|
if pwd_set {
|
||||||
|
warn!(
|
||||||
|
"The Conduit account emergency password is set! Please unset it as soon as you finish admin account \
|
||||||
|
recovery!"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(pwd_set)
|
||||||
}
|
}
|
||||||
|
|
|
@ -276,14 +276,12 @@ bad_signature_ratelimiter: {bad_signature_ratelimiter}
|
||||||
|
|
||||||
pub async fn start(&self) -> Result<()> {
|
pub async fn start(&self) -> Result<()> {
|
||||||
debug_info!("Starting services");
|
debug_info!("Starting services");
|
||||||
|
|
||||||
globals::migrations::migrations(&self.db, &self.globals.config).await?;
|
globals::migrations::migrations(&self.db, &self.globals.config).await?;
|
||||||
|
globals::emerg_access::init_emergency_access();
|
||||||
|
|
||||||
self.admin.start_handler().await;
|
self.admin.start_handler().await;
|
||||||
|
|
||||||
globals::emerg_access::init_emergency_access().await;
|
|
||||||
|
|
||||||
self.sending.start_handler().await;
|
self.sending.start_handler().await;
|
||||||
|
|
||||||
if self.globals.config.allow_local_presence {
|
if self.globals.config.allow_local_presence {
|
||||||
self.presence.start_handler().await;
|
self.presence.start_handler().await;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue