fix/simplify emergency access initialization
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
b2e56777af
commit
dd49b3c3a1
|
@ -1,9 +1,6 @@
|
|||
use conduit::Result;
|
||||
use ruma::{
|
||||
events::{
|
||||
push_rules::PushRulesEventContent, room::message::RoomMessageEventContent, GlobalAccountDataEvent,
|
||||
GlobalAccountDataEventType,
|
||||
},
|
||||
events::{push_rules::PushRulesEventContent, GlobalAccountDataEvent, GlobalAccountDataEventType},
|
||||
push::Ruleset,
|
||||
UserId,
|
||||
};
|
||||
|
@ -11,28 +8,11 @@ use tracing::{error, warn};
|
|||
|
||||
use crate::services;
|
||||
|
||||
pub(crate) async fn init_emergency_access() {
|
||||
// Set emergency access for the conduit user
|
||||
match set_emergency_access() {
|
||||
Ok(pwd_set) => {
|
||||
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);
|
||||
},
|
||||
};
|
||||
/// Set emergency access for the conduit user
|
||||
pub(crate) fn init_emergency_access() {
|
||||
if let Err(e) = set_emergency_access() {
|
||||
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
|
||||
|
@ -45,9 +25,9 @@ fn set_emergency_access() -> Result<bool> {
|
|||
.users
|
||||
.set_password(&conduit_user, services().globals.emergency_password().as_deref())?;
|
||||
|
||||
let (ruleset, res) = match services().globals.emergency_password() {
|
||||
Some(_) => (Ruleset::server_default(&conduit_user), Ok(true)),
|
||||
None => (Ruleset::new(), Ok(false)),
|
||||
let (ruleset, pwd_set) = match services().globals.emergency_password() {
|
||||
Some(_) => (Ruleset::server_default(&conduit_user), true),
|
||||
None => (Ruleset::new(), false),
|
||||
};
|
||||
|
||||
services().account_data.update(
|
||||
|
@ -62,5 +42,12 @@ fn set_emergency_access() -> Result<bool> {
|
|||
.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<()> {
|
||||
debug_info!("Starting services");
|
||||
|
||||
globals::migrations::migrations(&self.db, &self.globals.config).await?;
|
||||
globals::emerg_access::init_emergency_access();
|
||||
|
||||
self.admin.start_handler().await;
|
||||
|
||||
globals::emerg_access::init_emergency_access().await;
|
||||
|
||||
self.sending.start_handler().await;
|
||||
|
||||
if self.globals.config.allow_local_presence {
|
||||
self.presence.start_handler().await;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue