improvement: better deploy guide

This commit is contained in:
Timo Kösters 2021-01-01 13:47:53 +01:00
parent d7e56dbfa0
commit b4818716b8
No known key found for this signature in database
GPG key ID: 24DA7517711A2BA4
7 changed files with 131 additions and 71 deletions

View file

@ -86,7 +86,7 @@ pub async fn register_route(
db: State<'_, Database>,
body: Ruma<register::Request<'_>>,
) -> ConduitResult<register::Response> {
if db.globals.registration_disabled() {
if !db.globals.allow_registration() {
return Err(Error::BadRequest(
ErrorKind::Forbidden,
"Registration has been disabled.",

View file

@ -240,7 +240,7 @@ pub async fn create_room_route(
.map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "Invalid initial state event."))?;
// Silently skip encryption events if they are not allowed
if pdu_builder.event_type == EventType::RoomEncryption && db.globals.encryption_disabled() {
if pdu_builder.event_type == EventType::RoomEncryption && !db.globals.allow_encryption() {
continue;
}

View file

@ -33,11 +33,19 @@ pub struct Config {
#[serde(default = "default_max_concurrent_requests")]
max_concurrent_requests: u16,
#[serde(default)]
registration_disabled: bool,
#[serde(default)]
encryption_disabled: bool,
#[serde(default)]
federation_disabled: bool,
allow_registration: bool,
#[serde(default = "true_fn")]
allow_encryption: bool,
#[serde(default = "false_fn")]
allow_federation: bool,
}
fn false_fn() -> bool {
false
}
fn true_fn() -> bool {
true
}
fn default_cache_capacity() -> u64 {

View file

@ -111,16 +111,16 @@ impl Globals {
self.config.max_request_size
}
pub fn registration_disabled(&self) -> bool {
self.config.registration_disabled
pub fn allow_registration(&self) -> bool {
self.config.allow_registration
}
pub fn encryption_disabled(&self) -> bool {
self.config.encryption_disabled
pub fn allow_encryption(&self) -> bool {
self.config.allow_encryption
}
pub fn federation_disabled(&self) -> bool {
self.config.federation_disabled
pub fn allow_federation(&self) -> bool {
self.config.allow_federation
}
pub fn dns_resolver(&self) -> &TokioAsyncResolver {

View file

@ -786,8 +786,8 @@ impl Rooms {
#[allow(clippy::blocks_in_if_conditions)]
if !match event_type {
EventType::RoomEncryption => {
// Don't allow encryption events when it's disabled
!globals.encryption_disabled()
// Only allow encryption events if it's allowed in the config
globals.allow_encryption()
}
EventType::RoomMember => {
let prev_event = self

View file

@ -36,7 +36,7 @@ pub async fn send_request<T: OutgoingRequest>(
where
T: Debug,
{
if globals.federation_disabled() {
if !globals.allow_federation() {
return Err(Error::bad_config("Federation is disabled."));
}
@ -322,7 +322,7 @@ pub async fn request_well_known(
pub fn get_server_version_route(
db: State<'_, Database>,
) -> ConduitResult<get_server_version::Response> {
if db.globals.federation_disabled() {
if !db.globals.allow_federation() {
return Err(Error::bad_config("Federation is disabled."));
}
@ -337,7 +337,7 @@ pub fn get_server_version_route(
#[cfg_attr(feature = "conduit_bin", get("/_matrix/key/v2/server"))]
pub fn get_server_keys_route(db: State<'_, Database>) -> Json<String> {
if db.globals.federation_disabled() {
if !db.globals.allow_federation() {
// TODO: Use proper types
return Json("Federation is disabled.".to_owned());
}
@ -390,7 +390,7 @@ pub async fn get_public_rooms_filtered_route(
db: State<'_, Database>,
body: Ruma<get_public_rooms_filtered::v1::Request<'_>>,
) -> ConduitResult<get_public_rooms_filtered::v1::Response> {
if db.globals.federation_disabled() {
if !db.globals.allow_federation() {
return Err(Error::bad_config("Federation is disabled."));
}
@ -437,7 +437,7 @@ pub async fn get_public_rooms_route(
db: State<'_, Database>,
body: Ruma<get_public_rooms::v1::Request<'_>>,
) -> ConduitResult<get_public_rooms::v1::Response> {
if db.globals.federation_disabled() {
if !db.globals.allow_federation() {
return Err(Error::bad_config("Federation is disabled."));
}
@ -484,7 +484,7 @@ pub async fn send_transaction_message_route<'a>(
db: State<'a, Database>,
body: Ruma<send_transaction_message::v1::Request<'_>>,
) -> ConduitResult<send_transaction_message::v1::Response> {
if db.globals.federation_disabled() {
if !db.globals.allow_federation() {
return Err(Error::bad_config("Federation is disabled."));
}
@ -587,7 +587,7 @@ pub fn get_missing_events_route<'a>(
db: State<'a, Database>,
body: Ruma<get_missing_events::v1::Request<'_>>,
) -> ConduitResult<get_missing_events::v1::Response> {
if db.globals.federation_disabled() {
if !db.globals.allow_federation() {
return Err(Error::bad_config("Federation is disabled."));
}
@ -632,7 +632,7 @@ pub fn get_profile_information_route<'a>(
db: State<'a, Database>,
body: Ruma<get_profile_information::v1::Request<'_>>,
) -> ConduitResult<get_profile_information::v1::Response> {
if db.globals.federation_disabled() {
if !db.globals.allow_federation() {
return Err(Error::bad_config("Federation is disabled."));
}
@ -666,7 +666,7 @@ pub fn get_user_devices_route<'a>(
db: State<'a, Database>,
body: Ruma<membership::v1::Request<'_>>,
) -> ConduitResult<get_profile_information::v1::Response> {
if db.globals.federation_disabled() {
if !db.globals.allow_federation() {
return Err(Error::bad_config("Federation is disabled."));
}