Skip to content

Commit 0c22c66

Browse files
committed
nightly rustfmt
1 parent d7f3054 commit 0c22c66

File tree

9 files changed

+129
-85
lines changed

9 files changed

+129
-85
lines changed

crates/cli/src/commands/syn2mas.rs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,43 +12,51 @@ use tracing::{error, warn};
1212

1313
use crate::util::database_connection_from_config;
1414

15-
/// The exit code used by `syn2mas check` and `syn2mas migrate` when there are errors preventing migration.
15+
/// The exit code used by `syn2mas check` and `syn2mas migrate` when there are
16+
/// errors preventing migration.
1617
const EXIT_CODE_CHECK_ERRORS: u8 = 10;
1718

18-
/// The exit code used by `syn2mas check` when there are warnings which should be considered prior to migration.
19+
/// The exit code used by `syn2mas check` when there are warnings which should
20+
/// be considered prior to migration.
1921
const EXIT_CODE_CHECK_WARNINGS: u8 = 11;
2022

2123
#[derive(Parser, Debug)]
2224
pub(super) struct Options {
2325
#[command(subcommand)]
2426
subcommand: Subcommand,
2527

26-
/// This version of the syn2mas tool is EXPERIMENTAL and INCOMPLETE. It is only suitable for TESTING.
27-
/// If you want to use this tool anyway, please pass this argument.
28+
/// This version of the syn2mas tool is EXPERIMENTAL and INCOMPLETE. It is
29+
/// only suitable for TESTING. If you want to use this tool anyway,
30+
/// please pass this argument.
2831
///
29-
/// If you want to migrate from Synapse to MAS today, please use the Node.js-based tool in the MAS repository.
32+
/// If you want to migrate from Synapse to MAS today, please use the
33+
/// Node.js-based tool in the MAS repository.
3034
#[clap(long = "i-swear-i-am-just-testing-in-a-staging-environment")]
3135
experimental_accepted: bool,
3236

3337
/// Path to the Synapse configuration (in YAML format).
34-
/// May be specified multiple times if multiple Synapse configuration files are in use.
38+
/// May be specified multiple times if multiple Synapse configuration files
39+
/// are in use.
3540
#[clap(long = "synapse-config")]
3641
synapse_configuration_files: Vec<Utf8PathBuf>,
3742

3843
/// Override the Synapse database URI.
39-
/// syn2mas normally loads the Synapse database connection details from the Synapse configuration.
40-
/// However, it may sometimes be necessary to override the database URI and in that case this flag can be used.
44+
/// syn2mas normally loads the Synapse database connection details from the
45+
/// Synapse configuration. However, it may sometimes be necessary to
46+
/// override the database URI and in that case this flag can be used.
4147
///
4248
/// Should be a connection URI of the following general form:
4349
/// ```text
4450
/// postgresql://[user[:password]@][host][:port][/dbname][?param1=value1&...]
4551
/// ```
46-
/// To use a UNIX socket at a custom path, the host should be a path to a socket, but in the URI string
47-
/// it must be URI-encoded by replacing `/` with `%2F`.
52+
/// To use a UNIX socket at a custom path, the host should be a path to a
53+
/// socket, but in the URI string it must be URI-encoded by replacing
54+
/// `/` with `%2F`.
4855
///
49-
/// Finally, any missing values will be loaded from the libpq-compatible environment variables
50-
/// `PGHOST`, `PGPORT`, `PGUSER`, `PGDATABASE`, `PGPASSWORD`, etc.
51-
/// It is valid to specify the URL `postgresql:` and configure all values through those environment variables.
56+
/// Finally, any missing values will be loaded from the libpq-compatible
57+
/// environment variables `PGHOST`, `PGPORT`, `PGUSER`, `PGDATABASE`,
58+
/// `PGPASSWORD`, etc. It is valid to specify the URL `postgresql:` and
59+
/// configure all values through those environment variables.
5260
#[clap(long = "synapse-database-uri")]
5361
synapse_database_uri: Option<PgConnectOptions>,
5462
}

crates/syn2mas/src/lib.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ mod synapse_reader;
88

99
mod migration;
1010

11-
pub use self::mas_writer::locking::LockedMasDatabase;
12-
pub use self::mas_writer::{checks::mas_pre_migration_checks, MasWriter};
13-
pub use self::migration::migrate;
14-
pub use self::synapse_reader::checks::{
15-
synapse_config_check, synapse_config_check_against_mas_config, synapse_database_check,
11+
pub use self::{
12+
mas_writer::{checks::mas_pre_migration_checks, locking::LockedMasDatabase, MasWriter},
13+
migration::migrate,
14+
synapse_reader::{
15+
checks::{
16+
synapse_config_check, synapse_config_check_against_mas_config, synapse_database_check,
17+
},
18+
config as synapse_config, SynapseReader,
19+
},
1620
};
17-
pub use self::synapse_reader::config as synapse_config;
18-
pub use self::synapse_reader::SynapseReader;

crates/syn2mas/src/mas_writer/checks.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
//! # MAS Database Checks
77
//!
8-
//! This module provides safety checks to run against a MAS database before running the Synapse-to-MAS migration.
8+
//! This module provides safety checks to run against a MAS database before
9+
//! running the Synapse-to-MAS migration.
910
1011
use thiserror::Error;
1112
use thiserror_ext::ContextInto;
@@ -43,7 +44,8 @@ pub enum Error {
4344
///
4445
/// - If any database access error occurs.
4546
/// - If any MAS tables involved in the migration are not empty.
46-
/// - If we can't check whether syn2mas is already in progress on this database or not.
47+
/// - If we can't check whether syn2mas is already in progress on this database
48+
/// or not.
4749
#[tracing::instrument(skip_all)]
4850
pub async fn mas_pre_migration_checks<'a>(
4951
mas_connection: &mut LockedMasDatabase<'a>,
@@ -56,7 +58,8 @@ pub async fn mas_pre_migration_checks<'a>(
5658
return Ok(());
5759
}
5860

59-
// Check that the database looks like a MAS database and that it is also an empty database.
61+
// Check that the database looks like a MAS database and that it is also an
62+
// empty database.
6063

6164
for &table in MAS_TABLES_AFFECTED_BY_MIGRATION {
6265
let row_present = sqlx::query(&format!("SELECT 1 AS dummy FROM {table} LIMIT 1"))

crates/syn2mas/src/mas_writer/locking.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,19 @@ use sqlx::{
1313
static SYN2MAS_ADVISORY_LOCK: LazyLock<PgAdvisoryLock> =
1414
LazyLock::new(|| PgAdvisoryLock::new("syn2mas-maswriter"));
1515

16-
/// A wrapper around a Postgres connection which holds a session-wide advisory lock
17-
/// preventing concurrent access by other syn2mas instances.
16+
/// A wrapper around a Postgres connection which holds a session-wide advisory
17+
/// lock preventing concurrent access by other syn2mas instances.
1818
pub struct LockedMasDatabase<'conn> {
1919
inner: PgAdvisoryLockGuard<'static, &'conn mut PgConnection>,
2020
}
2121

2222
impl<'conn> LockedMasDatabase<'conn> {
23-
/// Attempts to lock the MAS database against concurrent access by other syn2mas instances.
23+
/// Attempts to lock the MAS database against concurrent access by other
24+
/// syn2mas instances.
2425
///
2526
/// If the lock can be acquired, returns a `LockedMasDatabase`.
26-
/// If the lock cannot be acquired, returns the connection back to the caller wrapped in `Either::Right`.
27+
/// If the lock cannot be acquired, returns the connection back to the
28+
/// caller wrapped in `Either::Right`.
2729
///
2830
/// # Errors
2931
///

crates/syn2mas/src/mas_writer/mod.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ impl WriterConnectionPool {
146146
///
147147
/// # Panics
148148
///
149-
/// - If connections were not returned to the pool. (This indicates a serious bug.)
149+
/// - If connections were not returned to the pool. (This indicates a
150+
/// serious bug.)
150151
pub async fn finish(self) -> Result<(), Vec<Error>> {
151152
let mut errors = Vec::new();
152153

@@ -221,8 +222,8 @@ pub struct MasNewUnsupportedThreepid {
221222
pub created_at: DateTime<Utc>,
222223
}
223224

224-
/// The 'version' of the password hashing scheme used for passwords when they are
225-
/// migrated from Synapse to MAS.
225+
/// The 'version' of the password hashing scheme used for passwords when they
226+
/// are migrated from Synapse to MAS.
226227
/// This is version 1, as in the previous syn2mas script.
227228
// TODO hardcoding version to `1` may not be correct long-term?
228229
pub const MIGRATED_PASSWORD_VERSION: u16 = 1;
@@ -246,8 +247,8 @@ pub const MAS_TABLES_AFFECTED_BY_MIGRATION: &[&str] = &[
246247
/// Errors are returned under the following circumstances:
247248
///
248249
/// - If any database error occurs whilst querying the database.
249-
/// - If some, but not all, syn2mas restoration tables are present.
250-
/// (This shouldn't be possible without syn2mas having been sabotaged!)
250+
/// - If some, but not all, syn2mas restoration tables are present. (This
251+
/// shouldn't be possible without syn2mas having been sabotaged!)
251252
pub async fn is_syn2mas_in_progress(conn: &mut PgConnection) -> Result<bool, Error> {
252253
// Names of tables used for syn2mas resumption
253254
// Must be `String`s, not just `&str`, for the query.
@@ -476,7 +477,8 @@ impl<'conn> MasWriter<'conn> {
476477
.await
477478
.map_err(|errors| Error::Multiple(MultipleErrors::from(errors)))?;
478479

479-
// Now all the data has been migrated, finish off by restoring indices and constraints!
480+
// Now all the data has been migrated, finish off by restoring indices and
481+
// constraints!
480482

481483
query("BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED;")
482484
.execute(self.conn.as_mut())
@@ -718,10 +720,11 @@ impl<'conn> MasWriter<'conn> {
718720
}
719721
}
720722

721-
// How many entries to buffer at once, before writing a batch of rows to the database.
722-
// TODO tune: didn't see that much difference between 4k and 64k
723-
// (4k: 13.5~14, 64k: 12.5~13s — streaming the whole way would be better, especially for DB latency, but probably fiiine
724-
// and also we won't be able to stream to two tables at once...)
723+
// How many entries to buffer at once, before writing a batch of rows to the
724+
// database. TODO tune: didn't see that much difference between 4k and 64k
725+
// (4k: 13.5~14, 64k: 12.5~13s — streaming the whole way would be better,
726+
// especially for DB latency, but probably fiiine and also we won't be able to
727+
// stream to two tables at once...)
725728
const WRITE_BUFFER_BATCH_SIZE: usize = 4096;
726729

727730
pub struct MasUserWriteBuffer<'writer, 'conn> {
@@ -846,7 +849,6 @@ mod test {
846849

847850
use chrono::DateTime;
848851
use futures_util::TryStreamExt;
849-
850852
use serde::Serialize;
851853
use sqlx::{Column, PgConnection, PgPool, Row};
852854
use uuid::Uuid;
@@ -877,9 +879,11 @@ mod test {
877879

878880
const SKIPPED_TABLES: &[&str] = &["_sqlx_migrations"];
879881

880-
/// Produces a serialisable snapshot of a database, usable for snapshot testing
882+
/// Produces a serialisable snapshot of a database, usable for snapshot
883+
/// testing
881884
///
882-
/// For brevity, empty tables, as well as [`SKIPPED_TABLES`], will not be included in the snapshot.
885+
/// For brevity, empty tables, as well as [`SKIPPED_TABLES`], will not be
886+
/// included in the snapshot.
883887
async fn snapshot_database(conn: &mut PgConnection) -> DatabaseSnapshot {
884888
let mut out = DatabaseSnapshot::default();
885889
let table_names: Vec<String> = sqlx::query_scalar(

crates/syn2mas/src/migration.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55

66
//! # Migration
77
//!
8-
//! This module provides the high-level logic for performing the Synapse-to-MAS database migration.
8+
//! This module provides the high-level logic for performing the Synapse-to-MAS
9+
//! database migration.
910
//!
10-
//! This module does not implement any of the safety checks that should be run *before* the migration.
11+
//! This module does not implement any of the safety checks that should be run
12+
//! *before* the migration.
1113
1214
use std::{collections::HashMap, pin::pin};
1315

crates/syn2mas/src/synapse_reader/checks.rs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
//! # Synapse Checks
77
//!
8-
//! This module provides safety checks to run against a Synapse database before running the Synapse-to-MAS migration.
8+
//! This module provides safety checks to run against a Synapse database before
9+
//! running the Synapse-to-MAS migration.
910
1011
use figment::Figment;
1112
use mas_config::{
@@ -15,9 +16,8 @@ use mas_config::{
1516
use sqlx::{prelude::FromRow, query_as, query_scalar, PgConnection};
1617
use thiserror::Error;
1718

18-
use crate::mas_writer::MIGRATED_PASSWORD_VERSION;
19-
2019
use super::config::Config;
20+
use crate::mas_writer::MIGRATED_PASSWORD_VERSION;
2121

2222
#[derive(Debug, Error)]
2323
pub enum Error {
@@ -31,7 +31,8 @@ pub enum Error {
3131
MasPasswordConfig(#[source] anyhow::Error),
3232
}
3333

34-
/// An error found whilst checking the Synapse database, that should block a migration.
34+
/// An error found whilst checking the Synapse database, that should block a
35+
/// migration.
3536
#[derive(Debug, Error)]
3637
pub enum CheckError {
3738
#[error("MAS config is missing a password hashing scheme with version '1'")]
@@ -74,8 +75,9 @@ pub enum CheckError {
7475
},
7576
}
7677

77-
/// A potential hazard found whilst checking the Synapse database, that should be presented
78-
/// to the operator to check they are aware of a caveat before proceeding with the migration.
78+
/// A potential hazard found whilst checking the Synapse database, that should
79+
/// be presented to the operator to check they are aware of a caveat before
80+
/// proceeding with the migration.
7981
#[derive(Debug, Error)]
8082
pub enum CheckWarning {
8183
#[error("Synapse config contains OIDC auth configuration (issuer: {issuer:?}) which will need to be manually mapped to an upstream OpenID Connect Provider during migration.")]
@@ -148,12 +150,14 @@ pub fn synapse_config_check(synapse_config: &Config) -> (Vec<CheckWarning>, Vec<
148150
(warnings, errors)
149151
}
150152

151-
/// Check that the given Synapse configuration is sane for migration to a MAS with the given MAS configuration.
153+
/// Check that the given Synapse configuration is sane for migration to a MAS
154+
/// with the given MAS configuration.
152155
///
153156
/// # Errors
154157
///
155158
/// - If any necessary section of MAS config cannot be parsed.
156-
/// - If the MAS password configuration (including any necessary secrets) can't be loaded.
159+
/// - If the MAS password configuration (including any necessary secrets) can't
160+
/// be loaded.
157161
pub async fn synapse_config_check_against_mas_config(
158162
synapse: &Config,
159163
mas: &Figment,
@@ -169,8 +173,9 @@ pub async fn synapse_config_check_against_mas_config(
169173

170174
let mas_matrix = MatrixConfig::extract(mas)?;
171175

172-
// Look for the MAS password hashing scheme that will be used for imported Synapse passwords,
173-
// then check the configuration matches so that Synapse passwords will be compatible with MAS.
176+
// Look for the MAS password hashing scheme that will be used for imported
177+
// Synapse passwords, then check the configuration matches so that Synapse
178+
// passwords will be compatible with MAS.
174179
if let Some((_, algorithm, _, secret)) = mas_password_schemes
175180
.iter()
176181
.find(|(version, _, _, _)| *version == MIGRATED_PASSWORD_VERSION)
@@ -215,11 +220,13 @@ pub async fn synapse_config_check_against_mas_config(
215220
Ok((warnings, errors))
216221
}
217222

218-
/// Check that the Synapse database is sane for migration. Returns a list of warnings and errors.
223+
/// Check that the Synapse database is sane for migration. Returns a list of
224+
/// warnings and errors.
219225
///
220226
/// # Errors
221227
///
222-
/// - If there is some database connection error, or the given database is not a Synapse database.
228+
/// - If there is some database connection error, or the given database is not a
229+
/// Synapse database.
223230
/// - If the OAuth2 section of the MAS configuration could not be parsed.
224231
#[tracing::instrument(skip_all)]
225232
pub async fn synapse_database_check(

0 commit comments

Comments
 (0)