Skip to content
This repository was archived by the owner on Sep 10, 2024. It is now read-only.

Commit ff815c0

Browse files
jaywinksandhose
authored andcommitted
syn2mas: Skip access tokens that don't have a device ID
These can't be migrated. They are likely enirely valid tokens created by puppeting a user via the Synapse admin api. Treating them as fatal errors will make it impossible to migrate any host that has ever used this admin API feature.
1 parent 114c5fc commit ff815c0

File tree

3 files changed

+6
-11
lines changed

3 files changed

+6
-11
lines changed

tools/syn2mas/src/advisor.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export async function advisor(): Promise<void> {
161161
);
162162
if (accessTokensWithoutDeviceId > 0) {
163163
error(
164-
`Synapse database contains ${accessTokensWithoutDeviceId} access tokens without an associated device_id which aren't supported during migration`,
164+
`Synapse database contains ${accessTokensWithoutDeviceId} access tokens without an associated device_id which will be skipped during migration`,
165165
);
166166
}
167167

tools/syn2mas/src/migrate.mts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -337,16 +337,11 @@ export async function migrate(): Promise<void> {
337337
const synapseAccessTokens = await synapse
338338
.select("*")
339339
.from<SAccessToken>("access_tokens")
340-
.where({ user_id: user.name });
340+
.where({ user_id: user.name })
341+
// Skip tokens without devices.
342+
// These can be for example short-lived tokens created by puppeting a user over the Synapse admin API.
343+
.whereNotNull("device_id");
341344
for (const accessToken of synapseAccessTokens) {
342-
if (!accessToken.device_id) {
343-
warningsForUser += 1;
344-
warn(
345-
`Skipping access token ${accessToken.token} for user ${user.name} with no device_id`,
346-
);
347-
continue;
348-
}
349-
350345
const tokenCreatedAt = accessToken.last_validated
351346
? new Date(parseInt(`${accessToken.last_validated}`))
352347
: masUser.created_at;

tools/syn2mas/src/types/SAccessToken.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ CREATE TABLE access_tokens (
3232
export interface SAccessToken {
3333
id: Id<SAccessToken>;
3434
user_id: SynapseUserId;
35-
device_id?: string;
35+
device_id: string;
3636
token: string;
3737
valid_until_ms?: number;
3838
puppets_user_id?: SynapseUserId;

0 commit comments

Comments
 (0)