pub struct Root {
pub plugin_config: Option<Arc<V2PluginConfiguration>>,
pub open_id_resolvers: Vec<OpenIdResolver>,
pub open_id_providers: Vec<OpenIdProvider>,
pub waiting: Mutex<Vec<u32>>,
pub discovery_active: bool,
}Expand description
This is the main context which loads and parses the plugin configuration, handles the discovery of all Open ID Providers and creates the HTTP Contexts.
Fields§
§plugin_config: Option<Arc<V2PluginConfiguration>>Plugin config loaded from the envoy configuration
open_id_resolvers: Vec<OpenIdResolver>A set of Open ID Resolvers which are used to load the configuration from the discovery endpoint
open_id_providers: Vec<OpenIdProvider>A set of Open ID Providers which are used to store the configuration from the discovery endpoint
waiting: Mutex<Vec<u32>>Queue of waiting requests which are waiting for the configuration to be loaded
discovery_active: boolFlag to determine if the discovery is active
Trait Implementations§
Source§impl Context for Root
The context processes all responses from the open id config endpoints and jwks endpoints.
impl Context for Root
The context processes all responses from the open id config endpoints and jwks endpoints.
Source§fn on_http_call_response(
&mut self,
token_id: u32,
_num_headers: usize,
_body_size: usize,
_num_trailers: usize,
)
fn on_http_call_response( &mut self, token_id: u32, _num_headers: usize, _body_size: usize, _num_trailers: usize, )
Called when the response from any http call (sent from root context) is received.
fn get_current_time(&self) -> SystemTime
fn get_property(&self, path: Vec<&str>) -> Option<Vec<u8>>
fn set_property(&self, path: Vec<&str>, value: Option<&[u8]>)
fn dispatch_http_call( &self, upstream: &str, headers: Vec<(&str, &str)>, body: Option<&[u8]>, trailers: Vec<(&str, &str)>, timeout: Duration, ) -> Result<u32, Status>
fn get_http_call_response_headers(&self) -> Vec<(String, String)>
fn get_http_call_response_headers_bytes(&self) -> Vec<(String, Vec<u8>)>
fn get_http_call_response_header(&self, name: &str) -> Option<String>
fn get_http_call_response_header_bytes(&self, name: &str) -> Option<Vec<u8>>
fn get_http_call_response_body( &self, start: usize, max_size: usize, ) -> Option<Vec<u8>>
fn get_http_call_response_trailers(&self) -> Vec<(String, String)>
fn get_http_call_response_trailers_bytes(&self) -> Vec<(String, Vec<u8>)>
fn get_http_call_response_trailer(&self, name: &str) -> Option<String>
fn get_http_call_response_trailer_bytes(&self, name: &str) -> Option<Vec<u8>>
fn dispatch_grpc_call( &self, upstream_name: &str, service_name: &str, method_name: &str, initial_metadata: Vec<(&str, &[u8])>, message: Option<&[u8]>, timeout: Duration, ) -> Result<u32, Status>
fn on_grpc_call_response( &mut self, _token_id: u32, _status_code: u32, _response_size: usize, )
fn get_grpc_call_response_body( &self, start: usize, max_size: usize, ) -> Option<Vec<u8>>
fn cancel_grpc_call(&self, token_id: u32)
fn open_grpc_stream( &self, cluster_name: &str, service_name: &str, method_name: &str, initial_metadata: Vec<(&str, &[u8])>, ) -> Result<u32, Status>
fn on_grpc_stream_initial_metadata( &mut self, _token_id: u32, _num_elements: u32, )
fn get_grpc_stream_initial_metadata(&self) -> Vec<(String, Vec<u8>)>
fn get_grpc_stream_initial_metadata_value(&self, name: &str) -> Option<Vec<u8>>
fn send_grpc_stream_message( &self, token_id: u32, message: Option<&[u8]>, end_stream: bool, )
fn on_grpc_stream_message(&mut self, _token_id: u32, _message_size: usize)
fn get_grpc_stream_message( &mut self, start: usize, max_size: usize, ) -> Option<Vec<u8>>
fn on_grpc_stream_trailing_metadata( &mut self, _token_id: u32, _num_elements: u32, )
fn get_grpc_stream_trailing_metadata(&self) -> Vec<(String, Vec<u8>)>
fn get_grpc_stream_trailing_metadata_value(&self, name: &str) -> Option<Vec<u8>>
fn cancel_grpc_stream(&self, token_id: u32)
fn close_grpc_stream(&self, token_id: u32)
fn on_grpc_stream_close(&mut self, _token_id: u32, _status_code: u32)
fn get_grpc_status(&self) -> (u32, Option<String>)
fn on_foreign_function(&mut self, _function_id: u32, _arguments_size: usize)
fn call_foreign_function( &self, function_name: &str, arguments: Option<&[u8]>, ) -> Result<Option<Vec<u8>>, Status>
fn on_done(&mut self) -> bool
fn done(&self)
Source§impl RootContext for Root
The root context creates new HTTP Contexts and is responsible for loading the plugin configuration, as
well as the discovery of the Open ID Providers.
The first step after startup is the loading of the plugin configuration. This is done in the on_configure
function. The plugin configuration is loaded from the plugin configuration and parsed into the
PluginConfiguration struct. The configuration is then evaluated and checked if the values are valid.
If the configuration is valid, the plugin configuration is stored in the root context and the next state
is set. The next state is to load the configuration from the Open ID Providers. This is done by creating
a new OpenIdResolver for each Open ID Provider in the plugin configuration. The state of the resolver
is set to LoadingConfig and the configuration is loaded from the Open ID Configuration endpoint. The
response is handled in the on_http_call_response function. If the response is successful, the state is
set to LoadingJwks and the jwks endpoint is called. The response is handled in the on_http_call_response
function. If the response is successful, the state is set to Ready and the Open ID Provider is stored in
the root context. If all Open ID Providers are in the Ready state, the plugin is ready and the waiting
requests are resumed.
impl RootContext for Root
The root context creates new HTTP Contexts and is responsible for loading the plugin configuration, as
well as the discovery of the Open ID Providers.
The first step after startup is the loading of the plugin configuration. This is done in the on_configure
function. The plugin configuration is loaded from the plugin configuration and parsed into the
PluginConfiguration struct. The configuration is then evaluated and checked if the values are valid.
If the configuration is valid, the plugin configuration is stored in the root context and the next state
is set. The next state is to load the configuration from the Open ID Providers. This is done by creating
a new OpenIdResolver for each Open ID Provider in the plugin configuration. The state of the resolver
is set to LoadingConfig and the configuration is loaded from the Open ID Configuration endpoint. The
response is handled in the on_http_call_response function. If the response is successful, the state is
set to LoadingJwks and the jwks endpoint is called. The response is handled in the on_http_call_response
function. If the response is successful, the state is set to Ready and the Open ID Provider is stored in
the root context. If all Open ID Providers are in the Ready state, the plugin is ready and the waiting
requests are resumed.
Source§fn on_configure(&mut self, _plugin_configuration_size: usize) -> bool
fn on_configure(&mut self, _plugin_configuration_size: usize) -> bool
Called when proxy is being configured. This is where the plugin configuration is loaded and the next state is set.
Source§fn create_http_context(&self, context_id: u32) -> Option<Box<dyn HttpContext>>
fn create_http_context(&self, context_id: u32) -> Option<Box<dyn HttpContext>>
Creates the http context with the information from the open_id_providers and the plugin_configuration.
This is called whenever a new http context is created by the proxy.
When the plugin is not yet ready, the http context is created in PauseRequests state and the
context id is added to the waiting queue to be processed later.
Source§fn on_tick(&mut self)
fn on_tick(&mut self)
The root context is ticking every the configured interval (x) as long as the configuration is not loaded yet.
On every tick, the plugin is checking if the discovery is active. If the discovery is not active,
the plugin is starting the discovery (as it has been waiting for reload_interval_in_h * 3600).
The discovery is started by setting the discovery active to true and setting the state of all resolvers
to LoadingConfig. The ticking period is set to x ms to not overload the openid configuration endpoint (x is
the configured interval).
If the discovery is active, the plugin is checking if all resolvers are in Ready state. If all resolvers
are in Ready state, the plugin is resuming all requests that were sent during the loading phase. The
discovery is switched to false and the ticking period is set to the configured interval.
If the discovery is active and not all resolvers are in Ready state, the plugin is making a call to the
openid configuration endpoint or the jwks endpoint depending on the state of the resolver.
Source§fn get_type(&self) -> Option<ContextType>
fn get_type(&self) -> Option<ContextType>
This is one of those functions that need to be there for some reason but we are not sure why. It just doesn’t work without it.