Skip to content

Commit

Permalink
[rust-node-addon] add rust function and binding type for privilegedDe…
Browse files Browse the repository at this point in the history
…leteUsers

Summary:
we'll call this RPC from a keyserver script, so we need rust bindings

Depends on D13630

Test Plan:
created two test users on staging. manually added a token for user ID 256 to staging. then called privileged_delete_users from keyserver.js to delete the two test users. confirmed their data was removed from ddb

```
diff --git a/keyserver/src/keyserver.js b/keyserver/src/keyserver.js
index 88dcd0b4a2..950680086d 100644
--- a/keyserver/src/keyserver.js
+++ b/keyserver/src/keyserver.js
@@ -11,6 +11,7 @@ import type { $Request, $Response } from 'express';
 import expressWs from 'express-ws';
 import os from 'os';
 import qrcode from 'qrcode';
+import { getRustAPI } from 'rust-node-addon';
 import stoppable from 'stoppable';

 import './cron/cron.js';
@@ -76,6 +77,13 @@ void (async () => {
     initFCCache(),
   ]);

+  const rustAPI = await getRustAPI();
+  const response = await rustAPI.privilegedDeleteUsers('256', 'asdf', '1234', [
+    'C4E8C417-DD67-4084-8282-4A788DF38F57',
+    '78941137-03DB-4A23-A17F-890A94948493',
+  ]);
+  console.log(response);
+
```

Reviewers: bartek, will

Reviewed By: bartek

Subscribers: ashoat, tomek

Differential Revision: https://phab.comm.dev/D13631
  • Loading branch information
vdhanan committed Oct 8, 2024
1 parent bad0b9a commit 37da7ba
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
6 changes: 6 additions & 0 deletions keyserver/addons/rust-node-addon/rust-binding-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ type RustNativeBindingAPI = {
authAccessToken: string,
userIds: $ReadOnlyArray<string>,
) => Promise<UserIdentitiesResponse>,
+privilegedDeleteUsers: (
authUserId: string,
authDeviceId: string,
authAccessToken: string,
userIds: $ReadOnlyArray<string>,
) => Promise<void>,
};

export type { RustNativeBindingAPI };
3 changes: 2 additions & 1 deletion keyserver/addons/rust-node-addon/src/identity_client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub mod get_inbound_keys_for_user;
pub mod login;
pub mod nonce;
pub mod prekey;
mod privileged_delete_users;
pub mod register_user;
pub mod remove_reserved_usernames;
pub mod upload_one_time_keys;
Expand All @@ -20,7 +21,7 @@ use config::get_identity_service_config;
use generated::CODE_VERSION;
use grpc_clients::identity::authenticated::ChainedInterceptedAuthClient;
use grpc_clients::identity::protos::authenticated::{
InboundKeyInfo, UploadOneTimeKeysRequest,
InboundKeyInfo, PrivilegedDeleteUsersRequest, UploadOneTimeKeysRequest,
};
use grpc_clients::identity::protos::unauthenticated as client_proto;
use grpc_clients::identity::shared::CodeVersionLayer;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use super::*;

#[napi]
#[instrument(skip_all)]
pub async fn privileged_delete_users(
auth_user_id: String,
auth_device_id: String,
auth_access_token: String,
user_ids: Vec<String>,
) -> Result<()> {
let mut identity_client = get_authenticated_identity_client(
auth_user_id,
auth_device_id,
auth_access_token,
)
.await?;

let privileged_delete_users_request =
PrivilegedDeleteUsersRequest { user_ids };

identity_client
.privileged_delete_users(privileged_delete_users_request)
.await
.map_err(handle_grpc_error)?;

Ok(())
}

0 comments on commit 37da7ba

Please sign in to comment.