-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[keyserver] cron job to sync reserved usernames
Summary: daily cron job to send all the usernames from ashoat's keyserver to the identity service. the logic here is very similar to the logic added to the account-creator.js Depends on D8330 Test Plan: Modified cron job schedule to force a run and observed that usernames were added to the identity service's reserved usernames table locally Reviewers: ashoat Reviewed By: ashoat Subscribers: tomek Differential Revision: https://phab.comm.dev/D8331
- Loading branch information
Showing
2 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// @flow | ||
|
||
import { getRustAPI } from 'rust-node-addon'; | ||
|
||
import type { ReservedUsernameMessage } from 'lib/types/crypto-types.js'; | ||
|
||
import { fetchAllUsernames } from '../fetchers/user-fetchers.js'; | ||
import { addReservedUsernamesStatement } from '../shared/message-statements.js'; | ||
import { fetchOlmAccount } from '../updaters/olm-account-updater.js'; | ||
|
||
async function updateIdentityReservedUsernames(): Promise<void> { | ||
const [usernames, rustAPI, accountInfo] = await Promise.all([ | ||
fetchAllUsernames(), | ||
getRustAPI(), | ||
fetchOlmAccount('content'), | ||
]); | ||
const issuedAt = new Date().toISOString(); | ||
const reservedUsernameMessage: ReservedUsernameMessage< | ||
$ReadOnlyArray<string>, | ||
> = { | ||
statement: addReservedUsernamesStatement, | ||
payload: usernames, | ||
issuedAt, | ||
}; | ||
const stringifiedMessage = JSON.stringify(reservedUsernameMessage); | ||
const signature = accountInfo.account.sign(stringifiedMessage); | ||
|
||
await rustAPI.addReservedUsernames(stringifiedMessage, signature); | ||
} | ||
|
||
export { updateIdentityReservedUsernames }; |