-
Notifications
You must be signed in to change notification settings - Fork 54
syn2mas: Support migrating external IDs as upstream OAuth2 providers #3917
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7019ad0
Add `SynapseReader` support and test for external IDs
reivilibre eec27f3
Run database migrations and do a config sync before syn2mas
reivilibre 530c759
FullUserId: implement Display
reivilibre 3130d23
Add `MasWriter` support and test for upstream OAuth provider links
reivilibre c9ae892
Remove special-purpose write buffers and use only the generic one
reivilibre 6b02497
Build the provider ID mapping
reivilibre File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ use uuid::Uuid; | |
use crate::{ | ||
mas_writer::{ | ||
self, MasNewEmailThreepid, MasNewUnsupportedThreepid, MasNewUpstreamOauthLink, MasNewUser, | ||
MasNewUserPassword, MasThreepidWriteBuffer, MasUserWriteBuffer, MasWriteBuffer, MasWriter, | ||
MasNewUserPassword, MasWriteBuffer, MasWriter, | ||
}, | ||
synapse_reader::{ | ||
self, ExtractLocalpartError, FullUserId, SynapseExternalId, SynapseThreepid, SynapseUser, | ||
|
@@ -132,7 +132,8 @@ async fn migrate_users( | |
server_name: &str, | ||
rng: &mut impl RngCore, | ||
) -> Result<UsersMigrated, Error> { | ||
let mut write_buffer = MasUserWriteBuffer::new(mas); | ||
let mut user_buffer = MasWriteBuffer::new(MasWriter::write_users); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure how I feel about passing function pointers instead of using traits… I guess that works, not sure how it would look like with traits |
||
let mut password_buffer = MasWriteBuffer::new(MasWriter::write_passwords); | ||
let mut users_stream = pin!(synapse.read_users()); | ||
// TODO is 1:1 capacity enough for a hashmap? | ||
let mut user_localparts_to_uuid = HashMap::with_capacity(user_count_hint); | ||
|
@@ -143,23 +144,24 @@ async fn migrate_users( | |
|
||
user_localparts_to_uuid.insert(CompactString::new(&mas_user.username), mas_user.user_id); | ||
|
||
write_buffer | ||
.write_user(mas_user) | ||
user_buffer | ||
.write(mas, mas_user) | ||
.await | ||
.into_mas("writing user")?; | ||
|
||
if let Some(mas_password) = mas_password_opt { | ||
write_buffer | ||
.write_password(mas_password) | ||
password_buffer | ||
.write(mas, mas_password) | ||
.await | ||
.into_mas("writing password")?; | ||
} | ||
} | ||
|
||
write_buffer | ||
.finish() | ||
user_buffer.finish(mas).await.into_mas("writing users")?; | ||
password_buffer | ||
.finish(mas) | ||
.await | ||
.into_mas("writing users & passwords")?; | ||
.into_mas("writing passwords")?; | ||
|
||
Ok(UsersMigrated { | ||
user_localparts_to_uuid, | ||
|
@@ -174,7 +176,8 @@ async fn migrate_threepids( | |
rng: &mut impl RngCore, | ||
user_localparts_to_uuid: &HashMap<CompactString, Uuid>, | ||
) -> Result<(), Error> { | ||
let mut write_buffer = MasThreepidWriteBuffer::new(mas); | ||
let mut email_buffer = MasWriteBuffer::new(MasWriter::write_email_threepids); | ||
let mut unsupported_buffer = MasWriteBuffer::new(MasWriter::write_unsupported_threepids); | ||
let mut users_stream = pin!(synapse.read_threepids()); | ||
|
||
while let Some(threepid_res) = users_stream.next().await { | ||
|
@@ -198,32 +201,45 @@ async fn migrate_threepids( | |
}; | ||
|
||
if medium == "email" { | ||
write_buffer | ||
.write_email(MasNewEmailThreepid { | ||
user_id, | ||
user_email_id: Uuid::from(Ulid::from_datetime_with_source( | ||
created_at.into(), | ||
rng, | ||
)), | ||
email: address, | ||
created_at, | ||
}) | ||
email_buffer | ||
.write( | ||
mas, | ||
MasNewEmailThreepid { | ||
user_id, | ||
user_email_id: Uuid::from(Ulid::from_datetime_with_source( | ||
created_at.into(), | ||
rng, | ||
)), | ||
email: address, | ||
created_at, | ||
}, | ||
) | ||
.await | ||
.into_mas("writing email")?; | ||
} else { | ||
write_buffer | ||
.write_password(MasNewUnsupportedThreepid { | ||
user_id, | ||
medium, | ||
address, | ||
created_at, | ||
}) | ||
unsupported_buffer | ||
.write( | ||
mas, | ||
MasNewUnsupportedThreepid { | ||
user_id, | ||
medium, | ||
address, | ||
created_at, | ||
}, | ||
) | ||
.await | ||
.into_mas("writing unsupported threepid")?; | ||
} | ||
} | ||
|
||
write_buffer.finish().await.into_mas("writing threepids")?; | ||
email_buffer | ||
.finish(mas) | ||
.await | ||
.into_mas("writing email threepids")?; | ||
unsupported_buffer | ||
.finish(mas) | ||
.await | ||
.into_mas("writing unsupported threepids")?; | ||
|
||
Ok(()) | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reasoning with boxing here, and why not
-> impl Future
?