add support for reading a registration token from a file

Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
strawberry 2024-09-29 01:54:07 -04:00
parent ee1580e480
commit 7a59add8f1
10 changed files with 78 additions and 21 deletions

View file

@ -41,6 +41,7 @@ pub struct Service {
pub server_user: OwnedUserId,
pub admin_alias: OwnedRoomAliasId,
pub turn_secret: String,
pub registration_token: Option<String>,
}
type RateLimitState = (Instant, u32); // Time if last failed try, number of failed tries
@ -96,6 +97,20 @@ impl crate::Service for Service {
})
});
let registration_token =
config
.registration_token_file
.as_ref()
.map_or(config.registration_token.clone(), |path| {
let Ok(token) = std::fs::read_to_string(path).inspect_err(|e| {
error!("Failed to read the registration token file: {e}");
}) else {
return config.registration_token.clone();
};
Some(token)
});
let mut s = Self {
db,
config: config.clone(),
@ -112,6 +127,7 @@ impl crate::Service for Service {
server_user: UserId::parse_with_server_name(String::from("conduit"), &config.server_name)
.expect("@conduit:server_name is valid"),
turn_secret,
registration_token,
};
if !s