File tree Expand file tree Collapse file tree 10 files changed +33
-25
lines changed Expand file tree Collapse file tree 10 files changed +33
-25
lines changed Original file line number Diff line number Diff 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+
1925impl BackgroundTasksManager {
2026 pub fn new ( ) -> Self {
2127 Self {
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ use sonic_rs::Value;
66
77pub type TokenPayload = TokenData < JwtClaims > ;
88
9+ #[ allow( dead_code) ] // TODO: Remove this when we actually use this and integrate with header propagation
910pub struct JwtRequestContext {
1011 pub token : String ,
1112 pub payload : TokenPayload ,
Original file line number Diff line number Diff line change @@ -46,12 +46,12 @@ pub enum JwtError {
4646}
4747
4848impl 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 {
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ use sonic_rs::from_str;
33use std:: sync:: { Arc , RwLock } ;
44use tokio:: fs:: read_to_string;
55use tokio_util:: sync:: CancellationToken ;
6+ use tracing:: debug;
67
78use 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}
Original file line number Diff line number Diff 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 {
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 1+ #[ cfg( test) ]
12mod jwt;
23#[ cfg( test) ]
34mod testkit;
Original file line number Diff line number Diff 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
3233pub fn init_logger ( ) {
3334 TRACING_INIT . call_once ( || {
3435 let subscriber = tracing_subscriber:: registry ( )
Original file line number Diff line number Diff 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" ,
Original file line number Diff line number Diff 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
2424pub fn with_start_path < F , T > ( start_path : & Path , f : F ) -> T
2525where
You can’t perform that action at this time.
0 commit comments