Skip to content

Commit 5872713

Browse files
committed
fixes
1 parent a91a9f9 commit 5872713

File tree

10 files changed

+33
-25
lines changed

10 files changed

+33
-25
lines changed

bin/router/src/background_tasks/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ pub struct BackgroundTasksManager {
1616
task_handles: Vec<JoinHandle<()>>,
1717
}
1818

19+
impl Default for BackgroundTasksManager {
20+
fn default() -> Self {
21+
Self::new()
22+
}
23+
}
24+
1925
impl BackgroundTasksManager {
2026
pub fn new() -> Self {
2127
Self {

bin/router/src/jwt/context.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use sonic_rs::Value;
66

77
pub type TokenPayload = TokenData<JwtClaims>;
88

9+
#[allow(dead_code)] // TODO: Remove this when we actually use this and integrate with header propagation
910
pub struct JwtRequestContext {
1011
pub token: String,
1112
pub payload: TokenPayload,

bin/router/src/jwt/errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ pub enum JwtError {
4646
}
4747

4848
impl JwtError {
49-
pub fn into_response(&self) -> web::HttpResponse {
49+
pub fn make_response(&self) -> web::HttpResponse {
5050
let validation_error_result = FailedExecutionResult {
5151
errors: Some(vec![self.into()]),
5252
};
5353

54-
return ResponseBuilder::new(self.into()).json(&validation_error_result);
54+
ResponseBuilder::new(self.into()).json(&validation_error_result)
5555
}
5656

5757
pub fn error_code(&self) -> &'static str {

bin/router/src/jwt/jwks_manager.rs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use sonic_rs::from_str;
33
use std::sync::{Arc, RwLock};
44
use tokio::fs::read_to_string;
55
use tokio_util::sync::CancellationToken;
6+
use tracing::debug;
67

78
use jsonwebtoken::jwk::JwkSet;
89

@@ -72,27 +73,25 @@ impl BackgroundTask for JwksSource {
7273
}
7374

7475
async fn run(&self, token: CancellationToken) {
75-
match &self.config {
76-
JwksProviderSourceConfig::Remote {
77-
polling_interval, ..
78-
} => {
79-
if let Some(interval) = polling_interval {
80-
let mut tokio_interval = tokio::time::interval(*interval);
81-
82-
loop {
83-
tokio::select! {
84-
_ = tokio_interval.tick() => { match self.load_and_store_jwks().await {
85-
Ok(_) => {}
86-
Err(err) => {
87-
tracing::error!("Failed to load remote jwks: {}", err);
88-
}
89-
} }
90-
_ = token.cancelled() => { println!("Shutting down."); return; }
76+
if let JwksProviderSourceConfig::Remote {
77+
polling_interval: Some(interval),
78+
..
79+
} = &self.config
80+
{
81+
debug!("Starting remote jwks polling for source: {:?}", self.config);
82+
let mut tokio_interval = tokio::time::interval(*interval);
83+
84+
loop {
85+
tokio::select! {
86+
_ = tokio_interval.tick() => { match self.load_and_store_jwks().await {
87+
Ok(_) => {}
88+
Err(err) => {
89+
tracing::error!("Failed to load remote jwks: {}", err);
9190
}
92-
}
91+
} }
92+
_ = token.cancelled() => { println!("Shutting down."); return; }
9393
}
9494
}
95-
_ => {}
9695
}
9796
}
9897
}

bin/router/src/jwt/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,8 @@ impl JwtAuthRuntime {
242242
match (&self.config.audiences, &token_data.claims.aud) {
243243
(Some(audiences), Some(token_aud)) => {
244244
let all_valid = match token_aud {
245-
Audience::Single(s) => audiences.contains(&s),
246-
Audience::Multiple(s) => s.iter().all(|v| audiences.contains(&v)),
245+
Audience::Single(s) => audiences.contains(s),
246+
Audience::Multiple(s) => s.iter().all(|v| audiences.contains(v)),
247247
};
248248

249249
if !all_valid {

bin/router/src/pipeline/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub async fn graphql_request_handler(
5454
if let Some(jwt) = &state.jwt_auth_runtime {
5555
match jwt.validate_request(req) {
5656
Ok(_) => (),
57-
Err(err) => return err.into_response(),
57+
Err(err) => return err.make_response(),
5858
}
5959
}
6060

e2e/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#[cfg(test)]
12
mod jwt;
23
#[cfg(test)]
34
mod testkit;

e2e/src/testkit.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ lazy_static! {
2929
static ref TRACING_INIT: Once = Once::new();
3030
}
3131

32+
#[allow(dead_code)] // call this at the beginning of the test if you wish to see gw logs
3233
pub fn init_logger() {
3334
TRACING_INIT.call_once(|| {
3435
let subscriber = tracing_subscriber::registry()

lib/router-config/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub enum RouterConfigError {
5959
ConfigLoadError(config::ConfigError),
6060
}
6161

62-
static DEFAULT_FILE_NAMES: &[&'static str] = &[
62+
static DEFAULT_FILE_NAMES: &[&str] = &[
6363
"hive-router.config.yaml",
6464
"hive-router.config.yml",
6565
"hive-router.config.json",

lib/router-config/src/primitives/file_path.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub struct FilePath {
1919
}
2020

2121
// This is a workaround/solution to pass some kind of "context" to the deserialization process.
22-
thread_local!(static CONTEXT_START_PATH: RefCell<Option<PathBuf>> = RefCell::new(None));
22+
thread_local!(static CONTEXT_START_PATH: RefCell<Option<PathBuf>> = const { RefCell::new(None) });
2323

2424
pub fn with_start_path<F, T>(start_path: &Path, f: F) -> T
2525
where

0 commit comments

Comments
 (0)