pub fn patch_homeserver_config(&self) -> Result<(), Error> {
        use serde_yaml::{Mapping, Value as YAML};
        const LISTENERS: &str = "listeners";
        const MODULES: &str = "modules";

        let target_path = self.synapse_root().join("data").join("homeserver.yaml");
        debug!("Attempting to open {:#?}", target_path);
        let config_file = std::fs::File::open(&target_path)
            .context("Could not open the homeserver.yaml generated by synapse")?;
        let mut combined_config: Mapping = serde_yaml::from_reader(config_file)
            .context("The homeserver.yaml generated by synapse is invalid")?;

        for (key, value) in [
            ("public_baseurl", &self.homeserver.public_baseurl),
            ("server_name", &self.homeserver.server_name),
            (
                "registration_shared_secret",
                &self.homeserver.registration_shared_secret,
            ),
        ] {
            combined_config.insert(key.into(), value.to_string().into());
        }
        combined_config.insert(
            "enable_registration_without_verification".into(),
            true.into(),
        );

        // Copy extra fields.
        // Note: This may include `modules` or `listeners`.
        for (key, value) in &self.homeserver.extra_fields {
            combined_config.insert(YAML::from(key.clone()), value.clone());
        }

        // Make sure that we listen on the appropriate port.
        // For some reason, `start.py generate` tends to put port 4153 instead of HARDCODED_GUEST_PORT.
        let listeners = combined_config
            .entry(LISTENERS.into())
            .or_insert_with(|| yaml!([]));
        *listeners = yaml!([yaml!({
            "port" => if self.workers.enabled { HARDCODED_MAIN_PROCESS_HTTP_LISTENER_PORT } else { HARDCODED_GUEST_PORT },
            "tls" => false,
            "type" => "http",
            "bind_addresses" => yaml!(["::"]),
            "x_forwarded" => false,
            "resources" => yaml!([
                yaml!({
                    "names" => yaml!(["client"]),
                    "compress" => true
                }),
                yaml!({
                    "names" => yaml!(["federation"]),
                    "compress" => false
                })
            ]),
        })]);
        if self.workers.enabled {
            // Setup the replication port.
            listeners
                .as_sequence_mut()
                .unwrap() // We just set it up as a sequence
                .push(yaml!({
                    "port" => 9093,
                        "bind_address" => "127.0.0.1",
                        "type" => "http",
                        "resources" => yaml!([
                            yaml!({
                                "names" => yaml!(["replication"])
                            })
                        ])
                }));
        }

        // Copy modules config.
        let modules_root = combined_config
            .entry(MODULES.into())
            .or_insert_with(|| yaml!([]))
            .to_seq_mut()
            .ok_or_else(|| anyhow!("In homeserver.yaml, expected a sequence for key `modules`"))?;
        for module in &self.modules {
            modules_root.push(module.config.clone());
        }

        if self.workers.enabled {
            for (key, value) in std::iter::IntoIterator::into_iter([
                // No worker support without redis.
                (
                    "redis",
                    yaml!({
                        "enabled" => true,
                    }),
                ),
                // No worker support without postgresql
                (
                    "database",
                    yaml!({
                        "name" => "psycopg2",
                        "txn_limit" => 10_000,
                        "args" => yaml!({
                            "user" => "synapse",
                            "password" => "password",
                            "host" => "localhost",
                            "port" => 5432,
                            "cp_min" => 5,
                            "cp_max" => 10
                        })
                    }),
                ),
                // Deactivate a few features in the main process
                // and let a worker take over them.
                ("notify_appservices", yaml!(false)),
                ("send_federation", yaml!(false)),
                ("update_user_directory", yaml!(false)),
                ("start_pushers", yaml!(false)),
                ("url_preview_enabled", yaml!(false)),
                (
                    "url_preview_ip_range_blacklist",
                    yaml!(["255.255.255.255/32",]),
                ),
                // Also, let's get rid of that warning, it pollutes logs.
                ("suppress_key_server_warning", yaml!(true)),
            ]) {
                combined_config.insert(yaml!(key), value);
            }

            // Patch shared worker config (generated by workers_start.py) to inject modules into all workers.
            //
            // Note: In future versions, we might decide to only patch specific workers.
            let conf_path = self.synapse_workers_dir().join("shared.yaml");
            let conf_file = std::fs::File::open(&conf_path).with_context(|| {
                format!("Could not open workers shared config: {:?}", conf_path)
            })?;
            let mut config: serde_yaml::Mapping = serde_yaml::from_reader(&conf_file)
                .with_context(|| {
                    format!("Could not parse workers shared config: {:?}", conf_path)
                })?;

            let modules_root = config
                .entry(MODULES.into())
                .or_insert_with(|| yaml!([]))
                .to_seq_mut()
                .ok_or_else(|| anyhow!("In shared.yaml, expected a sequence for key `modules`"))?;
            for module in &self.modules {
                modules_root.push(module.config.clone());
            }

            for (key, value) in std::iter::IntoIterator::into_iter([
                // Disable url_preview_enabled.
                ("url_preview_enabled", yaml!(false)),
                (
                    "url_preview_ip_range_blacklist",
                    yaml!(["255.255.255.255/32"]),
                ),
                // No worker without postgres.
                (
                    "database",
                    yaml!({
                        "name" => "psycopg2",
                        "txn_limit" => 10_000,
                        "args" => yaml!({
                            "user" => "synapse",
                            "password" => "password",
                            "host" => "localhost",
                            "port" => 5432,
                            "cp_min" => 5,
                            "cp_max" => 10
                        })
                    }),
                ),
            ]) {
                config.insert(yaml!(key), value);
            }

            // Deactivate url preview
            serde_yaml::to_writer(std::fs::File::create(&conf_path)?, &combined_config)
                .context("Could not write workers shared config")?;
        }

        serde_yaml::to_writer(std::fs::File::create(&target_path)?, &combined_config)
            .context("Could not write combined homeserver config")?;

        Ok(())
    }
/// Patch the homeserver.yaml at the given path (usually one that has been generated by synapse)
/// with the properties in this struct (which will usually have been provided from mx-tester.yaml)
///
/// In multiple workers mode, also patch the worker files.
Patch the homeserver.yaml at the given path (usually one that has been generated by synapse)
with the properties in this struct (which will usually have been provided from mx-tester.yaml)

In multiple workers mode, also patch the worker files.
Patch the homeserver . yaml at the given path ( usually one that has been generated by synapse ) with the properties in this struct ( which will usually have been provided from mx - tester . yaml ) In multiple workers mode also patch the worker files .
pub fn patch_homeserver_config(&self) -> Result<(), Error> {
        use serde_yaml::{Mapping, Value as YAML};
        const LISTENERS: &str = "listeners";
        const MODULES: &str = "modules";
        let target_path = self.synapse_root().join("data").join("homeserver.yaml");
        debug!("Attempting to open {:#?}", target_path);
        let config_file = std::fs::File::open(&target_path)
            .context("Could not open the homeserver.yaml generated by synapse")?;
        let mut combined_config: Mapping = serde_yaml::from_reader(config_file)
            .context("The homeserver.yaml generated by synapse is invalid")?;
        for (key, value) in [
            ("public_baseurl", &self.homeserver.public_baseurl),
            ("server_name", &self.homeserver.server_name),
            (
                "registration_shared_secret",
                &self.homeserver.registration_shared_secret,
            ),
        ] {
            combined_config.insert(key.into(), value.to_string().into());
        }
        combined_config.insert(
            "enable_registration_without_verification".into(),
            true.into(),
        );
        // Copy extra fields.
        // Note: This may include `modules` or `listeners`.
        for (key, value) in &self.homeserver.extra_fields {
            combined_config.insert(YAML::from(key.clone()), value.clone());
        }
        // Make sure that we listen on the appropriate port.
        // For some reason, `start.py generate` tends to put port 4153 instead of HARDCODED_GUEST_PORT.
        let listeners = combined_config
            .entry(LISTENERS.into())
            .or_insert_with(|| yaml!([]));
        *listeners = yaml!([yaml!({
            "port" => if self.workers.enabled { HARDCODED_MAIN_PROCESS_HTTP_LISTENER_PORT } else { HARDCODED_GUEST_PORT },
            "tls" => false,
            "type" => "http",
            "bind_addresses" => yaml!(["::"]),
            "x_forwarded" => false,
            "resources" => yaml!([
                yaml!({
                    "names" => yaml!(["client"]),
                    "compress" => true
                }),
                yaml!({
                    "names" => yaml!(["federation"]),
                    "compress" => false
                })
            ]),
        })]);
        if self.workers.enabled {
            // Setup the replication port.
            listeners
                .as_sequence_mut()
                .unwrap() // We just set it up as a sequence
                .push(yaml!({
                    "port" => 9093,
                        "bind_address" => "127.0.0.1",
                        "type" => "http",
                        "resources" => yaml!([
                            yaml!({
                                "names" => yaml!(["replication"])
                            })
                        ])
                }));
        }
        // Copy modules config.
        let modules_root = combined_config
            .entry(MODULES.into())
            .or_insert_with(|| yaml!([]))
            .to_seq_mut()
            .ok_or_else(|| anyhow!("In homeserver.yaml, expected a sequence for key `modules`"))?;
        for module in &self.modules {
            modules_root.push(module.config.clone());
        }
        if self.workers.enabled {
            for (key, value) in std::iter::IntoIterator::into_iter([
                // No worker support without redis.
                (
                    "redis",
                    yaml!({
                        "enabled" => true,
                    }),
                ),
                // No worker support without postgresql
                (
                    "database",
                    yaml!({
                        "name" => "psycopg2",
                        "txn_limit" => 10_000,
                        "args" => yaml!({
                            "user" => "synapse",
                            "password" => "password",
                            "host" => "localhost",
                            "port" => 5432,
                            "cp_min" => 5,
                            "cp_max" => 10
                        })
                    }),
                ),
                // Deactivate a few features in the main process
                // and let a worker take over them.
                ("notify_appservices", yaml!(false)),
                ("send_federation", yaml!(false)),
                ("update_user_directory", yaml!(false)),
                ("start_pushers", yaml!(false)),
                ("url_preview_enabled", yaml!(false)),
                (
                    "url_preview_ip_range_blacklist",
                    yaml!(["255.255.255.255/32",]),
                ),
                // Also, let's get rid of that warning, it pollutes logs.
                ("suppress_key_server_warning", yaml!(true)),
            ]) {
                combined_config.insert(yaml!(key), value);
            }
            // Patch shared worker config (generated by workers_start.py) to inject modules into all workers.
            //
            // Note: In future versions, we might decide to only patch specific workers.
            let conf_path = self.synapse_workers_dir().join("shared.yaml");
            let conf_file = std::fs::File::open(&conf_path).with_context(|| {
                format!("Could not open workers shared config: {:?}", conf_path)
            })?;
            let mut config: serde_yaml::Mapping = serde_yaml::from_reader(&conf_file)
                .with_context(|| {
                    format!("Could not parse workers shared config: {:?}", conf_path)
                })?;
            let modules_root = config
                .entry(MODULES.into())
                .or_insert_with(|| yaml!([]))
                .to_seq_mut()
                .ok_or_else(|| anyhow!("In shared.yaml, expected a sequence for key `modules`"))?;
            for module in &self.modules {
                modules_root.push(module.config.clone());
            }
            for (key, value) in std::iter::IntoIterator::into_iter([
                // Disable url_preview_enabled.
                ("url_preview_enabled", yaml!(false)),
                (
                    "url_preview_ip_range_blacklist",
                    yaml!(["255.255.255.255/32"]),
                ),
                // No worker without postgres.
                (
                    "database",
                    yaml!({
                        "name" => "psycopg2",
                        "txn_limit" => 10_000,
                        "args" => yaml!({
                            "user" => "synapse",
                            "password" => "password",
                            "host" => "localhost",
                            "port" => 5432,
                            "cp_min" => 5,
                            "cp_max" => 10
                        })
                    }),
                ),
            ]) {
                config.insert(yaml!(key), value);
            }
            // Deactivate url preview
            serde_yaml::to_writer(std::fs::File::create(&conf_path)?, &combined_config)
                .context("Could not write workers shared config")?;
        }
        serde_yaml::to_writer(std::fs::File::create(&target_path)?, &combined_config)
            .context("Could not write combined homeserver config")?;
        Ok(())
    }
pub fn patch_homeserver_config ( & self ) -> Result < ( ) , Error > { use serde_yaml :: { Mapping , Value as YAML } ; const LISTENERS : & str = " " ; const MODULES : & str = " " ; let target_path = self . synapse_root ( ) . join ( " " ) . join ( " " ) ; debug ! ( " " target_path ) ; let config_file = std :: fs :: File :: open ( & target_path ) . context ( " " ) ? ; let mut combined_config : Mapping = serde_yaml :: from_reader ( config_file ) . context ( " " ) ? ; for ( key , value ) in [ ( " " , & self . homeserver . public_baseurl ) , ( " " , & self . homeserver . server_name ) , ( " " , & self . homeserver . registration_shared_secret , ) , ] { combined_config . insert ( key . into ( ) , value . to_string ( ) . into ( ) ) ; } combined_config . insert ( " " . into ( ) , true . into ( ) , ) ; // Copy extra fields. // Note: This may include `modules` or `listeners`. for ( key , value ) in & self . homeserver . extra_fields { combined_config . insert ( YAML :: from ( key . clone ( ) ) , value . clone ( ) ) ; } // Make sure that we listen on the appropriate port. // For some reason, `start.py generate` tends to put port 4153 instead of HARDCODED_GUEST_PORT. let listeners = combined_config . entry ( LISTENERS . into ( ) ) . or_insert_with ( | | yaml ! ( [ ] ) ) ; * listeners = yaml ! ( [ yaml ( { " " if self workers enabled { HARDCODED_MAIN_PROCESS_HTTP_LISTENER_PORT } else { HARDCODED_GUEST_PORT } " " false " " " " " " yaml ( [ " " ] ) " " false " " yaml ( [ yaml ( { " " yaml ( [ " " ] ) " " true } ) yaml ( { " " yaml ( [ " " ] ) " " false } ) ] ) } ) ] ) ; if self . workers . enabled { // Setup the replication port. listeners . as_sequence_mut ( ) . unwrap ( ) // We just set it up as a sequence . push ( yaml ! ( { " " 9093 " " " " " " " " " " yaml ( [ yaml ( { " " yaml ( [ " " ] ) } ) ] ) } ) ) ; } // Copy modules config. let modules_root = combined_config . entry ( MODULES . into ( ) ) . or_insert_with ( | | yaml ! ( [ ] ) ) . to_seq_mut ( ) . ok_or_else ( | | anyhow ! ( " " ) ) ? ; for module in & self . modules { modules_root . push ( module . config . clone ( ) ) ; } if self . workers . enabled { for ( key , value ) in std :: iter :: IntoIterator :: into_iter ( [ // No worker support without redis. ( " " , yaml ! ( { " " true } ) , ) , // No worker support without postgresql ( " " , yaml ! ( { " " " " " " 10_000 " " yaml ( { " " " " " " " " " " " " " " 5432 " " 5 " " 10 } ) } ) , ) , // Deactivate a few features in the main process // and let a worker take over them. ( " " , yaml ! ( false ) ) , ( " " , yaml ! ( false ) ) , ( " " , yaml ! ( false ) ) , ( " " , yaml ! ( false ) ) , ( " " , yaml ! ( false ) ) , ( " " , yaml ! ( [ " " ] ) , ) , // Also, let's get rid of that warning, it pollutes logs. ( " " , yaml ! ( true ) ) , ] ) { combined_config . insert ( yaml ! ( key ) , value ) ; } // Patch shared worker config (generated by workers_start.py) to inject modules into all workers. // // Note: In future versions, we might decide to only patch specific workers. let conf_path = self . synapse_workers_dir ( ) . join ( " " ) ; let conf_file = std :: fs :: File :: open ( & conf_path ) . with_context ( | | { format ! ( " " conf_path ) } ) ? ; let mut config : serde_yaml :: Mapping = serde_yaml :: from_reader ( & conf_file ) . with_context ( | | { format ! ( " " conf_path ) } ) ? ; let modules_root = config . entry ( MODULES . into ( ) ) . or_insert_with ( | | yaml ! ( [ ] ) ) . to_seq_mut ( ) . ok_or_else ( | | anyhow ! ( " " ) ) ? ; for module in & self . modules { modules_root . push ( module . config . clone ( ) ) ; } for ( key , value ) in std :: iter :: IntoIterator :: into_iter ( [ // Disable url_preview_enabled. ( " " , yaml ! ( false ) ) , ( " " , yaml ! ( [ " " ] ) , ) , // No worker without postgres. ( " " , yaml ! ( { " " " " " " 10_000 " " yaml ( { " " " " " " " " " " " " " " 5432 " " 5 " " 10 } ) } ) , ) , ] ) { config . insert ( yaml ! ( key ) , value ) ; } // Deactivate url preview serde_yaml :: to_writer ( std :: fs :: File :: create ( & conf_path ) ? , & combined_config ) . context ( " " ) ? ; } serde_yaml :: to_writer ( std :: fs :: File :: create ( & target_path ) ? , & combined_config ) . context ( " " ) ? ; Ok ( ( ) ) }
Patch the homeserver.yaml at the given path (usually one that has been generated by synapse)
with the properties in this struct (which will usually have been provided from mx-tester.yaml)
Patch the homeserver . yaml at the given path ( usually one that has been generated by synapse ) with the properties in this struct ( which will usually have been provided from mx - tester . yaml )
&self
&self