Skip to content

Commit 99468ef

Browse files
Preslav LeConvex, Inc.
authored andcommitted
Add Authenticate to Application API (#26450)
This allows us to remove application from sync worker. GitOrigin-RevId: fdd652e19d3adcafdde17f93b13b9c405b4f589c
1 parent d02cc16 commit 99468ef

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

crates/application/src/api.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use futures::{
2323
future::BoxFuture,
2424
FutureExt,
2525
};
26+
use keybroker::Identity;
2627
use model::session_requests::types::SessionRequestIdentifier;
2728
use serde_json::Value as JsonValue;
2829
use sync_types::{
@@ -58,6 +59,13 @@ pub enum ExecuteQueryTimestamp {
5859
// version of Convex.
5960
#[async_trait]
6061
pub trait ApplicationApi: Send + Sync {
62+
async fn authenticate(
63+
&self,
64+
host: &str,
65+
request_id: RequestId,
66+
auth_token: AuthenticationToken,
67+
) -> anyhow::Result<Identity>;
68+
6169
async fn execute_public_query(
6270
&self,
6371
host: &str,
@@ -104,6 +112,16 @@ pub trait ApplicationApi: Send + Sync {
104112
// Implements ApplicationApi via Application.
105113
#[async_trait]
106114
impl<RT: Runtime> ApplicationApi for Application<RT> {
115+
async fn authenticate(
116+
&self,
117+
_host: &str,
118+
_request_id: RequestId,
119+
auth_token: AuthenticationToken,
120+
) -> anyhow::Result<Identity> {
121+
let validate_time = self.runtime().system_time();
122+
self.authenticate(auth_token, validate_time).await
123+
}
124+
107125
async fn execute_public_query(
108126
&self,
109127
_host: &str,

crates/sync/src/worker.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,6 @@ const HEARTBEAT_INTERVAL: Duration = Duration::from_secs(15);
193193

194194
pub struct SyncWorker<RT: Runtime> {
195195
api: Arc<dyn ApplicationApi>,
196-
// TODO(presley): Delete application once all functionality is migrated to api.
197-
application: Application<RT>,
198196
config: SyncWorkerConfig,
199197
rt: RT,
200198
state: SyncState,
@@ -243,15 +241,14 @@ impl<RT: Runtime> SyncWorker<RT> {
243241
rx: UnboundedReceiver<(ClientMessage, RT::Instant)>,
244242
tx: SingleFlightSender<RT>,
245243
) -> Self {
244+
let rt = application.runtime().clone();
246245
// Use api implemented by application until all functionality is migrated
247246
// and we no longer need application.
248-
let api = Arc::new(application.clone());
249-
let rt = application.runtime().clone();
247+
let api = Arc::new(application);
250248
let (mutation_sender, receiver) = mpsc::channel(OPERATION_QUEUE_BUFFER_SIZE);
251249
let mutation_futures = receiver.buffered(1); // Execute at most one operation at a time.
252250
SyncWorker {
253251
api,
254-
application,
255252
config,
256253
rt,
257254
state: SyncState::new(),
@@ -563,8 +560,8 @@ impl<RT: Runtime> SyncWorker<RT> {
563560
base_version,
564561
} => {
565562
let identity = self
566-
.application
567-
.authenticate(auth_token, self.rt.system_time())
563+
.api
564+
.authenticate(self.host.as_str(), RequestId::new(), auth_token)
568565
.await?;
569566
self.state.modify_identity(identity, base_version)?;
570567
self.schedule_update();

0 commit comments

Comments
 (0)