Skip to content

Commit a55f26c

Browse files
authored
Merge branch 'main' into feat/login_hint_with_email
2 parents b189bfd + b9e342c commit a55f26c

32 files changed

+747
-345
lines changed

.github/workflows/build.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ jobs:
226226
steps:
227227
- name: Docker meta
228228
id: meta
229-
uses: docker/metadata-action@v5.7.0
229+
uses: docker/metadata-action@v5.8.0
230230
with:
231231
images: "${{ env.IMAGE }}"
232232
bake-target: docker-metadata-action
@@ -242,7 +242,7 @@ jobs:
242242
243243
- name: Docker meta (debug variant)
244244
id: meta-debug
245-
uses: docker/metadata-action@v5.7.0
245+
uses: docker/metadata-action@v5.8.0
246246
with:
247247
images: "${{ env.IMAGE }}"
248248
bake-target: docker-metadata-action-debug

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ features = ["derive"] # Most of the time, if we need serde, we need derive
593593

594594
# JSON serialization and deserialization
595595
[workspace.dependencies.serde_json]
596-
version = "1.0.141"
596+
version = "1.0.142"
597597
features = ["preserve_order"]
598598

599599
# URL encoded form serialization
@@ -650,7 +650,7 @@ version = "0.3.0"
650650

651651
# Async runtime
652652
[workspace.dependencies.tokio]
653-
version = "1.47.0"
653+
version = "1.47.1"
654654
features = ["full"]
655655

656656
[workspace.dependencies.tokio-stream]

crates/cli/src/commands/doctor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ impl Options {
4343
r"The homeserver host in the config (`matrix.homeserver`) is not a valid domain.
4444
See {DOCS_BASE}/setup/homeserver.html",
4545
)?;
46+
let admin_token = config.matrix.secret().await?;
4647
let hs_api = config.matrix.endpoint;
47-
let admin_token = config.matrix.secret;
4848

4949
if !issuer.starts_with("https://") {
5050
warn!(

crates/cli/src/commands/manage.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,11 @@ impl Options {
322322
} => {
323323
let database_config = DatabaseConfig::extract_or_default(figment)
324324
.map_err(anyhow::Error::from_boxed)?;
325+
let matrix_config =
326+
MatrixConfig::extract(figment).map_err(anyhow::Error::from_boxed)?;
327+
let http_client = mas_http::reqwest_client();
328+
let homeserver =
329+
homeserver_connection_from_config(&matrix_config, http_client).await?;
325330
let mut conn = database_connection_from_config(&database_config).await?;
326331
let txn = conn.begin().await?;
327332
let mut repo = PgRepository::from_conn(txn);
@@ -338,6 +343,24 @@ impl Options {
338343
Device::generate(&mut rng)
339344
};
340345

346+
if let Err(e) = homeserver
347+
.upsert_device(&user.username, device.as_str(), None)
348+
.await
349+
{
350+
error!(
351+
error = &*e,
352+
"Could not create the device on the homeserver, aborting"
353+
);
354+
355+
// Schedule a device sync job to remove the potential leftover device
356+
repo.queue_job()
357+
.schedule_job(&mut rng, &clock, SyncDevicesJob::new(&user))
358+
.await?;
359+
360+
repo.into_inner().commit().await?;
361+
return Ok(ExitCode::FAILURE);
362+
}
363+
341364
let compat_session = repo
342365
.compat_session()
343366
.add(&mut rng, &clock, &user, device, None, admin, None)
@@ -590,7 +613,8 @@ impl Options {
590613
MatrixConfig::extract(figment).map_err(anyhow::Error::from_boxed)?;
591614

592615
let password_manager = password_manager_from_config(&password_config).await?;
593-
let homeserver = homeserver_connection_from_config(&matrix_config, http_client);
616+
let homeserver =
617+
homeserver_connection_from_config(&matrix_config, http_client).await?;
594618
let mut conn = database_connection_from_config(&database_config).await?;
595619
let txn = conn.begin().await?;
596620
let mut repo = PgRepository::from_conn(txn);

crates/cli/src/commands/server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ impl Options {
167167
let http_client = mas_http::reqwest_client();
168168

169169
let homeserver_connection =
170-
homeserver_connection_from_config(&config.matrix, http_client.clone());
170+
homeserver_connection_from_config(&config.matrix, http_client.clone()).await?;
171171

172172
if !self.no_worker {
173173
let mailer = mailer_from_config(&config.email, &templates)?;

crates/cli/src/commands/worker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl Options {
5959
test_mailer_in_background(&mailer, Duration::from_secs(30));
6060

6161
let http_client = mas_http::reqwest_client();
62-
let conn = homeserver_connection_from_config(&config.matrix, http_client);
62+
let conn = homeserver_connection_from_config(&config.matrix, http_client).await?;
6363

6464
drop(config);
6565

crates/cli/src/sync.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ pub async fn config_sync(
385385
continue;
386386
}
387387

388-
let client_secret = client.client_secret.as_deref();
388+
let client_secret = client.client_secret().await?;
389389
let client_name = client.client_name.as_ref();
390390
let client_auth_method = client.client_auth_method();
391391
let jwks = client.jwks.as_ref();

crates/cli/src/util.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -464,36 +464,36 @@ pub async fn load_policy_factory_dynamic_data(
464464

465465
/// Create a clonable, type-erased [`HomeserverConnection`] from the
466466
/// configuration
467-
pub fn homeserver_connection_from_config(
467+
pub async fn homeserver_connection_from_config(
468468
config: &MatrixConfig,
469469
http_client: reqwest::Client,
470-
) -> Arc<dyn HomeserverConnection> {
471-
match config.kind {
472-
HomeserverKind::Synapse | HomeserverKind::SynapseLegacy => {
473-
Arc::new(LegacySynapseConnection::new(
470+
) -> anyhow::Result<Arc<dyn HomeserverConnection>> {
471+
Ok(match config.kind {
472+
HomeserverKind::Synapse | HomeserverKind::SynapseModern => {
473+
Arc::new(SynapseConnection::new(
474474
config.homeserver.clone(),
475475
config.endpoint.clone(),
476-
config.secret.clone(),
476+
config.secret().await?,
477477
http_client,
478478
))
479479
}
480-
HomeserverKind::SynapseModern => Arc::new(SynapseConnection::new(
480+
HomeserverKind::SynapseLegacy => Arc::new(LegacySynapseConnection::new(
481481
config.homeserver.clone(),
482482
config.endpoint.clone(),
483-
config.secret.clone(),
483+
config.secret().await?,
484484
http_client,
485485
)),
486486
HomeserverKind::SynapseReadOnly => {
487-
let connection = LegacySynapseConnection::new(
487+
let connection = SynapseConnection::new(
488488
config.homeserver.clone(),
489489
config.endpoint.clone(),
490-
config.secret.clone(),
490+
config.secret().await?,
491491
http_client,
492492
);
493493
let readonly = ReadOnlyHomeserverConnection::new(connection);
494494
Arc::new(readonly)
495495
}
496-
}
496+
})
497497
}
498498

499499
#[cfg(test)]

0 commit comments

Comments
 (0)