Skip to content

Commit 7e1ba5c

Browse files
committed
fix(serverless): pass admin token to outbound reqs (#3007)
1 parent 956eaaf commit 7e1ba5c

File tree

1 file changed

+13
-3
lines changed
  • packages/core/pegboard-serverless/src

1 file changed

+13
-3
lines changed

packages/core/pegboard-serverless/src/lib.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ use tokio::{sync::oneshot, task::JoinHandle, time::Duration};
1818
use universaldb::options::StreamingMode;
1919
use universaldb::utils::IsolationLevel::*;
2020

21+
const X_RIVET_TOKEN: HeaderName = HeaderName::from_static("x-rivet-token");
22+
2123
struct OutboundConnection {
2224
handle: JoinHandle<()>,
2325
shutdown_tx: oneshot::Sender<()>,
@@ -226,11 +228,19 @@ async fn outbound_handler(
226228
))
227229
})
228230
.collect();
229-
let mut es = sse::EventSource::new(client.get(url).headers(headers))?;
231+
232+
let mut req = client.get(url).headers(headers);
233+
234+
// Add admin token if configured
235+
if let Some(auth) = ctx.config().auth {
236+
req = req.header(X_RIVET_TOKEN, &auth.admin_token);
237+
}
238+
239+
let mut source = sse::EventSource::new(req)?;
230240
let mut runner_id = None;
231241

232242
let stream_handler = async {
233-
while let Some(event) = es.next().await {
243+
while let Some(event) = source.next().await {
234244
match event {
235245
Ok(sse::Event::Open) => {}
236246
Ok(sse::Event::Message(msg)) => {
@@ -269,7 +279,7 @@ async fn outbound_handler(
269279
}
270280

271281
// Continue waiting on req while draining
272-
while let Some(event) = es.next().await {
282+
while let Some(event) = source.next().await {
273283
match event {
274284
Ok(sse::Event::Open) => {}
275285
Ok(sse::Event::Message(msg)) => {

0 commit comments

Comments
 (0)