Struct wasm_oidc_plugin::discovery::OidcDiscovery
source · pub struct OidcDiscovery {
pub state: OidcRootState,
waiting: Mutex<Vec<u32>>,
token_id: Option<u32>,
}
Expand description
This context is responsible for getting the OIDC configuration, jwks keys and setting the http context.
Fields§
§state: OidcRootState
The state of the root context. This is an enum which has the following variants:
- Uninitialized: The plugin is not yet configured
- LoadingConfig: The plugin configuration is being loaded
- LoadingJwks: The jwks configuration is being loaded
- Ready: The plugin is ready
waiting: Mutex<Vec<u32>>
Queue of waiting requests which are waiting for the configuration to be loaded
token_id: Option<u32>
token_id of the HttpCalls to verify the call is correct
Implementations§
source§impl OidcDiscovery
impl OidcDiscovery
sourcepub fn evaluate_config(
plugin_config: PluginConfiguration,
) -> Result<(), PluginError>
pub fn evaluate_config( plugin_config: PluginConfiguration, ) -> Result<(), PluginError>
Evaluate the plugin configuration and check if the values are valid. Type checking is done by serde, so we only need to check the values.
plugin_config
- The plugin configuration to be evaluated ReturnsOk
if the configuration is valid, otherwiseErr
with a message.
Trait Implementations§
source§impl Context for OidcDiscovery
impl Context for OidcDiscovery
The context is used to process the response from the OIDC config endpoint and the jwks endpoint. It also utilized the state enum to determine what to do with the response.
- If the state is
Uninitialized
, the plugin is not initialized and the response is ignored. - If the state is
LoadingConfig
, the open id configuration is expected. - If the state is
LoadingJwks
, the jwks endpoint is expected. Ready
is not expected, as the root context doesn’t dispatch any calls in that state.
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 the http call is received. It also utilised the state enum to determine what to do with the response.
- If the state is
Uninitialized
, the plugin is not initialized and the response is ignored. - If the state is
LoadingConfig
, the open id configuration is expected. - If the state is
LoadingJwks
, the jwks endpoint is expected. Ready
is not expected, as the root context doesn’t dispatch any calls in that state.
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 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 OidcDiscovery
impl RootContext for OidcDiscovery
The root context is used to create new HTTP contexts and load configuration from the
open id discovery endpoint and the jwks endpoint.
When on_configure
is called, the plugin configuration is loaded and the state is set to
LoadingConfig. The filter is then ticked immediately to load the configuration.
When on_http_call_response
is called, the Open ID response is parsed and the state is set to
LoadingJwks.
On the next tick, the jwks endpoint is called and the state is set to Ready once the jwks
response is received and successfully parsed.
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_config 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 Unconfigured
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 400 millis as long as the configuration is not loaded yet. On every tick, the state is checked and the corresponding action is taken.
- If the state is
Uninitialized
, the configuration is loaded from the plugin configuration. - If the state is
LoadingConfig
, the configuration is loaded from the openid configuration endpoint. - If the state is
LoadingJwks
, the public key is loaded from the jwks endpoint. - If the state is
Ready
, the configuration is reloaded.
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.