Skip to content

Commit

Permalink
add GET {aggregator_api}/ → AggregatorApiConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
jbr committed Jul 28, 2023
1 parent 21b884b commit 991b894
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
20 changes: 9 additions & 11 deletions aggregator_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,24 +105,22 @@ pub fn aggregator_api_handler<C: Clock>(ds: Arc<Datastore<C>>, cfg: Config) -> i
)
}

async fn auth_check(conn: &mut Conn, State(cfg): State<Arc<Config>>) -> impl Handler {
let bearer_token = match extract_bearer_token(conn) {
Ok(Some(t)) => t,
_ => {
return Some((Status::Unauthorized, Halt));
}
async fn auth_check(conn: &mut Conn, (): ()) -> impl Handler {
let (Some(cfg), Ok(Some(bearer_token))) =
(conn.state::<Arc<Config>>(), extract_bearer_token(conn))
else {
return Some((Status::Unauthorized, Halt));
};

if cfg.auth_tokens.iter().any(|key| {
constant_time::verify_slices_are_equal(bearer_token.as_ref(), key.as_ref()).is_ok()
}) {
// Authorization succeeds.
conn.set_state(cfg);
return None;
None
} else {
// Authorization fails.
Some((Status::Unauthorized, Halt))
}

// Authorization fails.
Some((Status::Unauthorized, Halt))
}

async fn get_config(_: &mut Conn, State(config): State<Arc<Config>>) -> Json<AggregatorApiConfig> {
Expand Down
4 changes: 2 additions & 2 deletions aggregator_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ impl<H: Handler> InstrumentedHandler<H> {
self.0.run(conn).instrument(span).await
}

async fn before_send(&self, conn: Conn) -> Conn {
if let Some(span) = conn.state::<InstrumentedHandlerSpan>() {
async fn before_send(&self, mut conn: Conn) -> Conn {
if let Some(span) = conn.take_state::<InstrumentedHandlerSpan>() {
let conn = self.0.before_send(conn).instrument(span.0.clone()).await;
span.0.in_scope(|| {
let status = conn
Expand Down

0 comments on commit 991b894

Please sign in to comment.