@@ -32,9 +32,9 @@ pub struct Root {
32
32
/// Plugin config loaded from the envoy configuration
33
33
pub plugin_config : Option < Arc < PluginConfiguration > > ,
34
34
/// A set of Open ID Resolvers which are used to load the configuration from the discovery endpoint
35
- pub open_id_resolvers : Mutex < Vec < OpenIdResolver > > ,
35
+ pub open_id_resolvers : Vec < OpenIdResolver > ,
36
36
/// A set of Open ID Providers which are used to store the configuration from the discovery endpoint
37
- pub open_id_providers : Mutex < Vec < OpenIdProvider > > ,
37
+ pub open_id_providers : Vec < OpenIdProvider > ,
38
38
/// Queue of waiting requests which are waiting for the configuration to be loaded
39
39
pub waiting : Mutex < Vec < u32 > > ,
40
40
/// Flag to determine if the discovery is active
@@ -159,7 +159,7 @@ impl RootContext for Root {
159
159
} ;
160
160
resolvers. push ( open_id_resolver) ;
161
161
}
162
- self . open_id_resolvers = Mutex :: new ( resolvers) ;
162
+ self . open_id_resolvers = resolvers;
163
163
164
164
// Tick immediately to load the configuration.
165
165
// See `on_tick` for more information.
@@ -187,7 +187,7 @@ impl RootContext for Root {
187
187
188
188
// Return the http context.
189
189
Some ( Box :: new ( ConfiguredOidc {
190
- open_id_providers : Arc :: new ( self . open_id_providers . lock ( ) . unwrap ( ) . to_vec ( ) ) ,
190
+ open_id_providers : Arc :: new ( self . open_id_providers . clone ( ) ) ,
191
191
plugin_config : self . plugin_config . clone ( ) ?,
192
192
token_id : None ,
193
193
request_id : None ,
@@ -231,7 +231,7 @@ impl RootContext for Root {
231
231
232
232
// Set discovery to active and set the state of all resolvers to `LoadingConfig`.
233
233
self . discovery_active = true ;
234
- for resolver in self . open_id_resolvers . lock ( ) . unwrap ( ) . iter_mut ( ) {
234
+ for resolver in self . open_id_resolvers . iter_mut ( ) {
235
235
resolver. state = OpenIdResolverState :: LoadingConfig ;
236
236
}
237
237
// Tick every x ms to not overload the openid configuration endpoint. x is the configured interval.
@@ -245,8 +245,6 @@ impl RootContext for Root {
245
245
// configured interval.
246
246
let all_resolvers_done = self
247
247
. open_id_resolvers
248
- . lock ( )
249
- . unwrap ( )
250
248
. iter_mut ( )
251
249
. all ( |r| matches ! ( r. state, OpenIdResolverState :: Ready { .. } ) ) ;
252
250
@@ -278,12 +276,12 @@ impl RootContext for Root {
278
276
}
279
277
280
278
// Make call to openid configuration endpoint for all providers whose state is not ready.
281
- for resolver in self . open_id_resolvers . lock ( ) . unwrap ( ) . iter_mut ( ) {
279
+ for resolver in self . open_id_resolvers . iter_mut ( ) {
282
280
match & resolver. state {
283
281
OpenIdResolverState :: LoadingConfig { .. } => {
284
282
// Make call to openid configuration endpoint and load configuration
285
283
// The response is handled in `on_http_call_response`.
286
- match self . dispatch_http_call (
284
+ match hostcalls :: dispatch_http_call (
287
285
& resolver. open_id_config . upstream_cluster ,
288
286
vec ! [
289
287
( ":method" , "GET" ) ,
@@ -309,7 +307,7 @@ impl RootContext for Root {
309
307
// Make call to jwks endpoint for all providers whose state is not ready.
310
308
// The response is handled in `on_http_call_response`.
311
309
OpenIdResolverState :: LoadingJwks { open_id_response } => {
312
- match self . dispatch_http_call (
310
+ match hostcalls :: dispatch_http_call (
313
311
& resolver. open_id_config . upstream_cluster ,
314
312
vec ! [
315
313
( ":method" , "GET" ) ,
@@ -356,9 +354,10 @@ impl Context for Root {
356
354
_num_trailers : usize ,
357
355
) {
358
356
debug ! ( "received http call response with token_id: {}" , token_id) ;
357
+ let body = self . get_http_call_response_body ( 0 , _body_size) ;
359
358
360
359
// Find resolver to update based on toke_id
361
- let mut binding = self . open_id_resolvers . lock ( ) . unwrap ( ) ;
360
+ let binding = & mut self . open_id_resolvers ;
362
361
let resolver_to_update = match binding
363
362
. iter_mut ( )
364
363
. find ( |resolver| resolver. token_ids . contains ( & token_id) )
@@ -381,7 +380,7 @@ impl Context for Root {
381
380
// openid configuration.
382
381
OpenIdResolverState :: LoadingConfig => {
383
382
// Parse the response body as json.
384
- let body = match self . get_http_call_response_body ( 0 , _body_size ) {
383
+ let body = match body {
385
384
Some ( body) => body,
386
385
None => {
387
386
warn ! ( "no body in openid config response" ) ;
@@ -416,7 +415,7 @@ impl Context for Root {
416
415
open_id_response, ..
417
416
} => {
418
417
// Parse body using serde_json or fail
419
- let body = match self . get_http_call_response_body ( 0 , _body_size ) {
418
+ let body = match body {
420
419
Some ( body) => body,
421
420
None => {
422
421
warn ! ( "no body in jwks response" ) ;
@@ -450,15 +449,14 @@ impl Context for Root {
450
449
}
451
450
452
451
// Find OpenIdProvider to update or create a new one
453
- let mut open_id_providers = self . open_id_providers . lock ( ) . unwrap ( ) ;
454
- let provider = open_id_providers. iter_mut ( ) . find ( |provider| {
452
+ let provider = self . open_id_providers . iter_mut ( ) . find ( |provider| {
455
453
provider. issuer == resolver_to_update. open_id_config . authority
456
454
} ) ;
457
455
458
456
if let Some ( p) = provider {
459
457
p. public_keys = keys;
460
458
} else {
461
- open_id_providers. push ( OpenIdProvider {
459
+ self . open_id_providers . push ( OpenIdProvider {
462
460
open_id_config : resolver_to_update. open_id_config . clone ( ) ,
463
461
auth_endpoint : open_id_response. authorization_endpoint . clone ( ) ,
464
462
token_endpoint : open_id_response. token_endpoint . clone ( ) ,
0 commit comments