Merge branch 'evals' of https://github.com/buster-so/buster into evals

This commit is contained in:
Nate Kelley 2025-03-17 16:20:17 -06:00
commit 4dcb40f49e
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
3 changed files with 10 additions and 14 deletions

View File

@ -85,7 +85,7 @@ async fn test_real_trace_with_spans() -> Result<()> {
} }
// Create client (None means use env var) // Create client (None means use env var)
let client = BraintrustClient::new(None, "c7b996a6-1c7c-482d-b23f-3d39de16f433")?; let client = BraintrustClient::new(None, "172afc4a-16b7-4d59-978e-4c87cade87b6")?;
// Create a trace // Create a trace
let trace_id = uuid::Uuid::new_v4().to_string(); let trace_id = uuid::Uuid::new_v4().to_string();

View File

@ -14,6 +14,7 @@ tracing = { workspace = true }
uuid = { workspace = true } uuid = { workspace = true }
diesel = { workspace = true } diesel = { workspace = true }
diesel-async = { workspace = true } diesel-async = { workspace = true }
lazy_static = { workspace = true }
# Auth-specific dependencies # Auth-specific dependencies
jsonwebtoken = { workspace = true } jsonwebtoken = { workspace = true }

View File

@ -12,9 +12,15 @@ use jsonwebtoken::{decode, Algorithm, DecodingKey, Validation};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::{collections::HashMap, env}; use std::{collections::HashMap, env};
use uuid::Uuid; use uuid::Uuid;
use lazy_static::lazy_static;
use crate::types::{AuthenticatedUser, OrganizationMembership, TeamMembership}; use crate::types::{AuthenticatedUser, OrganizationMembership, TeamMembership};
lazy_static! {
static ref JWT_SECRET: String = env::var("JWT_SECRET").expect("JWT_SECRET is not set");
static ref WEBHOOK_TOKEN: String = env::var("BUSTER_WH_TOKEN").expect("BUSTER_WH_TOKEN is not set");
}
#[derive(Serialize, Deserialize, Debug, Clone)] #[derive(Serialize, Deserialize, Debug, Clone)]
pub struct JwtClaims { pub struct JwtClaims {
pub aud: String, pub aud: String,
@ -44,8 +50,6 @@ pub async fn auth(mut req: Request, next: Next) -> Result<Response, StatusCode>
} }
}; };
let buster_wh_token = env::var("BUSTER_WH_TOKEN").expect("BUSTER_WH_TOKEN is not set");
let bearer_token = req.headers().get("Authorization").and_then(|value| { let bearer_token = req.headers().get("Authorization").and_then(|value| {
value.to_str().ok().and_then(|v| { value.to_str().ok().and_then(|v| {
if v.starts_with("Bearer ") { if v.starts_with("Bearer ") {
@ -57,7 +61,7 @@ pub async fn auth(mut req: Request, next: Next) -> Result<Response, StatusCode>
}); });
if let Some(token) = bearer_token { if let Some(token) = bearer_token {
if token == buster_wh_token { if token == *WEBHOOK_TOKEN {
return Ok(next.run(req).await); return Ok(next.run(req).await);
} }
} }
@ -95,20 +99,11 @@ pub async fn auth(mut req: Request, next: Next) -> Result<Response, StatusCode>
} }
async fn authorize_current_user(token: &str) -> Result<Option<AuthenticatedUser>> { async fn authorize_current_user(token: &str) -> Result<Option<AuthenticatedUser>> {
let pg_pool = get_pg_pool();
let _conn = pg_pool.get().await.map_err(|e| {
tracing::error!("Pool connection error in auth: {:?}", e);
anyhow!("Database connection error in auth")
})?;
let key = env::var("JWT_SECRET").expect("JWT_SECRET is not set");
let mut validation = Validation::new(Algorithm::HS256); let mut validation = Validation::new(Algorithm::HS256);
validation.set_audience(&["authenticated", "api"]); validation.set_audience(&["authenticated", "api"]);
let token_data = let token_data =
match decode::<JwtClaims>(token, &DecodingKey::from_secret(key.as_ref()), &validation) { match decode::<JwtClaims>(token, &DecodingKey::from_secret(JWT_SECRET.as_ref()), &validation) {
Ok(jwt_claims) => jwt_claims.claims, Ok(jwt_claims) => jwt_claims.claims,
Err(e) => { Err(e) => {
return Err(anyhow!("Error while decoding the token: {}", e)); return Err(anyhow!("Error while decoding the token: {}", e));