From d8b90e6f344941b95af4e35ba67074e1d01d62c2 Mon Sep 17 00:00:00 2001 From: Anton Engelhardt Date: Tue, 27 Feb 2024 12:45:14 +0100 Subject: [PATCH 01/14] In-Code Documentation * `dispatch_http_call()` * `on_http_call_response()`` * `on_vm_start()` * `get_vm_configuration()` * `on_configure()` * `get_plugin_configuration()` * `set_tick_period()` * `on_tick()` * `on_http_request_headers()` * `get_http_request_headers()` * `get_http_request_header()` * `add_http_request_header()` * `resume_http_context()` * `send_http_response()` Signed-off-by: Anton Engelhardt --- src/traits.rs | 465 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 465 insertions(+) diff --git a/src/traits.rs b/src/traits.rs index 034f87ea..005e2e38 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -58,6 +58,62 @@ pub trait Context { hostcalls::enqueue_shared_queue(queue_id, value) } + /// Sends HTTP request with serialized `headers`, `body`, and serialized trailers to upstream. + /// + /// `on_http_call_response()` will be called with `token_id` when the response is received by the host, or after the timeout. + /// + /// # Arguments + /// + /// * `upstream` - The name of the upstream to send the request to (in your envoy configuration) + /// * `headers` - The headers to send with the request (in the form of `Vec<(&str, &str)>`) + /// * `body` - The body of the request (in the form of `Option<&[u8]>` - `None` if no body) + /// * `trailers` - The trailers to send with the request (in the form of `Vec<(&str, &str)>`) + /// * `timeout` - The timeout for the request + /// + /// # Returns + /// + /// * `OK` on success. + /// * `BAD_ARGUMENT` for unknown upstream, or when headers are missing required `:authority`, `:method` and/or `:path` values. + /// * `INTERNAL_FAILURE' when the host failed to send requested HTTP call. + /// * `INVALID_MEMORY_ACCESS` when `upstream_data`, `upstream_size`, `headers_data`, `headers_size`, `body_data`, `body_size`, `trailers_data`, `trailers_size` and/or `return_call_id` point to invalid memory address. + /// + /// # Example + /// + /// ```rust + /// use proxy_wasm::traits::*; + /// use proxy_wasm::types::*; + /// use std::time::Duration; + /// + /// struct MyContext; + /// + /// impl HttpContext for MyContext { + /// + /// fn on_http_request_headers(&mut self, _num_headers: usize) -> Action { + /// + /// match self.dispatch_http_call( + /// "upstream", + /// vec![(":method", "GET"), (":path", "/"), (":authority", "www.example.com")], + /// None, + /// vec![] + /// Duration::from_secs(5), + /// ) { + /// Ok(_) => Action::Pause, + /// Err(_) => Action::Continue, + /// } + /// } + /// } + /// + /// impl Context for MyContext { + /// + /// fn on_http_call_response(&mut self, token_id: u32, _: usize, body_size: usize, _: usize) { + /// + /// let headers = self.get_http_call_response_headers(); + /// let body = self.get_http_call_response_body(0, body_size); + /// + /// // Do something with the response + /// + /// } + /// } fn dispatch_http_call( &self, upstream: &str, @@ -69,6 +125,59 @@ pub trait Context { hostcalls::dispatch_http_call(upstream, headers, body, trailers, timeout) } + /// Called when HTTP response for call_id sent using proxy_http_call is received. + /// + /// If `num_headers` is 0, then the HTTP call failed. + /// + /// All `num_headers` headers can be retrieved using `self.get_http_response_headers()` or individually `self.get_http_response_header()`. + /// + /// All `num_trailers` trailers can be retrieved using `self.get_http_response_trailers()` or individually `self.get_http_response_trailer()`. + /// + /// # Arguments + /// + /// * `token_id` - The token id of the call + /// * `num_headers` - The number of headers in the response + /// * `body_size` - The size of the body in the response + /// * `num_trailers` - The number of trailers in the response + /// + /// # Example + /// + /// ```rust + /// + /// use proxy_wasm::traits::*; + /// use proxy_wasm::types::*; + /// + /// struct MyContext; + /// + /// impl HttpContext for MyContext { + /// + /// fn on_http_request_headers(&mut self, _num_headers: usize) -> Action { + /// + /// match self.dispatch_http_call( + /// "upstream", + /// vec![(":method", "GET"), (":path", "/"), (":authority", "www.example.com")], + /// None, + /// vec![] + /// Duration::from_secs(5), + /// ) { + /// Ok(_) => Action::Pause, + /// Err(_) => Action::Continue, + /// } + /// } + /// } + /// + /// impl Context for MyContext { + /// + /// fn on_http_call_response(&mut self, token_id: u32, _: usize, body_size: usize, _: usize) { + /// + /// let headers = self.get_http_call_response_headers(); + /// let body = self.get_http_call_response_body(0, body_size); + /// + /// // Do something with the response + /// + /// } + /// } + /// ``` fn on_http_call_response( &mut self, _token_id: u32, @@ -215,26 +324,225 @@ pub trait Context { } pub trait RootContext: Context { + /// Called when the host starts the WebAssembly Virtual Machine. + /// + /// Its configuration (of `_vm_configuration_size`) can be retrieved using `self.get_vm_configuration()`. + /// + /// # Arguments + /// + /// * `vm_configuration_size` - the size of the VM configuration + /// + /// # Returns + /// + /// * `bool` - `true` if the configuration was processed successfully, `false` otherwise + /// + /// /// # Example + /// + /// ```rust + /// + /// use proxy_wasm::traits::RootContext; + /// + /// struct MyRootContext; + /// + /// struct MyVmConfiguration { + /// /// Some key + /// pub key: String, + /// } + /// + /// impl RootContext for MyRootContext { + /// + /// fn on_vm_start(&mut self, _vm_configuration_size: usize) -> bool { + /// + /// let vm_confuguration = self.get_vm_configuration().unwrap(); + /// + /// let parsed_vm_configuration: MyVmConfiguration = serde_json::from_slice::(&vm_confuguration).unwrap(); + /// + /// // Do something with the parsed vm configuration + /// + /// true + /// } + /// } fn on_vm_start(&mut self, _vm_configuration_size: usize) -> bool { true } + /// Get the VM configuration. + /// + /// # Returns + /// + /// * `Option` - the VM configuration + /// + /// # Example + /// + /// ```rust + /// + /// use proxy_wasm::traits::RootContext; + /// + /// struct MyRootContext; + /// + /// struct MyVmConfiguration { + /// /// Some key + /// pub key: String, + /// } + /// + /// impl RootContext for MyRootContext { + /// + /// fn on_vm_start(&mut self, _vm_configuration_size: usize) -> bool { + /// + /// let vm_confuguration = self.get_vm_configuration().unwrap(); + /// + /// let parsed_vm_configuration: MyVmConfiguration = serde_json::from_slice::(&vm_confuguration).unwrap(); + /// + /// // Do something with the parsed vm configuration + /// + /// true + /// } + /// } fn get_vm_configuration(&self) -> Option { hostcalls::get_buffer(BufferType::VmConfiguration, 0, usize::MAX).unwrap() } + /// Called when the host starts the Proxy-Wasm plugin. + /// + /// Its configuration (of `_plugin_configuration_size`) can be retrieved using `self.get_plugin_configuration()`. + /// + /// # Returns + /// + /// Plugin must return one of the following values: + /// + /// * `true` - to indicate that the configuration was processed successfully. + /// * `false` - to indicate that the configuration processing failed. + /// + /// # Example + /// + /// ```rust + /// + /// use proxy_wasm::traits::RootContext; + /// + /// struct MyRootContext; + /// + /// struct MyPluginConfiguration { + /// /// Some key + /// pub key: String, + /// } + /// + /// impl RootContext for MyRootContext { + /// + /// fn on_configure(&mut self, _plugin_configuration_size: usize) -> bool { + /// + /// let plugin_configuration = self.get_plugin_configuration().unwrap(); + /// + /// let parsed_plugin_configuration: MyPluginConfiguration = serde_json::from_slice::(&plugin_configuration).unwrap(); + /// + /// // Do something with the parsed plugin configuration + /// + /// true + /// } + /// } fn on_configure(&mut self, _plugin_configuration_size: usize) -> bool { true } + /// Get the plugin configuration. + /// + /// # Returns + /// + /// * `Option` - the plugin configuration + /// + /// # Example + /// + /// ```rust + /// + /// use proxy_wasm::traits::RootContext; + /// + /// struct MyRootContext; + /// + /// struct MyPluginConfiguration { + /// /// Some key + /// pub key: String, + /// } + /// + /// impl RootContext for MyRootContext { + /// + /// fn on_configure(&mut self, _plugin_configuration_size: usize) -> bool { + /// + /// let plugin_configuration = self.get_plugin_configuration().unwrap(); + /// + /// let parsed_plugin_configuration: MyPluginConfiguration = serde_json::from_slice::(&plugin_configuration).unwrap(); + /// + /// // Do something with the parsed plugin configuration + /// + /// true + /// } + /// } fn get_plugin_configuration(&self) -> Option { hostcalls::get_buffer(BufferType::PluginConfiguration, 0, usize::MAX).unwrap() } + /// Sets timer period. When set, `on_tick` will be called every `tick_period`. This is useful for making periodic updates to cached data, etc. + /// + /// # Arguments + /// + /// * `period` - the period of the timer + /// + /// # Example + /// + /// ```rust + /// + /// use proxy_wasm::traits::RootContext; + /// use std::time::Duration; + /// use log::info; + /// + /// struct MyRootContext; + /// + /// impl RootContext for MyRootContext { + /// + /// fn on_vm_start(&mut self, _vm_configuration_size: usize) -> bool { + /// + /// self.set_tick_period(Duration::from_millis(5000)); + /// + /// true + /// } + /// + /// fn on_tick(&mut self) { + /// + /// // Do something every 5 seconds + /// info!("tick!") + /// } + /// } fn set_tick_period(&self, period: Duration) { hostcalls::set_tick_period(period).unwrap() } + /// Called on a timer every tick period. + /// + /// The tick period can be configured using `proxy_set_tick_period_milliseconds`. + /// + /// # Example + /// + /// ```rust + /// + /// use proxy_wasm::traits::RootContext; + /// use std::time::Duration; + /// use log::info; + /// + /// struct MyRootContext; + /// + /// impl RootContext for MyRootContext { + /// + /// fn on_vm_start(&mut self, _vm_configuration_size: usize) -> bool { + /// + /// self.set_tick_period(Duration::from_millis(5000)); + /// + /// true + /// } + /// + /// fn on_tick(&mut self) { + /// + /// // Do something every 5 seconds + /// info!("tick!") + /// } + /// } fn on_tick(&mut self) {} fn on_queue_ready(&mut self, _queue_id: u32) {} @@ -307,10 +615,77 @@ pub trait StreamContext: Context { } pub trait HttpContext: Context { + + /// Called when HTTP request headers are received from downstream. + /// + /// All `num_headers` headers can be retrieved and/or modified using `self.get_http_request_headers()`. + /// + /// Individual HTTP request headers can be retrieved and/or modified using `self.get_http_request_header()`, `self.add_http_request_header()`. + /// + /// Paused request can be resumed using `self.resume_http_request()` or closed using `self.reset_http_request()`. + /// + /// Additionally, instead of forwarding request upstream, a HTTP response can be sent using `self.send_http_response()`. + /// + /// # Arguments + /// + /// * `num_headers` - the number of HTTP request headers + /// * `end_of_stream` - indicates if this is the last call for the request headers + /// + /// # Returns + /// + /// Plugin must return one of the following values: + /// + /// * `CONTINUE` to forward `HTTP_REQUEST_HEADERS` fields downstream. + /// * `PAUSE` to pause processing. + /// + /// # Example + /// + /// ```rust + /// use proxy_wasm::traits::*; + /// use proxy_wasm::types::*; + /// + /// use log::info; + /// + /// impl HttpContext for MyPlugin { + /// + /// fn on_http_request_headers(&mut self, num_headers: usize, end_of_stream: bool) -> Action { + /// + /// let headers = self.get_http_request_headers(); + /// + /// // Process the request + /// + /// Action::Continue + /// } + /// } + /// ``` fn on_http_request_headers(&mut self, _num_headers: usize, _end_of_stream: bool) -> Action { Action::Continue } + /// Get all HTTP request headers. + /// + /// # Returns + /// + /// * `Vec<(String, String)>` - a list of HTTP request headers + /// + /// # Example + /// + /// ```rust + /// use log::info; + /// use proxy_wasm::traits::HttpContext; + /// + /// impl HttpContext for MyPlugin { + /// fn on_http_request_headers(&mut self, _: usize, _: bool) -> Action { + /// + /// let headers = self.get_http_request_headers(); + /// + /// for (name, value) in headers { + /// info!("{}: {}", name, value); + /// } + /// Action::Continue + /// } + /// } + /// fn get_http_request_headers(&self) -> Vec<(String, String)> { hostcalls::get_map(MapType::HttpRequestHeaders).unwrap() } @@ -327,6 +702,36 @@ pub trait HttpContext: Context { hostcalls::set_map_bytes(MapType::HttpRequestHeaders, headers).unwrap() } + /// Get a specific HTTP request header. + /// + /// # Arguments + /// + /// * `name` - the name of the header + /// + /// # Returns + /// + /// * `Option` - the value of the header (wrapped in an Option) or `None` if the header does not exist + /// + /// # Example + /// + /// ```rust + /// + /// use log::info; + /// use proxy_wasm::traits:*; + /// use proxy_wasm::types::Action; + /// + /// impl HttpContext for MyPlugin { + /// fn on_http_request_headers(&mut self, _: usize, _: bool) -> Action { + /// + /// let header = self.get_http_request_header(":path"); + /// + /// match header { + /// Some(value) => info!("The path is: {}", value), + /// None => info!("The path is missing") + /// } + /// Action::Continue + /// } + /// } fn get_http_request_header(&self, name: &str) -> Option { hostcalls::get_map_value(MapType::HttpRequestHeaders, name).unwrap() } @@ -343,6 +748,29 @@ pub trait HttpContext: Context { hostcalls::set_map_value_bytes(MapType::HttpRequestHeaders, name, value).unwrap() } + /// Add a new HTTP request header to be sent upstream. + /// + /// # Arguments + /// + /// * `name` - the name of the header + /// * `value` - the value of the header + /// + /// # Example + /// + /// ```rust + /// + /// use proxy_wasm::traits::*; + /// use proxy_wasm::types::Action; + /// + /// impl HttpContext for MyPlugin { + /// fn on_http_request_headers(&mut self, _: usize, _: bool) -> Action { + /// + /// self.add_http_request_header("x-my-header", "my-value"); + /// + /// Action::Continue + /// } + /// } + /// ``` fn add_http_request_header(&self, name: &str, value: &str) { hostcalls::add_map_value(MapType::HttpRequestHeaders, name, value).unwrap() } @@ -407,6 +835,7 @@ pub trait HttpContext: Context { hostcalls::add_map_value_bytes(MapType::HttpRequestTrailers, name, value).unwrap() } + /// Resumes processing of paused request. fn resume_http_request(&self) { hostcalls::resume_http_request().unwrap() } @@ -523,6 +952,42 @@ pub trait HttpContext: Context { hostcalls::reset_http_response().unwrap() } + /// Sends an HTTP response with the body and serialized headers. + /// + /// This can be used as long as HTTP response headers were not sent downstream. + /// + /// # Arguments + /// + /// * `status_code` - the HTTP status code + /// * `headers` - the HTTP headers as a `Vec` of `(&str, &str)` + /// * `body` - the HTTP body as a slice of bytes + /// + /// # Example + /// + /// ```rust + /// use log::info; + /// use proxy_wasm::traits::*; + /// use proxy_wasm::types::*; + /// + /// impl HttpContext for MyHttpContext { + /// + /// fn on_http_request_headers(&mut self, _num_headers: usize) -> Action { + /// + /// let auth = self.get_http_request_header("Authorization").unwrap_or_else( + /// || self.send_http_response(401, vec![("WWW-Authenticate", "Basic")], Some(b"Unauthorized")) + /// ); + /// + /// if auth == "I am authorized!" { + /// // Send an HTTP response with a status code of 200 and a body of "Hello, World!" + /// self.send_http_response(200, vec![("A header", "Some Value")], Some(b"Hello, World!")); + /// } else { + /// // Send an HTTP response with a status code of 403 and a body of "Forbidden" + /// self.send_http_response(403, vec![("location", "authenticate-here.com")], Some(b"Forbidden")); + /// } + /// + /// Action::Pause + /// } + /// } fn send_http_response( &self, status_code: u32, From 03514d9382a2fef192a4e1f55a0cea89e9d3ce43 Mon Sep 17 00:00:00 2001 From: Anton Engelhardt Date: Tue, 27 Feb 2024 20:28:15 +0100 Subject: [PATCH 02/14] All Examples tested and corrections added Signed-off-by: Anton Engelhardt --- src/traits.rs | 219 ++++++++++++++++++++++---------------------------- 1 file changed, 98 insertions(+), 121 deletions(-) diff --git a/src/traits.rs b/src/traits.rs index 005e2e38..e6d9eca6 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -82,38 +82,43 @@ pub trait Context { /// ```rust /// use proxy_wasm::traits::*; /// use proxy_wasm::types::*; - /// use std::time::Duration; + /// + /// use log::warn; /// /// struct MyContext; /// /// impl HttpContext for MyContext { - /// - /// fn on_http_request_headers(&mut self, _num_headers: usize) -> Action { - /// - /// match self.dispatch_http_call( - /// "upstream", - /// vec![(":method", "GET"), (":path", "/"), (":authority", "www.example.com")], - /// None, - /// vec![] + /// fn on_http_request_headers(&mut self, _num_headers: usize, _end_of_stream: bool) -> Action { + /// match self.dispatch_http_call( + /// "cluster_name", + /// vec![ + /// (":method", "GET"), + /// (":path", "/"), + /// (":authority", "google.com")], + /// None, + /// vec![], /// Duration::from_secs(5), - /// ) { + /// ) { /// Ok(_) => Action::Pause, - /// Err(_) => Action::Continue, + /// Err(e) => { + /// warn!("Failed to dispatch_http_call: {:?}", e); + /// Action::Pause + /// } /// } /// } /// } /// /// impl Context for MyContext { + /// fn on_http_call_response(&mut self, _token_id: u32, _: usize, body_size: usize, _: usize) { + /// let headers = self.get_http_call_response_headers(); + /// let body = self.get_http_call_response_body(0, body_size); /// - /// fn on_http_call_response(&mut self, token_id: u32, _: usize, body_size: usize, _: usize) { - /// - /// let headers = self.get_http_call_response_headers(); - /// let body = self.get_http_call_response_body(0, body_size); + /// info!("Received response headers: {:?}", headers); /// - /// // Do something with the response - /// - /// } + /// // Do something with the response + /// } /// } + /// ``` fn dispatch_http_call( &self, upstream: &str, @@ -143,39 +148,43 @@ pub trait Context { /// # Example /// /// ```rust - /// /// use proxy_wasm::traits::*; /// use proxy_wasm::types::*; /// + /// use log::warn; + /// /// struct MyContext; /// /// impl HttpContext for MyContext { - /// - /// fn on_http_request_headers(&mut self, _num_headers: usize) -> Action { - /// - /// match self.dispatch_http_call( - /// "upstream", - /// vec![(":method", "GET"), (":path", "/"), (":authority", "www.example.com")], - /// None, - /// vec![] + /// fn on_http_request_headers(&mut self, _num_headers: usize, _end_of_stream: bool) -> Action { + /// match self.dispatch_http_call( + /// "cluster_name", + /// vec![ + /// (":method", "GET"), + /// (":path", "/"), + /// (":authority", "google.com")], + /// None, + /// vec![], /// Duration::from_secs(5), - /// ) { + /// ) { /// Ok(_) => Action::Pause, - /// Err(_) => Action::Continue, + /// Err(e) => { + /// warn!("Failed to dispatch_http_call: {:?}", e); + /// Action::Pause + /// } /// } /// } /// } /// /// impl Context for MyContext { + /// fn on_http_call_response(&mut self, _token_id: u32, _: usize, body_size: usize, _: usize) { + /// let headers = self.get_http_call_response_headers(); + /// let body = self.get_http_call_response_body(0, body_size); /// - /// fn on_http_call_response(&mut self, token_id: u32, _: usize, body_size: usize, _: usize) { + /// info!("Received response headers: {:?}", headers); /// - /// let headers = self.get_http_call_response_headers(); - /// let body = self.get_http_call_response_body(0, body_size); - /// - /// // Do something with the response - /// - /// } + /// // Do something with the response + /// } /// } /// ``` fn on_http_call_response( @@ -339,7 +348,6 @@ pub trait RootContext: Context { /// /// # Example /// /// ```rust - /// /// use proxy_wasm::traits::RootContext; /// /// struct MyRootContext; @@ -350,16 +358,14 @@ pub trait RootContext: Context { /// } /// /// impl RootContext for MyRootContext { - /// - /// fn on_vm_start(&mut self, _vm_configuration_size: usize) -> bool { - /// + /// fn on_vm_start(&mut self, _vm_configuration_size: usize) -> bool { /// let vm_confuguration = self.get_vm_configuration().unwrap(); /// /// let parsed_vm_configuration: MyVmConfiguration = serde_json::from_slice::(&vm_confuguration).unwrap(); /// /// // Do something with the parsed vm configuration /// - /// true + /// true /// } /// } fn on_vm_start(&mut self, _vm_configuration_size: usize) -> bool { @@ -375,7 +381,6 @@ pub trait RootContext: Context { /// # Example /// /// ```rust - /// /// use proxy_wasm::traits::RootContext; /// /// struct MyRootContext; @@ -386,16 +391,14 @@ pub trait RootContext: Context { /// } /// /// impl RootContext for MyRootContext { - /// - /// fn on_vm_start(&mut self, _vm_configuration_size: usize) -> bool { - /// + /// fn on_vm_start(&mut self, _vm_configuration_size: usize) -> bool { /// let vm_confuguration = self.get_vm_configuration().unwrap(); /// /// let parsed_vm_configuration: MyVmConfiguration = serde_json::from_slice::(&vm_confuguration).unwrap(); /// /// // Do something with the parsed vm configuration /// - /// true + /// true /// } /// } fn get_vm_configuration(&self) -> Option { @@ -416,27 +419,24 @@ pub trait RootContext: Context { /// # Example /// /// ```rust - /// /// use proxy_wasm::traits::RootContext; /// /// struct MyRootContext; /// /// struct MyPluginConfiguration { - /// /// Some key - /// pub key: String, + /// /// Some key + /// pub key: String, /// } /// /// impl RootContext for MyRootContext { - /// - /// fn on_configure(&mut self, _plugin_configuration_size: usize) -> bool { - /// + /// fn on_configure(&mut self, _plugin_configuration_size: usize) -> bool { /// let plugin_configuration = self.get_plugin_configuration().unwrap(); /// /// let parsed_plugin_configuration: MyPluginConfiguration = serde_json::from_slice::(&plugin_configuration).unwrap(); /// /// // Do something with the parsed plugin configuration /// - /// true + /// true /// } /// } fn on_configure(&mut self, _plugin_configuration_size: usize) -> bool { @@ -452,7 +452,6 @@ pub trait RootContext: Context { /// # Example /// /// ```rust - /// /// use proxy_wasm::traits::RootContext; /// /// struct MyRootContext; @@ -463,16 +462,14 @@ pub trait RootContext: Context { /// } /// /// impl RootContext for MyRootContext { - /// - /// fn on_configure(&mut self, _plugin_configuration_size: usize) -> bool { - /// + /// fn on_configure(&mut self, _plugin_configuration_size: usize) -> bool { /// let plugin_configuration = self.get_plugin_configuration().unwrap(); /// /// let parsed_plugin_configuration: MyPluginConfiguration = serde_json::from_slice::(&plugin_configuration).unwrap(); /// /// // Do something with the parsed plugin configuration /// - /// true + /// true /// } /// } fn get_plugin_configuration(&self) -> Option { @@ -488,7 +485,6 @@ pub trait RootContext: Context { /// # Example /// /// ```rust - /// /// use proxy_wasm::traits::RootContext; /// use std::time::Duration; /// use log::info; @@ -496,19 +492,16 @@ pub trait RootContext: Context { /// struct MyRootContext; /// /// impl RootContext for MyRootContext { - /// /// fn on_vm_start(&mut self, _vm_configuration_size: usize) -> bool { + /// self.set_tick_period(Duration::from_millis(5000)); /// - /// self.set_tick_period(Duration::from_millis(5000)); - /// - /// true - /// } - /// - /// fn on_tick(&mut self) { + /// true + /// } /// - /// // Do something every 5 seconds - /// info!("tick!") - /// } + /// fn on_tick(&mut self) { + /// // Do something every 5 seconds + /// info!("tick!") + /// } /// } fn set_tick_period(&self, period: Duration) { hostcalls::set_tick_period(period).unwrap() @@ -516,12 +509,11 @@ pub trait RootContext: Context { /// Called on a timer every tick period. /// - /// The tick period can be configured using `proxy_set_tick_period_milliseconds`. + /// The tick period can be configured using `self.set_tick_period()`. /// /// # Example /// /// ```rust - /// /// use proxy_wasm::traits::RootContext; /// use std::time::Duration; /// use log::info; @@ -529,19 +521,16 @@ pub trait RootContext: Context { /// struct MyRootContext; /// /// impl RootContext for MyRootContext { - /// /// fn on_vm_start(&mut self, _vm_configuration_size: usize) -> bool { + /// self.set_tick_period(Duration::from_millis(5000)); /// - /// self.set_tick_period(Duration::from_millis(5000)); - /// - /// true - /// } - /// - /// fn on_tick(&mut self) { + /// true + /// } /// - /// // Do something every 5 seconds - /// info!("tick!") - /// } + /// fn on_tick(&mut self) { + /// // Do something every 5 seconds + /// info!("tick!") + /// } /// } fn on_tick(&mut self) {} @@ -615,7 +604,6 @@ pub trait StreamContext: Context { } pub trait HttpContext: Context { - /// Called when HTTP request headers are received from downstream. /// /// All `num_headers` headers can be retrieved and/or modified using `self.get_http_request_headers()`. @@ -647,14 +635,12 @@ pub trait HttpContext: Context { /// use log::info; /// /// impl HttpContext for MyPlugin { - /// - /// fn on_http_request_headers(&mut self, num_headers: usize, end_of_stream: bool) -> Action { - /// + /// fn on_http_request_headers(&mut self, num_headers: usize, end_of_stream: bool) -> Action { /// let headers = self.get_http_request_headers(); /// /// // Process the request /// - /// Action::Continue + /// Action::Continue /// } /// } /// ``` @@ -675,15 +661,14 @@ pub trait HttpContext: Context { /// use proxy_wasm::traits::HttpContext; /// /// impl HttpContext for MyPlugin { - /// fn on_http_request_headers(&mut self, _: usize, _: bool) -> Action { - /// - /// let headers = self.get_http_request_headers(); + /// fn on_http_request_headers(&mut self, _num_headers: usize, _end_of_stream: bool) -> Action { + /// let headers = self.get_http_request_headers(); /// - /// for (name, value) in headers { - /// info!("{}: {}", name, value); - /// } - /// Action::Continue + /// for (name, value) in headers { + /// info!("{}: {}", name, value); /// } + /// Action::Continue + /// } /// } /// fn get_http_request_headers(&self) -> Vec<(String, String)> { @@ -715,22 +700,20 @@ pub trait HttpContext: Context { /// # Example /// /// ```rust - /// /// use log::info; /// use proxy_wasm::traits:*; /// use proxy_wasm::types::Action; /// /// impl HttpContext for MyPlugin { - /// fn on_http_request_headers(&mut self, _: usize, _: bool) -> Action { - /// - /// let header = self.get_http_request_header(":path"); + /// fn on_http_request_headers(&mut self, _num_headers: usize, _end_of_stream: bool) -> Action { + /// let header = self.get_http_request_header(":path"); /// - /// match header { - /// Some(value) => info!("The path is: {}", value), - /// None => info!("The path is missing") - /// } - /// Action::Continue - /// } + /// match header { + /// Some(value) => info!("The path is: {}", value), + /// None => info!("The path is missing") + /// } + /// Action::Continue + /// } /// } fn get_http_request_header(&self, name: &str) -> Option { hostcalls::get_map_value(MapType::HttpRequestHeaders, name).unwrap() @@ -758,16 +741,14 @@ pub trait HttpContext: Context { /// # Example /// /// ```rust - /// /// use proxy_wasm::traits::*; /// use proxy_wasm::types::Action; /// /// impl HttpContext for MyPlugin { - /// fn on_http_request_headers(&mut self, _: usize, _: bool) -> Action { - /// - /// self.add_http_request_header("x-my-header", "my-value"); + /// fn on_http_request_headers(&mut self, _num_headers: usize, _end_of_stream: bool) -> Action { + /// self.add_http_request_header("x-my-header", "my-value"); /// - /// Action::Continue + /// Action::Continue /// } /// } /// ``` @@ -970,22 +951,18 @@ pub trait HttpContext: Context { /// use proxy_wasm::types::*; /// /// impl HttpContext for MyHttpContext { + /// fn on_http_request_headers(&mut self, _num_headers: usize, _end_of_stream: bool) -> Action { + /// let auth = self.get_http_request_header("Authorization").unwrap_or_defauklt(); /// - /// fn on_http_request_headers(&mut self, _num_headers: usize) -> Action { - /// - /// let auth = self.get_http_request_header("Authorization").unwrap_or_else( - /// || self.send_http_response(401, vec![("WWW-Authenticate", "Basic")], Some(b"Unauthorized")) - /// ); - /// - /// if auth == "I am authorized!" { + /// if auth == "I am authorized!" { /// // Send an HTTP response with a status code of 200 and a body of "Hello, World!" - /// self.send_http_response(200, vec![("A header", "Some Value")], Some(b"Hello, World!")); - /// } else { - /// // Send an HTTP response with a status code of 403 and a body of "Forbidden" - /// self.send_http_response(403, vec![("location", "authenticate-here.com")], Some(b"Forbidden")); - /// } + /// self.send_http_response(200, vec![("A header", "Some Value")], Some(b"Hello, World!")); + /// } else { + /// // Send an HTTP response with a status code of 403 and a body of "Forbidden" + /// self.send_http_response(307, vec![("location", "https://authenticate-here.com")], Some(b"Forbidden")); + /// } /// - /// Action::Pause + /// Action::Pause /// } /// } fn send_http_response( From 2d9990adef08e4e41a3b31e57a4097558b8d835e Mon Sep 17 00:00:00 2001 From: Anton Engelhardt Date: Tue, 30 Apr 2024 17:03:25 +0200 Subject: [PATCH 03/14] added missing backticks, tested all scenarios again and added missing stuff Signed-off-by: Anton Engelhardt --- src/traits.rs | 93 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 62 insertions(+), 31 deletions(-) diff --git a/src/traits.rs b/src/traits.rs index e6d9eca6..c7342f33 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -85,12 +85,12 @@ pub trait Context { /// /// use log::warn; /// - /// struct MyContext; + /// struct MyPlugin; /// - /// impl HttpContext for MyContext { + /// impl HttpContext for MyPlugin { /// fn on_http_request_headers(&mut self, _num_headers: usize, _end_of_stream: bool) -> Action { /// match self.dispatch_http_call( - /// "cluster_name", + /// "cluster_name_from_envoy_config", /// vec![ /// (":method", "GET"), /// (":path", "/"), @@ -108,7 +108,7 @@ pub trait Context { /// } /// } /// - /// impl Context for MyContext { + /// impl Context for MyPlugin { /// fn on_http_call_response(&mut self, _token_id: u32, _: usize, body_size: usize, _: usize) { /// let headers = self.get_http_call_response_headers(); /// let body = self.get_http_call_response_body(0, body_size); @@ -151,14 +151,14 @@ pub trait Context { /// use proxy_wasm::traits::*; /// use proxy_wasm::types::*; /// - /// use log::warn; + /// use log::{debug, warn}; /// - /// struct MyContext; + /// struct MyPlugin; /// - /// impl HttpContext for MyContext { + /// impl HttpContext for MyPlugin { /// fn on_http_request_headers(&mut self, _num_headers: usize, _end_of_stream: bool) -> Action { /// match self.dispatch_http_call( - /// "cluster_name", + /// "google", /// vec![ /// (":method", "GET"), /// (":path", "/"), @@ -176,12 +176,12 @@ pub trait Context { /// } /// } /// - /// impl Context for MyContext { + /// impl Context for MyPlugin { /// fn on_http_call_response(&mut self, _token_id: u32, _: usize, body_size: usize, _: usize) { /// let headers = self.get_http_call_response_headers(); /// let body = self.get_http_call_response_body(0, body_size); /// - /// info!("Received response headers: {:?}", headers); + /// debug!("Received response headers: {:?}", headers); /// /// // Do something with the response /// } @@ -345,13 +345,15 @@ pub trait RootContext: Context { /// /// * `bool` - `true` if the configuration was processed successfully, `false` otherwise /// - /// /// # Example + /// # Example /// /// ```rust /// use proxy_wasm::traits::RootContext; /// /// struct MyRootContext; /// + /// #[derive(serde::Deserialize)] + /// #[derive(Debug)] /// struct MyVmConfiguration { /// /// Some key /// pub key: String, @@ -359,15 +361,17 @@ pub trait RootContext: Context { /// /// impl RootContext for MyRootContext { /// fn on_vm_start(&mut self, _vm_configuration_size: usize) -> bool { - /// let vm_confuguration = self.get_vm_configuration().unwrap(); + /// let vm_configuration = self.get_vm_configuration().unwrap(); /// - /// let parsed_vm_configuration: MyVmConfiguration = serde_json::from_slice::(&vm_confuguration).unwrap(); + /// let parsed_vm_configuration: MyVmConfiguration = serde_json::from_slice::(&vm_configuration).unwrap(); /// /// // Do something with the parsed vm configuration + /// debug!("vm_configuration: {:?}", parsed_vm_configuration) /// /// true /// } /// } + /// ``` fn on_vm_start(&mut self, _vm_configuration_size: usize) -> bool { true } @@ -385,6 +389,8 @@ pub trait RootContext: Context { /// /// struct MyRootContext; /// + /// #[derive(serde::Deserialize)] + /// #[derive(Debug)] /// struct MyVmConfiguration { /// /// Some key /// pub key: String, @@ -392,15 +398,17 @@ pub trait RootContext: Context { /// /// impl RootContext for MyRootContext { /// fn on_vm_start(&mut self, _vm_configuration_size: usize) -> bool { - /// let vm_confuguration = self.get_vm_configuration().unwrap(); + /// let vm_configuration = self.get_vm_configuration().unwrap(); /// - /// let parsed_vm_configuration: MyVmConfiguration = serde_json::from_slice::(&vm_confuguration).unwrap(); + /// let parsed_vm_configuration: MyVmConfiguration = serde_json::from_slice::(&vm_configuration).unwrap(); /// /// // Do something with the parsed vm configuration + /// debug!("vm_configuration: {:?}", parsed_vm_configuration) /// /// true /// } /// } + /// ``` fn get_vm_configuration(&self) -> Option { hostcalls::get_buffer(BufferType::VmConfiguration, 0, usize::MAX).unwrap() } @@ -423,6 +431,8 @@ pub trait RootContext: Context { /// /// struct MyRootContext; /// + /// #[derive(serde::Deserialize)] + /// #[derive(Debug)] /// struct MyPluginConfiguration { /// /// Some key /// pub key: String, @@ -439,6 +449,7 @@ pub trait RootContext: Context { /// true /// } /// } + /// ``` fn on_configure(&mut self, _plugin_configuration_size: usize) -> bool { true } @@ -456,9 +467,11 @@ pub trait RootContext: Context { /// /// struct MyRootContext; /// + /// #[derive(serde::Deserialize)] + /// #[derive(Debug)] /// struct MyPluginConfiguration { - /// /// Some key - /// pub key: String, + /// /// Some key + /// pub key: String, /// } /// /// impl RootContext for MyRootContext { @@ -472,6 +485,7 @@ pub trait RootContext: Context { /// true /// } /// } + /// ``` fn get_plugin_configuration(&self) -> Option { hostcalls::get_buffer(BufferType::PluginConfiguration, 0, usize::MAX).unwrap() } @@ -503,6 +517,7 @@ pub trait RootContext: Context { /// info!("tick!") /// } /// } + /// ``` fn set_tick_period(&self, period: Duration) { hostcalls::set_tick_period(period).unwrap() } @@ -532,6 +547,7 @@ pub trait RootContext: Context { /// info!("tick!") /// } /// } + /// ``` fn on_tick(&mut self) {} fn on_queue_ready(&mut self, _queue_id: u32) {} @@ -631,13 +647,16 @@ pub trait HttpContext: Context { /// ```rust /// use proxy_wasm::traits::*; /// use proxy_wasm::types::*; + /// use log::debug; /// - /// use log::info; + /// struct MyPlugin; /// /// impl HttpContext for MyPlugin { /// fn on_http_request_headers(&mut self, num_headers: usize, end_of_stream: bool) -> Action { /// let headers = self.get_http_request_headers(); /// + /// debug!("Received request headers: {:?}", headers); + /// /// // Process the request /// /// Action::Continue @@ -657,20 +676,24 @@ pub trait HttpContext: Context { /// # Example /// /// ```rust - /// use log::info; - /// use proxy_wasm::traits::HttpContext; + /// use proxy_wasm::traits::*; + /// use proxy_wasm::types::*; + /// use log::debug; + /// + /// struct MyPlugin; /// /// impl HttpContext for MyPlugin { - /// fn on_http_request_headers(&mut self, _num_headers: usize, _end_of_stream: bool) -> Action { + /// fn on_http_request_headers(&mut self, num_headers: usize, end_of_stream: bool) -> Action { /// let headers = self.get_http_request_headers(); /// - /// for (name, value) in headers { - /// info!("{}: {}", name, value); - /// } + /// debug!("Received request headers: {:?}", headers); + /// + /// // Process the request + /// /// Action::Continue - /// } + /// } /// } - /// + /// ``` fn get_http_request_headers(&self) -> Vec<(String, String)> { hostcalls::get_map(MapType::HttpRequestHeaders).unwrap() } @@ -700,21 +723,24 @@ pub trait HttpContext: Context { /// # Example /// /// ```rust - /// use log::info; + /// use log::debug; /// use proxy_wasm::traits:*; /// use proxy_wasm::types::Action; /// + /// struct MyPlugin; + /// /// impl HttpContext for MyPlugin { /// fn on_http_request_headers(&mut self, _num_headers: usize, _end_of_stream: bool) -> Action { /// let header = self.get_http_request_header(":path"); /// /// match header { - /// Some(value) => info!("The path is: {}", value), - /// None => info!("The path is missing") + /// Some(value) => debug!("The path is: {}", value), + /// None => debug!("The path is missing") /// } /// Action::Continue /// } /// } + /// ``` fn get_http_request_header(&self, name: &str) -> Option { hostcalls::get_map_value(MapType::HttpRequestHeaders, name).unwrap() } @@ -744,6 +770,8 @@ pub trait HttpContext: Context { /// use proxy_wasm::traits::*; /// use proxy_wasm::types::Action; /// + /// struct MyPlugin; + /// /// impl HttpContext for MyPlugin { /// fn on_http_request_headers(&mut self, _num_headers: usize, _end_of_stream: bool) -> Action { /// self.add_http_request_header("x-my-header", "my-value"); @@ -950,9 +978,11 @@ pub trait HttpContext: Context { /// use proxy_wasm::traits::*; /// use proxy_wasm::types::*; /// - /// impl HttpContext for MyHttpContext { + /// struct MyPlugin; + /// + /// impl HttpContext for MyPlugin { /// fn on_http_request_headers(&mut self, _num_headers: usize, _end_of_stream: bool) -> Action { - /// let auth = self.get_http_request_header("Authorization").unwrap_or_defauklt(); + /// let auth = self.get_http_request_header("Authorization").unwrap_or_default(); /// /// if auth == "I am authorized!" { /// // Send an HTTP response with a status code of 200 and a body of "Hello, World!" @@ -965,6 +995,7 @@ pub trait HttpContext: Context { /// Action::Pause /// } /// } + /// ``` fn send_http_response( &self, status_code: u32, From f190139e0942cdfaba669c76aa8aa00f308fcbcf Mon Sep 17 00:00:00 2001 From: Anton Engelhardt Date: Tue, 30 Apr 2024 17:22:10 +0200 Subject: [PATCH 04/14] update imports in docs & tiny fixes Signed-off-by: Anton Engelhardt --- src/traits.rs | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/src/traits.rs b/src/traits.rs index c7342f33..7c2d3c6d 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -82,7 +82,7 @@ pub trait Context { /// ```rust /// use proxy_wasm::traits::*; /// use proxy_wasm::types::*; - /// + /// use std::time::Duration; /// use log::warn; /// /// struct MyPlugin; @@ -99,7 +99,7 @@ pub trait Context { /// vec![], /// Duration::from_secs(5), /// ) { - /// Ok(_) => Action::Pause, + /// Ok(_) => Action::Continue, /// Err(e) => { /// warn!("Failed to dispatch_http_call: {:?}", e); /// Action::Pause @@ -150,7 +150,7 @@ pub trait Context { /// ```rust /// use proxy_wasm::traits::*; /// use proxy_wasm::types::*; - /// + /// use std::time::Duration; /// use log::{debug, warn}; /// /// struct MyPlugin; @@ -167,7 +167,7 @@ pub trait Context { /// vec![], /// Duration::from_secs(5), /// ) { - /// Ok(_) => Action::Pause, + /// Ok(_) => Action::Continue, /// Err(e) => { /// warn!("Failed to dispatch_http_call: {:?}", e); /// Action::Pause @@ -348,7 +348,10 @@ pub trait RootContext: Context { /// # Example /// /// ```rust - /// use proxy_wasm::traits::RootContext; + /// use proxy_wasm::traits::*; + /// use proxy_wasm::types::*; + /// use serde_json; + /// use log::debug; /// /// struct MyRootContext; /// @@ -385,7 +388,10 @@ pub trait RootContext: Context { /// # Example /// /// ```rust - /// use proxy_wasm::traits::RootContext; + /// use proxy_wasm::traits::*; + /// use proxy_wasm::types::*; + /// use serde_json; + /// use log::debug; /// /// struct MyRootContext; /// @@ -427,7 +433,10 @@ pub trait RootContext: Context { /// # Example /// /// ```rust - /// use proxy_wasm::traits::RootContext; + /// use proxy_wasm::traits::*; + /// use proxy_wasm::types::*; + /// use serde_json; + /// use log::debug; /// /// struct MyRootContext; /// @@ -445,6 +454,7 @@ pub trait RootContext: Context { /// let parsed_plugin_configuration: MyPluginConfiguration = serde_json::from_slice::(&plugin_configuration).unwrap(); /// /// // Do something with the parsed plugin configuration + /// debug!("plugin_configuration: {:?}", parsed_plugin_configuration) /// /// true /// } @@ -463,7 +473,10 @@ pub trait RootContext: Context { /// # Example /// /// ```rust - /// use proxy_wasm::traits::RootContext; + /// use proxy_wasm::traits::*; + /// use proxy_wasm::types::*; + /// use serde_json; + /// use log::debug; /// /// struct MyRootContext; /// @@ -481,6 +494,7 @@ pub trait RootContext: Context { /// let parsed_plugin_configuration: MyPluginConfiguration = serde_json::from_slice::(&plugin_configuration).unwrap(); /// /// // Do something with the parsed plugin configuration + /// debug!("plugin_configuration: {:?}", parsed_plugin_configuration) /// /// true /// } @@ -499,7 +513,8 @@ pub trait RootContext: Context { /// # Example /// /// ```rust - /// use proxy_wasm::traits::RootContext; + /// use proxy_wasm::traits::*; + /// use proxy_wasm::types::*; /// use std::time::Duration; /// use log::info; /// @@ -529,7 +544,8 @@ pub trait RootContext: Context { /// # Example /// /// ```rust - /// use proxy_wasm::traits::RootContext; + /// use proxy_wasm::traits::*; + /// use proxy_wasm::types::*; /// use std::time::Duration; /// use log::info; /// @@ -723,9 +739,9 @@ pub trait HttpContext: Context { /// # Example /// /// ```rust - /// use log::debug; /// use proxy_wasm::traits:*; - /// use proxy_wasm::types::Action; + /// use proxy_wasm::types::*; + /// use log::debug; /// /// struct MyPlugin; /// @@ -768,7 +784,7 @@ pub trait HttpContext: Context { /// /// ```rust /// use proxy_wasm::traits::*; - /// use proxy_wasm::types::Action; + /// use proxy_wasm::types::*; /// /// struct MyPlugin; /// From c11460b1de51f8441d889a588b8bf1cb66b42c6c Mon Sep 17 00:00:00 2001 From: Anton Engelhardt Date: Tue, 30 Apr 2024 17:35:16 +0200 Subject: [PATCH 05/14] simplify serde annotations Signed-off-by: Anton Engelhardt --- src/traits.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/traits.rs b/src/traits.rs index 7c2d3c6d..3799b2e1 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -355,8 +355,7 @@ pub trait RootContext: Context { /// /// struct MyRootContext; /// - /// #[derive(serde::Deserialize)] - /// #[derive(Debug)] + /// #[derive(serde::Deserialize, Debug)] /// struct MyVmConfiguration { /// /// Some key /// pub key: String, @@ -395,8 +394,7 @@ pub trait RootContext: Context { /// /// struct MyRootContext; /// - /// #[derive(serde::Deserialize)] - /// #[derive(Debug)] + /// #[derive(serde::Deserialize, Debug)] /// struct MyVmConfiguration { /// /// Some key /// pub key: String, @@ -440,8 +438,7 @@ pub trait RootContext: Context { /// /// struct MyRootContext; /// - /// #[derive(serde::Deserialize)] - /// #[derive(Debug)] + /// #[derive(serde::Deserialize, Debug)] /// struct MyPluginConfiguration { /// /// Some key /// pub key: String, @@ -480,8 +477,7 @@ pub trait RootContext: Context { /// /// struct MyRootContext; /// - /// #[derive(serde::Deserialize)] - /// #[derive(Debug)] + /// #[derive(serde::Deserialize, Debug)] /// struct MyPluginConfiguration { /// /// Some key /// pub key: String, From 3c5b187f280d0e162841b0bdd80dcd8cdb2b7842 Mon Sep 17 00:00:00 2001 From: Anton Engelhardt Date: Tue, 13 Aug 2024 09:10:34 +0200 Subject: [PATCH 06/14] fix(docs): google cluster name should match example Signed-off-by: Anton Engelhardt --- src/traits.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/traits.rs b/src/traits.rs index deef35de..5ed57018 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -90,7 +90,7 @@ pub trait Context { /// impl HttpContext for MyPlugin { /// fn on_http_request_headers(&mut self, _num_headers: usize, _end_of_stream: bool) -> Action { /// match self.dispatch_http_call( - /// "cluster_name_from_envoy_config", + /// "google", /// vec![ /// (":method", "GET"), /// (":path", "/"), From 41c011946107bbff8f5a72982b11ea24695ab767 Mon Sep 17 00:00:00 2001 From: Anton Engelhardt Date: Tue, 13 Aug 2024 09:11:10 +0200 Subject: [PATCH 07/14] fix(docs): format serde plugin config and remove import Signed-off-by: Anton Engelhardt --- src/traits.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/traits.rs b/src/traits.rs index 5ed57018..0f522b8b 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -350,7 +350,6 @@ pub trait RootContext: Context { /// ```rust /// use proxy_wasm::traits::*; /// use proxy_wasm::types::*; - /// use serde_json; /// use log::debug; /// /// struct MyRootContext; @@ -365,7 +364,8 @@ pub trait RootContext: Context { /// fn on_vm_start(&mut self, _vm_configuration_size: usize) -> bool { /// let vm_configuration = self.get_vm_configuration().unwrap(); /// - /// let parsed_vm_configuration: MyVmConfiguration = serde_json::from_slice::(&vm_configuration).unwrap(); + /// let parsed_vm_configuration: MyVmConfiguration = + /// serde_json::from_slice::(&vm_configuration).unwrap(); /// /// // Do something with the parsed vm configuration /// debug!("vm_configuration: {:?}", parsed_vm_configuration) @@ -389,7 +389,6 @@ pub trait RootContext: Context { /// ```rust /// use proxy_wasm::traits::*; /// use proxy_wasm::types::*; - /// use serde_json; /// use log::debug; /// /// struct MyRootContext; @@ -404,7 +403,8 @@ pub trait RootContext: Context { /// fn on_vm_start(&mut self, _vm_configuration_size: usize) -> bool { /// let vm_configuration = self.get_vm_configuration().unwrap(); /// - /// let parsed_vm_configuration: MyVmConfiguration = serde_json::from_slice::(&vm_configuration).unwrap(); + /// let parsed_vm_configuration: MyVmConfiguration = + /// serde_json::from_slice::(&vm_configuration).unwrap(); /// /// // Do something with the parsed vm configuration /// debug!("vm_configuration: {:?}", parsed_vm_configuration) @@ -433,7 +433,6 @@ pub trait RootContext: Context { /// ```rust /// use proxy_wasm::traits::*; /// use proxy_wasm::types::*; - /// use serde_json; /// use log::debug; /// /// struct MyRootContext; @@ -448,7 +447,8 @@ pub trait RootContext: Context { /// fn on_configure(&mut self, _plugin_configuration_size: usize) -> bool { /// let plugin_configuration = self.get_plugin_configuration().unwrap(); /// - /// let parsed_plugin_configuration: MyPluginConfiguration = serde_json::from_slice::(&plugin_configuration).unwrap(); + /// let parsed_plugin_configuration: MyPluginConfiguration = + /// serde_json::from_slice::(&plugin_configuration).unwrap(); /// /// // Do something with the parsed plugin configuration /// debug!("plugin_configuration: {:?}", parsed_plugin_configuration) @@ -472,7 +472,6 @@ pub trait RootContext: Context { /// ```rust /// use proxy_wasm::traits::*; /// use proxy_wasm::types::*; - /// use serde_json; /// use log::debug; /// /// struct MyRootContext; @@ -487,7 +486,8 @@ pub trait RootContext: Context { /// fn on_configure(&mut self, _plugin_configuration_size: usize) -> bool { /// let plugin_configuration = self.get_plugin_configuration().unwrap(); /// - /// let parsed_plugin_configuration: MyPluginConfiguration = serde_json::from_slice::(&plugin_configuration).unwrap(); + /// let parsed_plugin_configuration: MyPluginConfiguration = + /// serde_json::from_slice::(&plugin_configuration).unwrap(); /// /// // Do something with the parsed plugin configuration /// debug!("plugin_configuration: {:?}", parsed_plugin_configuration) From 0df70c890bf2870b5f48c7b9284288477b61ffba Mon Sep 17 00:00:00 2001 From: Anton Engelhardt Date: Tue, 13 Aug 2024 17:46:37 +0200 Subject: [PATCH 08/14] fix(docs): log import Signed-off-by: Anton Engelhardt --- src/traits.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/traits.rs b/src/traits.rs index 0f522b8b..4ed2cf6a 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -83,7 +83,7 @@ pub trait Context { /// use proxy_wasm::traits::*; /// use proxy_wasm::types::*; /// use std::time::Duration; - /// use log::warn; + /// use log::{debug, warn}; /// /// struct MyPlugin; /// @@ -113,7 +113,7 @@ pub trait Context { /// let headers = self.get_http_call_response_headers(); /// let body = self.get_http_call_response_body(0, body_size); /// - /// info!("Received response headers: {:?}", headers); + /// debug!("Received response headers: {:?}", headers); /// /// // Do something with the response /// } From 9eaac20ee2a24d3fb4ebaae80e4499b5b52c0639 Mon Sep 17 00:00:00 2001 From: Anton Engelhardt Date: Sun, 13 Oct 2024 20:09:06 +0200 Subject: [PATCH 09/14] fix(docs): refine docs Signed-off-by: Anton Engelhardt --- src/traits.rs | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/traits.rs b/src/traits.rs index 4ed2cf6a..eee3037e 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -72,10 +72,7 @@ pub trait Context { /// /// # Returns /// - /// * `OK` on success. - /// * `BAD_ARGUMENT` for unknown upstream, or when headers are missing required `:authority`, `:method` and/or `:path` values. - /// * `INTERNAL_FAILURE' when the host failed to send requested HTTP call. - /// * `INVALID_MEMORY_ACCESS` when `upstream_data`, `upstream_size`, `headers_data`, `headers_size`, `body_data`, `body_size`, `trailers_data`, `trailers_size` and/or `return_call_id` point to invalid memory address. + /// A Result containing the token id of the request, or an error status. /// /// # Example /// @@ -130,13 +127,13 @@ pub trait Context { hostcalls::dispatch_http_call(upstream, headers, body, trailers, timeout) } - /// Called when HTTP response for call_id sent using proxy_http_call is received. + /// Called when HTTP response using `dispatch_http_call` is received. /// /// If `num_headers` is 0, then the HTTP call failed. /// - /// All `num_headers` headers can be retrieved using `self.get_http_response_headers()` or individually `self.get_http_response_header()`. + /// All headers can be retrieved using `self.get_http_response_headers()` or individually `self.get_http_response_header(name)`. /// - /// All `num_trailers` trailers can be retrieved using `self.get_http_response_trailers()` or individually `self.get_http_response_trailer()`. + /// All trailers can be retrieved using `self.get_http_response_trailers()` or individually `self.get_http_response_trailer(name)`. /// /// # Arguments /// @@ -640,7 +637,7 @@ pub trait HttpContext: Context { /// /// Paused request can be resumed using `self.resume_http_request()` or closed using `self.reset_http_request()`. /// - /// Additionally, instead of forwarding request upstream, a HTTP response can be sent using `self.send_http_response()`. + /// Additionally, instead of forwarding requests upstream, a HTTP response can be sent using `self.send_http_response()`. /// /// # Arguments /// @@ -722,7 +719,7 @@ pub trait HttpContext: Context { hostcalls::set_map_bytes(MapType::HttpRequestHeaders, headers).unwrap() } - /// Get a specific HTTP request header. + /// Get a specific HTTP request header by name. /// /// # Arguments /// @@ -973,9 +970,9 @@ pub trait HttpContext: Context { hostcalls::reset_http_response().unwrap() } - /// Sends an HTTP response with the body and serialized headers. + /// Sends an HTTP response with the specified status code, headers, and body. /// - /// This can be used as long as HTTP response headers were not sent downstream. + /// This can be used as long as HTTP response headers were not sent downstream yet. /// /// # Arguments /// @@ -1000,7 +997,7 @@ pub trait HttpContext: Context { /// // Send an HTTP response with a status code of 200 and a body of "Hello, World!" /// self.send_http_response(200, vec![("A header", "Some Value")], Some(b"Hello, World!")); /// } else { - /// // Send an HTTP response with a status code of 403 and a body of "Forbidden" + /// // Send an HTTP response with a status code of 307, redirecting to authenticate-here.com, and a body of "Forbidden" /// self.send_http_response(307, vec![("location", "https://authenticate-here.com")], Some(b"Forbidden")); /// } /// From 4f36bf1435076d37de8580c4d9587e961406336f Mon Sep 17 00:00:00 2001 From: Anton Engelhardt Date: Sun, 13 Oct 2024 21:19:19 +0200 Subject: [PATCH 10/14] fix(docs): make doc tests compilable with `cargo test --doc` Signed-off-by: Anton Engelhardt --- Cargo.toml | 4 ++++ src/traits.rs | 36 +++++++++++++++++++++++++++++------- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c59d968c..fee263bd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,10 @@ build = "build.rs" hashbrown = "0.14" log = "0.4" +[dev-dependencies] +serde = { version = "1.0.210", features = ["derive"] } +serde_json = "1.0.128" + [profile.release] lto = true opt-level = 3 diff --git a/src/traits.rs b/src/traits.rs index eee3037e..a8cb1fd9 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -131,9 +131,9 @@ pub trait Context { /// /// If `num_headers` is 0, then the HTTP call failed. /// - /// All headers can be retrieved using `self.get_http_response_headers()` or individually `self.get_http_response_header(name)`. + /// All headers can be retrieved using `self.get_http_call_response_headers()` or individually `self.get_http_call_response_header(name)`. /// - /// All trailers can be retrieved using `self.get_http_response_trailers()` or individually `self.get_http_response_trailer(name)`. + /// All trailers can be retrieved using `self.get_http_call_response_trailers()` or individually `self.get_http_call_response_trailer(name)`. /// /// # Arguments /// @@ -365,11 +365,13 @@ pub trait RootContext: Context { /// serde_json::from_slice::(&vm_configuration).unwrap(); /// /// // Do something with the parsed vm configuration - /// debug!("vm_configuration: {:?}", parsed_vm_configuration) + /// debug!("vm_configuration: {:?}", parsed_vm_configuration); /// /// true /// } /// } + /// + /// # impl Context for MyRootContext {} /// ``` fn on_vm_start(&mut self, _vm_configuration_size: usize) -> bool { true @@ -404,11 +406,13 @@ pub trait RootContext: Context { /// serde_json::from_slice::(&vm_configuration).unwrap(); /// /// // Do something with the parsed vm configuration - /// debug!("vm_configuration: {:?}", parsed_vm_configuration) + /// debug!("vm_configuration: {:?}", parsed_vm_configuration); /// /// true /// } /// } + /// + /// # impl Context for MyRootContext {} /// ``` fn get_vm_configuration(&self) -> Option { hostcalls::get_buffer(BufferType::VmConfiguration, 0, usize::MAX).unwrap() @@ -448,11 +452,13 @@ pub trait RootContext: Context { /// serde_json::from_slice::(&plugin_configuration).unwrap(); /// /// // Do something with the parsed plugin configuration - /// debug!("plugin_configuration: {:?}", parsed_plugin_configuration) + /// debug!("plugin_configuration: {:?}", parsed_plugin_configuration); /// /// true /// } /// } + /// + /// # impl Context for MyRootContext {} /// ``` fn on_configure(&mut self, _plugin_configuration_size: usize) -> bool { true @@ -487,11 +493,13 @@ pub trait RootContext: Context { /// serde_json::from_slice::(&plugin_configuration).unwrap(); /// /// // Do something with the parsed plugin configuration - /// debug!("plugin_configuration: {:?}", parsed_plugin_configuration) + /// debug!("plugin_configuration: {:?}", parsed_plugin_configuration); /// /// true /// } /// } + /// + /// # impl Context for MyRootContext {} /// ``` fn get_plugin_configuration(&self) -> Option { hostcalls::get_buffer(BufferType::PluginConfiguration, 0, usize::MAX).unwrap() @@ -525,6 +533,8 @@ pub trait RootContext: Context { /// info!("tick!") /// } /// } + /// + /// # impl Context for MyRootContext {} /// ``` fn set_tick_period(&self, period: Duration) { hostcalls::set_tick_period(period).unwrap() @@ -556,6 +566,8 @@ pub trait RootContext: Context { /// info!("tick!") /// } /// } + /// + /// # impl Context for MyRootContext {} /// ``` fn on_tick(&mut self) {} @@ -671,6 +683,8 @@ pub trait HttpContext: Context { /// Action::Continue /// } /// } + /// + /// # impl Context for MyPlugin {} /// ``` fn on_http_request_headers(&mut self, _num_headers: usize, _end_of_stream: bool) -> Action { Action::Continue @@ -702,6 +716,8 @@ pub trait HttpContext: Context { /// Action::Continue /// } /// } + /// + /// # impl Context for MyPlugin {} /// ``` fn get_http_request_headers(&self) -> Vec<(String, String)> { hostcalls::get_map(MapType::HttpRequestHeaders).unwrap() @@ -732,7 +748,7 @@ pub trait HttpContext: Context { /// # Example /// /// ```rust - /// use proxy_wasm::traits:*; + /// use proxy_wasm::traits::*; /// use proxy_wasm::types::*; /// use log::debug; /// @@ -749,6 +765,8 @@ pub trait HttpContext: Context { /// Action::Continue /// } /// } + /// + /// # impl Context for MyPlugin {} /// ``` fn get_http_request_header(&self, name: &str) -> Option { hostcalls::get_map_value(MapType::HttpRequestHeaders, name).unwrap() @@ -788,6 +806,8 @@ pub trait HttpContext: Context { /// Action::Continue /// } /// } + /// + /// # impl Context for MyPlugin {} /// ``` fn add_http_request_header(&self, name: &str, value: &str) { hostcalls::add_map_value(MapType::HttpRequestHeaders, name, value).unwrap() @@ -1004,6 +1024,8 @@ pub trait HttpContext: Context { /// Action::Pause /// } /// } + /// + /// # impl Context for MyPlugin {} /// ``` fn send_http_response( &self, From 3b0cf7e9496d40fffd08be874c811e394ab3cc80 Mon Sep 17 00:00:00 2001 From: Anton Engelhardt Date: Sun, 13 Oct 2024 21:19:51 +0200 Subject: [PATCH 11/14] fix(docs): add doc test ci Signed-off-by: Anton Engelhardt --- .github/workflows/rust.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 11de901a..fe394c7b 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -134,6 +134,9 @@ jobs: - name: Package (docs) run: cargo doc --no-deps --target=wasm32-unknown-unknown + - name: Test (docs) + run: cargo test --doc + - name: Package (publish) run: cargo publish --dry-run --target=wasm32-unknown-unknown @@ -182,6 +185,9 @@ jobs: - name: Package (docs) run: cargo doc --no-deps --target=wasm32-unknown-unknown + - name: Test (docs) + run: cargo test --doc + - name: Package (publish) run: cargo publish --dry-run --target=wasm32-unknown-unknown @@ -231,6 +237,9 @@ jobs: - name: Package (docs) run: cargo doc --no-deps --target=wasm32-unknown-unknown + - name: Test (docs) + run: cargo test --doc + - name: Package (publish) run: cargo publish --dry-run --target=wasm32-unknown-unknown From bf220864f56ad08cb5d32df87963d0313f0e7e9a Mon Sep 17 00:00:00 2001 From: Anton Engelhardt Date: Wed, 23 Oct 2024 10:28:28 +0200 Subject: [PATCH 12/14] docs: documentation for more functions and smaller changes Signed-off-by: Anton Engelhardt --- src/traits.rs | 537 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 531 insertions(+), 6 deletions(-) diff --git a/src/traits.rs b/src/traits.rs index a8cb1fd9..02567b5a 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -96,7 +96,7 @@ pub trait Context { /// vec![], /// Duration::from_secs(5), /// ) { - /// Ok(_) => Action::Continue, + /// Ok(_) => Action::Pause, /// Err(e) => { /// warn!("Failed to dispatch_http_call: {:?}", e); /// Action::Pause @@ -108,11 +108,14 @@ pub trait Context { /// impl Context for MyPlugin { /// fn on_http_call_response(&mut self, _token_id: u32, _: usize, body_size: usize, _: usize) { /// let headers = self.get_http_call_response_headers(); - /// let body = self.get_http_call_response_body(0, body_size); + /// let body = self.get_http_call_response_body(0, body_size).unwrap(); + /// let body_str = String::from_utf8(body).unwrap(); /// /// debug!("Received response headers: {:?}", headers); + /// debug!("Received response body: {:?}", body_str); /// - /// // Do something with the response + /// // Resume the HTTP request after processing the response + /// self.resume_http_request(); /// } /// } /// ``` @@ -164,7 +167,7 @@ pub trait Context { /// vec![], /// Duration::from_secs(5), /// ) { - /// Ok(_) => Action::Continue, + /// Ok(_) => Action::Pause, /// Err(e) => { /// warn!("Failed to dispatch_http_call: {:?}", e); /// Action::Pause @@ -176,11 +179,14 @@ pub trait Context { /// impl Context for MyPlugin { /// fn on_http_call_response(&mut self, _token_id: u32, _: usize, body_size: usize, _: usize) { /// let headers = self.get_http_call_response_headers(); - /// let body = self.get_http_call_response_body(0, body_size); + /// let body = self.get_http_call_response_body(0, body_size).unwrap(); + /// let body_str = String::from_utf8(body).unwrap(); /// /// debug!("Received response headers: {:?}", headers); + /// debug!("Received response body: {:?}", body_str); /// - /// // Do something with the response + /// // Resume the HTTP request after processing the response + /// self.resume_http_request(); /// } /// } /// ``` @@ -193,38 +199,494 @@ pub trait Context { ) { } + /// Get the HTTP call response headers. + /// + /// # Returns + /// + /// * `Vec<(String, String)>` - the HTTP call response headers + /// + /// # Example + /// + /// ```rust + /// use proxy_wasm::traits::*; + /// use proxy_wasm::types::*; + /// use std::time::Duration; + /// use log::{debug, warn}; + /// + /// struct MyPlugin; + /// + /// impl HttpContext for MyPlugin { + /// fn on_http_request_headers(&mut self, _num_headers: usize, _end_of_stream: bool) -> Action { + /// match self.dispatch_http_call( + /// "google", + /// vec![ + /// (":method", "GET"), + /// (":path", "/"), + /// (":authority", "google.com")], + /// None, + /// vec![], + /// Duration::from_secs(5), + /// ) { + /// Ok(_) => Action::Pause, + /// Err(e) => { + /// warn!("Failed to dispatch_http_call: {:?}", e); + /// Action::Pause + /// } + /// } + /// } + /// } + /// + /// impl Context for MyPlugin { + /// fn on_http_call_response(&mut self, _token_id: u32, _: usize, body_size: usize, _: usize) { + /// let headers = self.get_http_call_response_headers(); + /// + /// debug!("Received response headers: {:?}", headers); + /// + /// // Resume the HTTP request after processing the response + /// self.resume_http_request(); + /// } + /// } + /// ``` fn get_http_call_response_headers(&self) -> Vec<(String, String)> { hostcalls::get_map(MapType::HttpCallResponseHeaders).unwrap() } + /// Get all HTTP call response headers as bytes. + /// + /// # Returns + /// + /// * `Vec<(String, Bytes)>` - a list of HTTP call response headers + /// + /// # Example + /// + /// ```rust + /// use proxy_wasm::traits::*; + /// use proxy_wasm::types::*; + /// use std::time::Duration; + /// use log::{debug, warn}; + /// + /// struct MyPlugin; + /// + /// impl HttpContext for MyPlugin { + /// fn on_http_request_headers(&mut self, _num_headers: usize, _end_of_stream: bool) -> Action { + /// match self.dispatch_http_call( + /// "google", + /// vec![ + /// (":method", "GET"), + /// (":path", "/"), + /// (":authority", "google.com")], + /// None, + /// vec![], + /// Duration::from_secs(5), + /// ) { + /// Ok(_) => Action::Pause, + /// Err(e) => { + /// warn!("Failed to dispatch_http_call: {:?}", e); + /// Action::Pause + /// } + /// } + /// } + /// } + /// + /// impl Context for MyPlugin { + /// fn on_http_call_response(&mut self, _token_id: u32, _: usize, body_size: usize, _: usize) { + /// let headers = self.get_http_call_response_headers_bytes(); + /// + /// for (name, value) in headers { + /// let value_str = String::from_utf8(value).unwrap(); + /// debug!("Received response header: {:?} = {:?}", name, value_str); + /// + /// // Resume the HTTP call after processing the response + /// self.resume_http_request(); + /// } + /// } + /// } + /// ``` fn get_http_call_response_headers_bytes(&self) -> Vec<(String, Bytes)> { hostcalls::get_map_bytes(MapType::HttpCallResponseHeaders).unwrap() } + /// Get a HTTP call response header by name. + /// + /// # Arguments + /// + /// * `name` - the name of the header + /// + /// # Returns + /// + /// * `Option` - the HTTP call response header or `None` if the header is not found + /// + /// # Example + /// + /// ```rust + /// use proxy_wasm::traits::*; + /// use proxy_wasm::types::*; + /// use std::time::Duration; + /// use log::{debug, warn}; + /// + /// struct MyPlugin; + /// + /// impl HttpContext for MyPlugin { + /// fn on_http_request_headers(&mut self, _num_headers: usize, _end_of_stream: bool) -> Action { + /// match self.dispatch_http_call( + /// "google", + /// vec![ + /// (":method", "GET"), + /// (":path", "/"), + /// (":authority", "google.com")], + /// None, + /// vec![], + /// Duration::from_secs(5), + /// ) { + /// Ok(_) => Action::Pause, + /// Err(e) => { + /// warn!("Failed to dispatch_http_call: {:?}", e); + /// Action::Pause + /// } + /// } + /// } + /// } + /// + /// impl Context for MyPlugin { + /// fn on_http_call_response(&mut self, _token_id: u32, _: usize, body_size: usize, _: usize) { + /// let header = self.get_http_call_response_header("content-type"); + /// debug!("Received response header: {:?}", header); + /// + /// // Resume the HTTP request after processing the response + /// self.resume_http_request(); + /// } + /// } + /// ``` fn get_http_call_response_header(&self, name: &str) -> Option { hostcalls::get_map_value(MapType::HttpCallResponseHeaders, name).unwrap() } + /// Get a HTTP call response header by name as bytes. + /// + /// # Arguments + /// + /// * `name` - the name of the header + /// + /// # Returns + /// + /// * `Option` - the HTTP call response header or `None` if the header is not found + /// + /// # Example + /// + /// ```rust + /// use proxy_wasm::traits::*; + /// use proxy_wasm::types::*; + /// use std::time::Duration; + /// use log::{debug, warn}; + /// + /// struct MyPlugin; + /// + /// impl HttpContext for MyPlugin { + /// fn on_http_request_headers(&mut self, _num_headers: usize, _end_of_stream: bool) -> Action { + /// match self.dispatch_http_call( + /// "google", + /// vec![ + /// (":method", "GET"), + /// (":path", "/"), + /// (":authority", "google.com")], + /// None, + /// vec![], + /// Duration::from_secs(5), + /// ) { + /// Ok(_) => Action::Pause, + /// Err(e) => { + /// warn!("Failed to dispatch_http_call: {:?}", e); + /// Action::Pause + /// } + /// } + /// } + /// } + /// + /// impl Context for MyPlugin { + /// fn on_http_call_response(&mut self, _token_id: u32, _: usize, body_size: usize, _: usize) { + /// let header = self.get_http_call_response_header_bytes("content-type").unwrap(); + /// let header_str = String::from_utf8(header).unwrap(); + /// debug!("Received response header: {:?}", header_str); + /// + /// // Resume the HTTP request after processing the response + /// self.resume_http_request(); + /// } + /// } + /// ``` fn get_http_call_response_header_bytes(&self, name: &str) -> Option { hostcalls::get_map_value_bytes(MapType::HttpCallResponseHeaders, name).unwrap() } + /// Get the HTTP call response body. + /// + /// # Arguments + /// + /// * `start` - the start offset of the body + /// * `max_size` - the maximum size of the body + /// + /// # Returns + /// + /// * `Option` - the HTTP call response body or `None` if the body is not found + /// + /// # Example + /// + /// ```rust + /// use proxy_wasm::traits::*; + /// use proxy_wasm::types::*; + /// use std::time::Duration; + /// use log::{debug, warn}; + /// + /// struct MyPlugin; + /// + /// impl HttpContext for MyPlugin { + /// fn on_http_request_headers(&mut self, _num_headers: usize, _end_of_stream: bool) -> Action { + /// match self.dispatch_http_call( + /// "google", + /// vec![ + /// (":method", "GET"), + /// (":path", "/"), + /// (":authority", "google.com")], + /// None, + /// vec![], + /// Duration::from_secs(5), + /// ) { + /// Ok(_) => Action::Pause, + /// Err(e) => { + /// warn!("Failed to dispatch_http_call: {:?}", e); + /// Action::Pause + /// } + /// } + /// } + /// } + /// + /// impl Context for MyPlugin { + /// fn on_http_call_response(&mut self, _token_id: u32, _: usize, body_size: usize, _: usize) { + /// let body = self.get_http_call_response_body(0, body_size).unwrap(); + /// let body_str = String::from_utf8(body).unwrap(); + /// + /// debug!("Received response body: {:?}", body_str); + /// + /// // Resume the HTTP request after processing the response + /// self.resume_http_request(); + /// } + /// } + /// ``` fn get_http_call_response_body(&self, start: usize, max_size: usize) -> Option { hostcalls::get_buffer(BufferType::HttpCallResponseBody, start, max_size).unwrap() } + /// Get the HTTP call response trailers. + /// + /// # Returns + /// + /// * `Vec<(String, String)>` - the HTTP call response trailers + /// + /// # Example + /// + /// ```rust + /// use proxy_wasm::traits::*; + /// use proxy_wasm::types::*; + /// use std::time::Duration; + /// use log::{debug, warn}; + /// + /// struct MyPlugin; + /// + /// impl HttpContext for MyPlugin { + /// fn on_http_request_headers(&mut self, _num_headers: usize, _end_of_stream: bool) -> Action { + /// match self.dispatch_http_call( + /// "google", + /// vec![ + /// (":method", "GET"), + /// (":path", "/"), + /// (":authority", "google.com")], + /// None, + /// vec![], + /// Duration::from_secs(5), + /// ) { + /// Ok(_) => Action::Pause, + /// Err(e) => { + /// warn!("Failed to dispatch_http_call: {:?}", e); + /// Action::Pause + /// } + /// } + /// } + /// } + /// + /// impl Context for MyPlugin { + /// fn on_http_call_response(&mut self, _token_id: u32, _: usize, body_size: usize, _: usize) { + /// let trailers = self.get_http_call_response_trailers(); + /// debug!("Received response trailers: {:?}", trailers); + /// + /// // Resume the HTTP call after processing the response + /// self.resume_http_request(); + /// } + /// } + /// ``` fn get_http_call_response_trailers(&self) -> Vec<(String, String)> { hostcalls::get_map(MapType::HttpCallResponseTrailers).unwrap() } + /// Get the HTTP call response trailers as bytes. + /// + /// # Returns + /// + /// * `Vec<(String, Bytes)>` - the HTTP call response trailers + /// + /// /// # Example + /// + /// ```rust + /// use proxy_wasm::traits::*; + /// use proxy_wasm::types::*; + /// use std::time::Duration; + /// use log::{debug, warn}; + /// + /// struct MyPlugin; + /// + /// impl HttpContext for MyPlugin { + /// fn on_http_request_headers(&mut self, _num_headers: usize, _end_of_stream: bool) -> Action { + /// match self.dispatch_http_call( + /// "google", + /// vec![ + /// (":method", "GET"), + /// (":path", "/"), + /// (":authority", "google.com")], + /// None, + /// vec![], + /// Duration::from_secs(5), + /// ) { + /// Ok(_) => Action::Pause, + /// Err(e) => { + /// warn!("Failed to dispatch_http_call: {:?}", e); + /// Action::Pause + /// } + /// } + /// } + /// } + /// + /// impl Context for MyPlugin { + /// fn on_http_call_response(&mut self, _token_id: u32, _: usize, body_size: usize, _: usize) { + /// let trailers = self.get_http_call_response_trailers_bytes(); + /// for (name, value) in trailers { + /// let value_str = String::from_utf8(value).unwrap(); + /// debug!("Received response trailer: {:?}", (name, value_str)); + /// + /// // Resume the HTTP call after processing the response + /// self.resume_http_request(); + /// } + /// } + /// } + /// ``` fn get_http_call_response_trailers_bytes(&self) -> Vec<(String, Bytes)> { hostcalls::get_map_bytes(MapType::HttpCallResponseTrailers).unwrap() } + /// Get a HTTP call response trailer by name. + /// + /// # Arguments + /// + /// * `name` - the name of the trailer + /// + /// # Returns + /// + /// * `Option` - the HTTP call response trailer or `None` if the trailer is not found + /// + /// /// # Example + /// + /// ```rust + /// use proxy_wasm::traits::*; + /// use proxy_wasm::types::*; + /// use std::time::Duration; + /// use log::{debug, warn}; + /// + /// struct MyPlugin; + /// + /// impl HttpContext for MyPlugin { + /// fn on_http_request_headers(&mut self, _num_headers: usize, _end_of_stream: bool) -> Action { + /// match self.dispatch_http_call( + /// "google", + /// vec![ + /// (":method", "GET"), + /// (":path", "/"), + /// (":authority", "google.com")], + /// None, + /// vec![], + /// Duration::from_secs(5), + /// ) { + /// Ok(_) => Action::Pause, + /// Err(e) => { + /// warn!("Failed to dispatch_http_call: {:?}", e); + /// Action::Pause + /// } + /// } + /// } + /// } + /// + /// impl Context for MyPlugin { + /// fn on_http_call_response(&mut self, _token_id: u32, _: usize, body_size: usize, _: usize) { + /// let trailer = self.get_http_call_response_trailer("content-type").unwrap(); + /// debug!("Received response trailer: {:?}", trailer); + /// + /// // Resume the HTTP call after processing the response + /// self.resume_http_request(); + /// } + /// } + /// ``` fn get_http_call_response_trailer(&self, name: &str) -> Option { hostcalls::get_map_value(MapType::HttpCallResponseTrailers, name).unwrap() } + /// Get a HTTP call response trailer by name as bytes. + /// + /// # Arguments + /// + /// * `name` - the name of the trailer + /// + /// # Returns + /// + /// * `Option` - the HTTP call response trailer or `None` if the trailer is not found + /// + /// # Example + /// + /// ```rust + /// use proxy_wasm::traits::*; + /// use proxy_wasm::types::*; + /// use std::time::Duration; + /// use log::{debug, warn}; + /// + /// struct MyPlugin; + /// + /// impl HttpContext for MyPlugin { + /// fn on_http_request_headers(&mut self, _num_headers: usize, _end_of_stream: bool) -> Action { + /// match self.dispatch_http_call( + /// "google", + /// vec![ + /// (":method", "GET"), + /// (":path", "/"), + /// (":authority", "google.com")], + /// None, + /// vec![], + /// Duration::from_secs(5), + /// ) { + /// Ok(_) => Action::Pause, + /// Err(e) => { + /// warn!("Failed to dispatch_http_call: {:?}", e); + /// Action::Pause + /// } + /// } + /// } + /// } + /// + /// impl Context for MyPlugin { + /// fn on_http_call_response(&mut self, _token_id: u32, _: usize, body_size: usize, _: usize) { + /// let trailer = self.get_http_call_response_trailer_bytes("content-type").unwrap(); + /// let trailer_str = String::from_utf8(trailer).unwrap(); + /// debug!("Received response trailer: {:?}", trailer_str); + /// + /// // Resume the HTTP call after processing the response + /// self.resume_http_request(); + /// } + /// } + /// ``` fn get_http_call_response_trailer_bytes(&self, name: &str) -> Option { hostcalls::get_map_value_bytes(MapType::HttpCallResponseTrailers, name).unwrap() } @@ -723,6 +1185,38 @@ pub trait HttpContext: Context { hostcalls::get_map(MapType::HttpRequestHeaders).unwrap() } + /// Get all HTTP request headers as bytes. + /// + /// # Returns + /// + /// * `Vec<(String, Bytes)>` - a list of HTTP request headers + /// + /// # Example + /// + /// ```rust + /// use proxy_wasm::traits::*; + /// use proxy_wasm::types::*; + /// use log::debug; + /// + /// struct MyPlugin; + /// + /// impl HttpContext for MyPlugin { + /// fn on_http_request_headers(&mut self, num_headers: usize, end_of_stream: bool) -> Action { + /// let headers = self.get_http_request_headers_bytes(); + /// + /// for (name, value) in headers { + /// let value_str = String::from_utf8(value).unwrap(); + /// debug!("Received request header: {:?} = {:?}", name, value_str); + /// } + /// + /// // Process the request + /// + /// Action::Continue + /// } + /// } + /// + /// # impl Context for MyPlugin {} + /// ``` fn get_http_request_headers_bytes(&self) -> Vec<(String, Bytes)> { hostcalls::get_map_bytes(MapType::HttpRequestHeaders).unwrap() } @@ -772,6 +1266,37 @@ pub trait HttpContext: Context { hostcalls::get_map_value(MapType::HttpRequestHeaders, name).unwrap() } + /// Get a specific HTTP request header by name as bytes. + /// + /// # Arguments + /// + /// * `name` - the name of the header + /// + /// # Returns + /// + /// * `Option` - the value of the header (wrapped in an Option) or `None` if the header does not exist + /// + /// # Example + /// + /// ```rust + /// use proxy_wasm::traits::*; + /// use proxy_wasm::types::*; + /// use log::debug; + /// + /// struct MyPlugin; + /// + /// impl HttpContext for MyPlugin { + /// fn on_http_request_headers(&mut self, _num_headers: usize, _end_of_stream: bool) -> Action { + /// let header = self.get_http_request_header_bytes(":path").unwrap(); + /// let header_str = String::from_utf8(header).unwrap(); + /// debug!("The path is: {:?}", header_str); + /// + /// Action::Continue + /// } + /// } + /// + /// # impl Context for MyPlugin {} + /// ``` fn get_http_request_header_bytes(&self, name: &str) -> Option { hostcalls::get_map_value_bytes(MapType::HttpRequestHeaders, name).unwrap() } From f97217d809d2f29939d4c5c2e57d14bcc7386d0c Mon Sep 17 00:00:00 2001 From: Anton Engelhardt Date: Mon, 4 Nov 2024 14:49:36 +0100 Subject: [PATCH 13/14] fix(docs): refine docs Signed-off-by: Anton Engelhardt --- src/traits.rs | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/traits.rs b/src/traits.rs index 02567b5a..b134baf1 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -58,7 +58,7 @@ pub trait Context { hostcalls::enqueue_shared_queue(queue_id, value) } - /// Sends HTTP request with serialized `headers`, `body`, and serialized trailers to upstream. + /// Sends HTTP request with serialized `headers`, `body`, and serialized `trailers` to upstream. /// /// `on_http_call_response()` will be called with `token_id` when the response is received by the host, or after the timeout. /// @@ -72,7 +72,10 @@ pub trait Context { /// /// # Returns /// - /// A Result containing the token id of the request, or an error status. + /// A Result containing either + /// + /// * `Ok(token_id)` - The token id of the request + /// * `Err(Status)` - An error status /// /// # Example /// @@ -349,8 +352,8 @@ pub trait Context { /// /// impl Context for MyPlugin { /// fn on_http_call_response(&mut self, _token_id: u32, _: usize, body_size: usize, _: usize) { - /// let header = self.get_http_call_response_header("content-type"); - /// debug!("Received response header: {:?}", header); + /// let content_type = self.get_http_call_response_header("content-type"); + /// debug!("Content-Type: {:?}", content_type); /// /// // Resume the HTTP request after processing the response /// self.resume_http_request(); @@ -404,9 +407,9 @@ pub trait Context { /// /// impl Context for MyPlugin { /// fn on_http_call_response(&mut self, _token_id: u32, _: usize, body_size: usize, _: usize) { - /// let header = self.get_http_call_response_header_bytes("content-type").unwrap(); - /// let header_str = String::from_utf8(header).unwrap(); - /// debug!("Received response header: {:?}", header_str); + /// let content_type = self.get_http_call_response_header_bytes("content-type").unwrap(); + /// let content_type_str = String::from_utf8(content_type).unwrap(); + /// debug!("Content-Type: {:?}", content_type_str); /// /// // Resume the HTTP request after processing the response /// self.resume_http_request(); @@ -532,7 +535,7 @@ pub trait Context { /// /// * `Vec<(String, Bytes)>` - the HTTP call response trailers /// - /// /// # Example + /// # Example /// /// ```rust /// use proxy_wasm::traits::*; @@ -566,13 +569,10 @@ pub trait Context { /// impl Context for MyPlugin { /// fn on_http_call_response(&mut self, _token_id: u32, _: usize, body_size: usize, _: usize) { /// let trailers = self.get_http_call_response_trailers_bytes(); - /// for (name, value) in trailers { - /// let value_str = String::from_utf8(value).unwrap(); - /// debug!("Received response trailer: {:?}", (name, value_str)); + /// debug!("Received response trailers: {:?}", trailers); /// - /// // Resume the HTTP call after processing the response - /// self.resume_http_request(); - /// } + /// // Resume the HTTP call after processing the response + /// self.resume_http_request(); /// } /// } /// ``` @@ -590,7 +590,7 @@ pub trait Context { /// /// * `Option` - the HTTP call response trailer or `None` if the trailer is not found /// - /// /// # Example + /// # Example /// /// ```rust /// use proxy_wasm::traits::*; @@ -623,8 +623,8 @@ pub trait Context { /// /// impl Context for MyPlugin { /// fn on_http_call_response(&mut self, _token_id: u32, _: usize, body_size: usize, _: usize) { - /// let trailer = self.get_http_call_response_trailer("content-type").unwrap(); - /// debug!("Received response trailer: {:?}", trailer); + /// let content_type = self.get_http_call_response_trailer("content-type").unwrap(); + /// debug!("Content-Type: {:?}", content_type); /// /// // Resume the HTTP call after processing the response /// self.resume_http_request(); @@ -678,9 +678,9 @@ pub trait Context { /// /// impl Context for MyPlugin { /// fn on_http_call_response(&mut self, _token_id: u32, _: usize, body_size: usize, _: usize) { - /// let trailer = self.get_http_call_response_trailer_bytes("content-type").unwrap(); - /// let trailer_str = String::from_utf8(trailer).unwrap(); - /// debug!("Received response trailer: {:?}", trailer_str); + /// let content_type = self.get_http_call_response_trailer_bytes("content-type").unwrap(); + /// let content_type_str = String::from_utf8(content_type).unwrap(); + /// debug!("Content-Type: {:?}", content_type_str); /// /// // Resume the HTTP call after processing the response /// self.resume_http_request(); From 74dc47915f12449100a271ddfa9249a7a9a0dcf2 Mon Sep 17 00:00:00 2001 From: Anton Engelhardt Date: Mon, 4 Nov 2024 14:54:47 +0100 Subject: [PATCH 14/14] chore(deps): update bazel dependencies Signed-off-by: Anton Engelhardt --- bazel/cargo/Cargo.Bazel.lock | 87 ++++++++++ bazel/cargo/remote/BUILD.bazel | 12 ++ bazel/cargo/remote/BUILD.itoa-1.0.11.bazel | 81 +++++++++ bazel/cargo/remote/BUILD.memchr-2.7.4.bazel | 85 ++++++++++ .../remote/BUILD.proc-macro2-1.0.89.bazel | 147 +++++++++++++++++ bazel/cargo/remote/BUILD.quote-1.0.37.bazel | 87 ++++++++++ bazel/cargo/remote/BUILD.ryu-1.0.18.bazel | 81 +++++++++ bazel/cargo/remote/BUILD.serde-1.0.214.bazel | 155 ++++++++++++++++++ .../remote/BUILD.serde_derive-1.0.214.bazel | 89 ++++++++++ .../remote/BUILD.serde_json-1.0.132.bazel | 152 +++++++++++++++++ bazel/cargo/remote/BUILD.syn-2.0.87.bazel | 93 +++++++++++ .../remote/BUILD.unicode-ident-1.0.13.bazel | 81 +++++++++ bazel/cargo/remote/defs.bzl | 110 +++++++++++++ 13 files changed, 1260 insertions(+) create mode 100644 bazel/cargo/remote/BUILD.itoa-1.0.11.bazel create mode 100644 bazel/cargo/remote/BUILD.memchr-2.7.4.bazel create mode 100644 bazel/cargo/remote/BUILD.proc-macro2-1.0.89.bazel create mode 100644 bazel/cargo/remote/BUILD.quote-1.0.37.bazel create mode 100644 bazel/cargo/remote/BUILD.ryu-1.0.18.bazel create mode 100644 bazel/cargo/remote/BUILD.serde-1.0.214.bazel create mode 100644 bazel/cargo/remote/BUILD.serde_derive-1.0.214.bazel create mode 100644 bazel/cargo/remote/BUILD.serde_json-1.0.132.bazel create mode 100644 bazel/cargo/remote/BUILD.syn-2.0.87.bazel create mode 100644 bazel/cargo/remote/BUILD.unicode-ident-1.0.13.bazel diff --git a/bazel/cargo/Cargo.Bazel.lock b/bazel/cargo/Cargo.Bazel.lock index f4d451ea..a42c44c4 100644 --- a/bazel/cargo/Cargo.Bazel.lock +++ b/bazel/cargo/Cargo.Bazel.lock @@ -31,16 +31,103 @@ dependencies = [ "foldhash", ] +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + [[package]] name = "log" version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "proc-macro2" +version = "1.0.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f139b0662de085916d1fb67d2b4169d1addddda1919e696f3252b740b629986e" +dependencies = [ + "unicode-ident", +] + [[package]] name = "proxy-wasm" version = "0.2.3-dev" dependencies = [ "hashbrown", "log", + "serde", + "serde_json", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "serde" +version = "1.0.214" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f55c3193aca71c12ad7890f1785d2b73e1b9f63a0bbc353c08ef26fe03fc56b5" +dependencies = [ + "serde_derive", ] + +[[package]] +name = "serde_derive" +version = "1.0.214" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de523f781f095e28fa605cdce0f8307e451cc0fd14e2eb4cd2e98a355b147766" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.132" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d726bfaff4b320266d395898905d0eba0345aae23b54aee3a737e260fd46db03" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "syn" +version = "2.0.87" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" diff --git a/bazel/cargo/remote/BUILD.bazel b/bazel/cargo/remote/BUILD.bazel index f62c1da8..336166ca 100644 --- a/bazel/cargo/remote/BUILD.bazel +++ b/bazel/cargo/remote/BUILD.bazel @@ -48,3 +48,15 @@ alias( actual = "@crates_vendor__proxy-wasm-0.2.3-dev//:proxy_wasm", tags = ["manual"], ) + +alias( + name = "serde", + actual = "@crates_vendor__serde-1.0.214//:serde", + tags = ["manual"], +) + +alias( + name = "serde_json", + actual = "@crates_vendor__serde_json-1.0.132//:serde_json", + tags = ["manual"], +) diff --git a/bazel/cargo/remote/BUILD.itoa-1.0.11.bazel b/bazel/cargo/remote/BUILD.itoa-1.0.11.bazel new file mode 100644 index 00000000..d8c549e8 --- /dev/null +++ b/bazel/cargo/remote/BUILD.itoa-1.0.11.bazel @@ -0,0 +1,81 @@ +############################################################################### +# @generated +# DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To +# regenerate this file, run the following: +# +# bazel run @//bazel/cargo:crates_vendor +############################################################################### + +load("@rules_rust//rust:defs.bzl", "rust_library") + +package(default_visibility = ["//visibility:public"]) + +rust_library( + name = "itoa", + srcs = glob( + include = ["**/*.rs"], + allow_empty = True, + ), + compile_data = glob( + include = ["**"], + allow_empty = True, + exclude = [ + "**/* *", + ".tmp_git_root/**/*", + "BUILD", + "BUILD.bazel", + "WORKSPACE", + "WORKSPACE.bazel", + ], + ), + crate_root = "src/lib.rs", + edition = "2018", + rustc_flags = [ + "--cap-lints=allow", + ], + tags = [ + "cargo-bazel", + "crate-name=itoa", + "manual", + "noclippy", + "norustfmt", + ], + target_compatible_with = select({ + "@rules_rust//rust/platform:aarch64-apple-darwin": [], + "@rules_rust//rust/platform:aarch64-apple-ios": [], + "@rules_rust//rust/platform:aarch64-apple-ios-sim": [], + "@rules_rust//rust/platform:aarch64-fuchsia": [], + "@rules_rust//rust/platform:aarch64-linux-android": [], + "@rules_rust//rust/platform:aarch64-pc-windows-msvc": [], + "@rules_rust//rust/platform:aarch64-unknown-linux-gnu": [], + "@rules_rust//rust/platform:aarch64-unknown-nixos-gnu": [], + "@rules_rust//rust/platform:aarch64-unknown-nto-qnx710": [], + "@rules_rust//rust/platform:arm-unknown-linux-gnueabi": [], + "@rules_rust//rust/platform:armv7-linux-androideabi": [], + "@rules_rust//rust/platform:armv7-unknown-linux-gnueabi": [], + "@rules_rust//rust/platform:i686-apple-darwin": [], + "@rules_rust//rust/platform:i686-linux-android": [], + "@rules_rust//rust/platform:i686-pc-windows-msvc": [], + "@rules_rust//rust/platform:i686-unknown-freebsd": [], + "@rules_rust//rust/platform:i686-unknown-linux-gnu": [], + "@rules_rust//rust/platform:powerpc-unknown-linux-gnu": [], + "@rules_rust//rust/platform:riscv32imc-unknown-none-elf": [], + "@rules_rust//rust/platform:riscv64gc-unknown-none-elf": [], + "@rules_rust//rust/platform:s390x-unknown-linux-gnu": [], + "@rules_rust//rust/platform:thumbv7em-none-eabi": [], + "@rules_rust//rust/platform:thumbv8m.main-none-eabi": [], + "@rules_rust//rust/platform:wasm32-unknown-unknown": [], + "@rules_rust//rust/platform:wasm32-wasi": [], + "@rules_rust//rust/platform:x86_64-apple-darwin": [], + "@rules_rust//rust/platform:x86_64-apple-ios": [], + "@rules_rust//rust/platform:x86_64-fuchsia": [], + "@rules_rust//rust/platform:x86_64-linux-android": [], + "@rules_rust//rust/platform:x86_64-pc-windows-msvc": [], + "@rules_rust//rust/platform:x86_64-unknown-freebsd": [], + "@rules_rust//rust/platform:x86_64-unknown-linux-gnu": [], + "@rules_rust//rust/platform:x86_64-unknown-nixos-gnu": [], + "@rules_rust//rust/platform:x86_64-unknown-none": [], + "//conditions:default": ["@platforms//:incompatible"], + }), + version = "1.0.11", +) diff --git a/bazel/cargo/remote/BUILD.memchr-2.7.4.bazel b/bazel/cargo/remote/BUILD.memchr-2.7.4.bazel new file mode 100644 index 00000000..be1aa06f --- /dev/null +++ b/bazel/cargo/remote/BUILD.memchr-2.7.4.bazel @@ -0,0 +1,85 @@ +############################################################################### +# @generated +# DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To +# regenerate this file, run the following: +# +# bazel run @//bazel/cargo:crates_vendor +############################################################################### + +load("@rules_rust//rust:defs.bzl", "rust_library") + +package(default_visibility = ["//visibility:public"]) + +rust_library( + name = "memchr", + srcs = glob( + include = ["**/*.rs"], + allow_empty = True, + ), + compile_data = glob( + include = ["**"], + allow_empty = True, + exclude = [ + "**/* *", + ".tmp_git_root/**/*", + "BUILD", + "BUILD.bazel", + "WORKSPACE", + "WORKSPACE.bazel", + ], + ), + crate_features = [ + "alloc", + "std", + ], + crate_root = "src/lib.rs", + edition = "2021", + rustc_flags = [ + "--cap-lints=allow", + ], + tags = [ + "cargo-bazel", + "crate-name=memchr", + "manual", + "noclippy", + "norustfmt", + ], + target_compatible_with = select({ + "@rules_rust//rust/platform:aarch64-apple-darwin": [], + "@rules_rust//rust/platform:aarch64-apple-ios": [], + "@rules_rust//rust/platform:aarch64-apple-ios-sim": [], + "@rules_rust//rust/platform:aarch64-fuchsia": [], + "@rules_rust//rust/platform:aarch64-linux-android": [], + "@rules_rust//rust/platform:aarch64-pc-windows-msvc": [], + "@rules_rust//rust/platform:aarch64-unknown-linux-gnu": [], + "@rules_rust//rust/platform:aarch64-unknown-nixos-gnu": [], + "@rules_rust//rust/platform:aarch64-unknown-nto-qnx710": [], + "@rules_rust//rust/platform:arm-unknown-linux-gnueabi": [], + "@rules_rust//rust/platform:armv7-linux-androideabi": [], + "@rules_rust//rust/platform:armv7-unknown-linux-gnueabi": [], + "@rules_rust//rust/platform:i686-apple-darwin": [], + "@rules_rust//rust/platform:i686-linux-android": [], + "@rules_rust//rust/platform:i686-pc-windows-msvc": [], + "@rules_rust//rust/platform:i686-unknown-freebsd": [], + "@rules_rust//rust/platform:i686-unknown-linux-gnu": [], + "@rules_rust//rust/platform:powerpc-unknown-linux-gnu": [], + "@rules_rust//rust/platform:riscv32imc-unknown-none-elf": [], + "@rules_rust//rust/platform:riscv64gc-unknown-none-elf": [], + "@rules_rust//rust/platform:s390x-unknown-linux-gnu": [], + "@rules_rust//rust/platform:thumbv7em-none-eabi": [], + "@rules_rust//rust/platform:thumbv8m.main-none-eabi": [], + "@rules_rust//rust/platform:wasm32-unknown-unknown": [], + "@rules_rust//rust/platform:wasm32-wasi": [], + "@rules_rust//rust/platform:x86_64-apple-darwin": [], + "@rules_rust//rust/platform:x86_64-apple-ios": [], + "@rules_rust//rust/platform:x86_64-fuchsia": [], + "@rules_rust//rust/platform:x86_64-linux-android": [], + "@rules_rust//rust/platform:x86_64-pc-windows-msvc": [], + "@rules_rust//rust/platform:x86_64-unknown-freebsd": [], + "@rules_rust//rust/platform:x86_64-unknown-linux-gnu": [], + "@rules_rust//rust/platform:x86_64-unknown-nixos-gnu": [], + "@rules_rust//rust/platform:x86_64-unknown-none": [], + "//conditions:default": ["@platforms//:incompatible"], + }), + version = "2.7.4", +) diff --git a/bazel/cargo/remote/BUILD.proc-macro2-1.0.89.bazel b/bazel/cargo/remote/BUILD.proc-macro2-1.0.89.bazel new file mode 100644 index 00000000..8c8e666c --- /dev/null +++ b/bazel/cargo/remote/BUILD.proc-macro2-1.0.89.bazel @@ -0,0 +1,147 @@ +############################################################################### +# @generated +# DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To +# regenerate this file, run the following: +# +# bazel run @//bazel/cargo:crates_vendor +############################################################################### + +load("@rules_rust//cargo:defs.bzl", "cargo_build_script") +load("@rules_rust//rust:defs.bzl", "rust_library") + +package(default_visibility = ["//visibility:public"]) + +rust_library( + name = "proc_macro2", + srcs = glob( + include = ["**/*.rs"], + allow_empty = True, + ), + compile_data = glob( + include = ["**"], + allow_empty = True, + exclude = [ + "**/* *", + ".tmp_git_root/**/*", + "BUILD", + "BUILD.bazel", + "WORKSPACE", + "WORKSPACE.bazel", + ], + ), + crate_features = [ + "proc-macro", + ], + crate_root = "src/lib.rs", + edition = "2021", + rustc_flags = [ + "--cap-lints=allow", + ], + tags = [ + "cargo-bazel", + "crate-name=proc-macro2", + "manual", + "noclippy", + "norustfmt", + ], + target_compatible_with = select({ + "@rules_rust//rust/platform:aarch64-apple-darwin": [], + "@rules_rust//rust/platform:aarch64-apple-ios": [], + "@rules_rust//rust/platform:aarch64-apple-ios-sim": [], + "@rules_rust//rust/platform:aarch64-fuchsia": [], + "@rules_rust//rust/platform:aarch64-linux-android": [], + "@rules_rust//rust/platform:aarch64-pc-windows-msvc": [], + "@rules_rust//rust/platform:aarch64-unknown-linux-gnu": [], + "@rules_rust//rust/platform:aarch64-unknown-nixos-gnu": [], + "@rules_rust//rust/platform:aarch64-unknown-nto-qnx710": [], + "@rules_rust//rust/platform:arm-unknown-linux-gnueabi": [], + "@rules_rust//rust/platform:armv7-linux-androideabi": [], + "@rules_rust//rust/platform:armv7-unknown-linux-gnueabi": [], + "@rules_rust//rust/platform:i686-apple-darwin": [], + "@rules_rust//rust/platform:i686-linux-android": [], + "@rules_rust//rust/platform:i686-pc-windows-msvc": [], + "@rules_rust//rust/platform:i686-unknown-freebsd": [], + "@rules_rust//rust/platform:i686-unknown-linux-gnu": [], + "@rules_rust//rust/platform:powerpc-unknown-linux-gnu": [], + "@rules_rust//rust/platform:riscv32imc-unknown-none-elf": [], + "@rules_rust//rust/platform:riscv64gc-unknown-none-elf": [], + "@rules_rust//rust/platform:s390x-unknown-linux-gnu": [], + "@rules_rust//rust/platform:thumbv7em-none-eabi": [], + "@rules_rust//rust/platform:thumbv8m.main-none-eabi": [], + "@rules_rust//rust/platform:wasm32-unknown-unknown": [], + "@rules_rust//rust/platform:wasm32-wasi": [], + "@rules_rust//rust/platform:x86_64-apple-darwin": [], + "@rules_rust//rust/platform:x86_64-apple-ios": [], + "@rules_rust//rust/platform:x86_64-fuchsia": [], + "@rules_rust//rust/platform:x86_64-linux-android": [], + "@rules_rust//rust/platform:x86_64-pc-windows-msvc": [], + "@rules_rust//rust/platform:x86_64-unknown-freebsd": [], + "@rules_rust//rust/platform:x86_64-unknown-linux-gnu": [], + "@rules_rust//rust/platform:x86_64-unknown-nixos-gnu": [], + "@rules_rust//rust/platform:x86_64-unknown-none": [], + "//conditions:default": ["@platforms//:incompatible"], + }), + version = "1.0.89", + deps = [ + "@crates_vendor__proc-macro2-1.0.89//:build_script_build", + "@crates_vendor__unicode-ident-1.0.13//:unicode_ident", + ], +) + +cargo_build_script( + name = "_bs", + srcs = glob( + include = ["**/*.rs"], + allow_empty = True, + ), + compile_data = glob( + include = ["**"], + allow_empty = True, + exclude = [ + "**/* *", + "**/*.rs", + ".tmp_git_root/**/*", + "BUILD", + "BUILD.bazel", + "WORKSPACE", + "WORKSPACE.bazel", + ], + ), + crate_features = [ + "proc-macro", + ], + crate_name = "build_script_build", + crate_root = "build.rs", + data = glob( + include = ["**"], + allow_empty = True, + exclude = [ + "**/* *", + ".tmp_git_root/**/*", + "BUILD", + "BUILD.bazel", + "WORKSPACE", + "WORKSPACE.bazel", + ], + ), + edition = "2021", + pkg_name = "proc-macro2", + rustc_flags = [ + "--cap-lints=allow", + ], + tags = [ + "cargo-bazel", + "crate-name=proc-macro2", + "manual", + "noclippy", + "norustfmt", + ], + version = "1.0.89", + visibility = ["//visibility:private"], +) + +alias( + name = "build_script_build", + actual = ":_bs", + tags = ["manual"], +) diff --git a/bazel/cargo/remote/BUILD.quote-1.0.37.bazel b/bazel/cargo/remote/BUILD.quote-1.0.37.bazel new file mode 100644 index 00000000..1c6217c9 --- /dev/null +++ b/bazel/cargo/remote/BUILD.quote-1.0.37.bazel @@ -0,0 +1,87 @@ +############################################################################### +# @generated +# DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To +# regenerate this file, run the following: +# +# bazel run @//bazel/cargo:crates_vendor +############################################################################### + +load("@rules_rust//rust:defs.bzl", "rust_library") + +package(default_visibility = ["//visibility:public"]) + +rust_library( + name = "quote", + srcs = glob( + include = ["**/*.rs"], + allow_empty = True, + ), + compile_data = glob( + include = ["**"], + allow_empty = True, + exclude = [ + "**/* *", + ".tmp_git_root/**/*", + "BUILD", + "BUILD.bazel", + "WORKSPACE", + "WORKSPACE.bazel", + ], + ), + crate_features = [ + "proc-macro", + ], + crate_root = "src/lib.rs", + edition = "2018", + rustc_flags = [ + "--cap-lints=allow", + ], + tags = [ + "cargo-bazel", + "crate-name=quote", + "manual", + "noclippy", + "norustfmt", + ], + target_compatible_with = select({ + "@rules_rust//rust/platform:aarch64-apple-darwin": [], + "@rules_rust//rust/platform:aarch64-apple-ios": [], + "@rules_rust//rust/platform:aarch64-apple-ios-sim": [], + "@rules_rust//rust/platform:aarch64-fuchsia": [], + "@rules_rust//rust/platform:aarch64-linux-android": [], + "@rules_rust//rust/platform:aarch64-pc-windows-msvc": [], + "@rules_rust//rust/platform:aarch64-unknown-linux-gnu": [], + "@rules_rust//rust/platform:aarch64-unknown-nixos-gnu": [], + "@rules_rust//rust/platform:aarch64-unknown-nto-qnx710": [], + "@rules_rust//rust/platform:arm-unknown-linux-gnueabi": [], + "@rules_rust//rust/platform:armv7-linux-androideabi": [], + "@rules_rust//rust/platform:armv7-unknown-linux-gnueabi": [], + "@rules_rust//rust/platform:i686-apple-darwin": [], + "@rules_rust//rust/platform:i686-linux-android": [], + "@rules_rust//rust/platform:i686-pc-windows-msvc": [], + "@rules_rust//rust/platform:i686-unknown-freebsd": [], + "@rules_rust//rust/platform:i686-unknown-linux-gnu": [], + "@rules_rust//rust/platform:powerpc-unknown-linux-gnu": [], + "@rules_rust//rust/platform:riscv32imc-unknown-none-elf": [], + "@rules_rust//rust/platform:riscv64gc-unknown-none-elf": [], + "@rules_rust//rust/platform:s390x-unknown-linux-gnu": [], + "@rules_rust//rust/platform:thumbv7em-none-eabi": [], + "@rules_rust//rust/platform:thumbv8m.main-none-eabi": [], + "@rules_rust//rust/platform:wasm32-unknown-unknown": [], + "@rules_rust//rust/platform:wasm32-wasi": [], + "@rules_rust//rust/platform:x86_64-apple-darwin": [], + "@rules_rust//rust/platform:x86_64-apple-ios": [], + "@rules_rust//rust/platform:x86_64-fuchsia": [], + "@rules_rust//rust/platform:x86_64-linux-android": [], + "@rules_rust//rust/platform:x86_64-pc-windows-msvc": [], + "@rules_rust//rust/platform:x86_64-unknown-freebsd": [], + "@rules_rust//rust/platform:x86_64-unknown-linux-gnu": [], + "@rules_rust//rust/platform:x86_64-unknown-nixos-gnu": [], + "@rules_rust//rust/platform:x86_64-unknown-none": [], + "//conditions:default": ["@platforms//:incompatible"], + }), + version = "1.0.37", + deps = [ + "@crates_vendor__proc-macro2-1.0.89//:proc_macro2", + ], +) diff --git a/bazel/cargo/remote/BUILD.ryu-1.0.18.bazel b/bazel/cargo/remote/BUILD.ryu-1.0.18.bazel new file mode 100644 index 00000000..2a49d080 --- /dev/null +++ b/bazel/cargo/remote/BUILD.ryu-1.0.18.bazel @@ -0,0 +1,81 @@ +############################################################################### +# @generated +# DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To +# regenerate this file, run the following: +# +# bazel run @//bazel/cargo:crates_vendor +############################################################################### + +load("@rules_rust//rust:defs.bzl", "rust_library") + +package(default_visibility = ["//visibility:public"]) + +rust_library( + name = "ryu", + srcs = glob( + include = ["**/*.rs"], + allow_empty = True, + ), + compile_data = glob( + include = ["**"], + allow_empty = True, + exclude = [ + "**/* *", + ".tmp_git_root/**/*", + "BUILD", + "BUILD.bazel", + "WORKSPACE", + "WORKSPACE.bazel", + ], + ), + crate_root = "src/lib.rs", + edition = "2018", + rustc_flags = [ + "--cap-lints=allow", + ], + tags = [ + "cargo-bazel", + "crate-name=ryu", + "manual", + "noclippy", + "norustfmt", + ], + target_compatible_with = select({ + "@rules_rust//rust/platform:aarch64-apple-darwin": [], + "@rules_rust//rust/platform:aarch64-apple-ios": [], + "@rules_rust//rust/platform:aarch64-apple-ios-sim": [], + "@rules_rust//rust/platform:aarch64-fuchsia": [], + "@rules_rust//rust/platform:aarch64-linux-android": [], + "@rules_rust//rust/platform:aarch64-pc-windows-msvc": [], + "@rules_rust//rust/platform:aarch64-unknown-linux-gnu": [], + "@rules_rust//rust/platform:aarch64-unknown-nixos-gnu": [], + "@rules_rust//rust/platform:aarch64-unknown-nto-qnx710": [], + "@rules_rust//rust/platform:arm-unknown-linux-gnueabi": [], + "@rules_rust//rust/platform:armv7-linux-androideabi": [], + "@rules_rust//rust/platform:armv7-unknown-linux-gnueabi": [], + "@rules_rust//rust/platform:i686-apple-darwin": [], + "@rules_rust//rust/platform:i686-linux-android": [], + "@rules_rust//rust/platform:i686-pc-windows-msvc": [], + "@rules_rust//rust/platform:i686-unknown-freebsd": [], + "@rules_rust//rust/platform:i686-unknown-linux-gnu": [], + "@rules_rust//rust/platform:powerpc-unknown-linux-gnu": [], + "@rules_rust//rust/platform:riscv32imc-unknown-none-elf": [], + "@rules_rust//rust/platform:riscv64gc-unknown-none-elf": [], + "@rules_rust//rust/platform:s390x-unknown-linux-gnu": [], + "@rules_rust//rust/platform:thumbv7em-none-eabi": [], + "@rules_rust//rust/platform:thumbv8m.main-none-eabi": [], + "@rules_rust//rust/platform:wasm32-unknown-unknown": [], + "@rules_rust//rust/platform:wasm32-wasi": [], + "@rules_rust//rust/platform:x86_64-apple-darwin": [], + "@rules_rust//rust/platform:x86_64-apple-ios": [], + "@rules_rust//rust/platform:x86_64-fuchsia": [], + "@rules_rust//rust/platform:x86_64-linux-android": [], + "@rules_rust//rust/platform:x86_64-pc-windows-msvc": [], + "@rules_rust//rust/platform:x86_64-unknown-freebsd": [], + "@rules_rust//rust/platform:x86_64-unknown-linux-gnu": [], + "@rules_rust//rust/platform:x86_64-unknown-nixos-gnu": [], + "@rules_rust//rust/platform:x86_64-unknown-none": [], + "//conditions:default": ["@platforms//:incompatible"], + }), + version = "1.0.18", +) diff --git a/bazel/cargo/remote/BUILD.serde-1.0.214.bazel b/bazel/cargo/remote/BUILD.serde-1.0.214.bazel new file mode 100644 index 00000000..ecc2921b --- /dev/null +++ b/bazel/cargo/remote/BUILD.serde-1.0.214.bazel @@ -0,0 +1,155 @@ +############################################################################### +# @generated +# DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To +# regenerate this file, run the following: +# +# bazel run @//bazel/cargo:crates_vendor +############################################################################### + +load("@rules_rust//cargo:defs.bzl", "cargo_build_script") +load("@rules_rust//rust:defs.bzl", "rust_library") + +package(default_visibility = ["//visibility:public"]) + +rust_library( + name = "serde", + srcs = glob( + include = ["**/*.rs"], + allow_empty = True, + ), + compile_data = glob( + include = ["**"], + allow_empty = True, + exclude = [ + "**/* *", + ".tmp_git_root/**/*", + "BUILD", + "BUILD.bazel", + "WORKSPACE", + "WORKSPACE.bazel", + ], + ), + crate_features = [ + "default", + "derive", + "serde_derive", + "std", + ], + crate_root = "src/lib.rs", + edition = "2018", + proc_macro_deps = [ + "@crates_vendor__serde_derive-1.0.214//:serde_derive", + ], + rustc_flags = [ + "--cap-lints=allow", + ], + tags = [ + "cargo-bazel", + "crate-name=serde", + "manual", + "noclippy", + "norustfmt", + ], + target_compatible_with = select({ + "@rules_rust//rust/platform:aarch64-apple-darwin": [], + "@rules_rust//rust/platform:aarch64-apple-ios": [], + "@rules_rust//rust/platform:aarch64-apple-ios-sim": [], + "@rules_rust//rust/platform:aarch64-fuchsia": [], + "@rules_rust//rust/platform:aarch64-linux-android": [], + "@rules_rust//rust/platform:aarch64-pc-windows-msvc": [], + "@rules_rust//rust/platform:aarch64-unknown-linux-gnu": [], + "@rules_rust//rust/platform:aarch64-unknown-nixos-gnu": [], + "@rules_rust//rust/platform:aarch64-unknown-nto-qnx710": [], + "@rules_rust//rust/platform:arm-unknown-linux-gnueabi": [], + "@rules_rust//rust/platform:armv7-linux-androideabi": [], + "@rules_rust//rust/platform:armv7-unknown-linux-gnueabi": [], + "@rules_rust//rust/platform:i686-apple-darwin": [], + "@rules_rust//rust/platform:i686-linux-android": [], + "@rules_rust//rust/platform:i686-pc-windows-msvc": [], + "@rules_rust//rust/platform:i686-unknown-freebsd": [], + "@rules_rust//rust/platform:i686-unknown-linux-gnu": [], + "@rules_rust//rust/platform:powerpc-unknown-linux-gnu": [], + "@rules_rust//rust/platform:riscv32imc-unknown-none-elf": [], + "@rules_rust//rust/platform:riscv64gc-unknown-none-elf": [], + "@rules_rust//rust/platform:s390x-unknown-linux-gnu": [], + "@rules_rust//rust/platform:thumbv7em-none-eabi": [], + "@rules_rust//rust/platform:thumbv8m.main-none-eabi": [], + "@rules_rust//rust/platform:wasm32-unknown-unknown": [], + "@rules_rust//rust/platform:wasm32-wasi": [], + "@rules_rust//rust/platform:x86_64-apple-darwin": [], + "@rules_rust//rust/platform:x86_64-apple-ios": [], + "@rules_rust//rust/platform:x86_64-fuchsia": [], + "@rules_rust//rust/platform:x86_64-linux-android": [], + "@rules_rust//rust/platform:x86_64-pc-windows-msvc": [], + "@rules_rust//rust/platform:x86_64-unknown-freebsd": [], + "@rules_rust//rust/platform:x86_64-unknown-linux-gnu": [], + "@rules_rust//rust/platform:x86_64-unknown-nixos-gnu": [], + "@rules_rust//rust/platform:x86_64-unknown-none": [], + "//conditions:default": ["@platforms//:incompatible"], + }), + version = "1.0.214", + deps = [ + "@crates_vendor__serde-1.0.214//:build_script_build", + ], +) + +cargo_build_script( + name = "_bs", + srcs = glob( + include = ["**/*.rs"], + allow_empty = True, + ), + compile_data = glob( + include = ["**"], + allow_empty = True, + exclude = [ + "**/* *", + "**/*.rs", + ".tmp_git_root/**/*", + "BUILD", + "BUILD.bazel", + "WORKSPACE", + "WORKSPACE.bazel", + ], + ), + crate_features = [ + "default", + "derive", + "serde_derive", + "std", + ], + crate_name = "build_script_build", + crate_root = "build.rs", + data = glob( + include = ["**"], + allow_empty = True, + exclude = [ + "**/* *", + ".tmp_git_root/**/*", + "BUILD", + "BUILD.bazel", + "WORKSPACE", + "WORKSPACE.bazel", + ], + ), + edition = "2018", + pkg_name = "serde", + rustc_flags = [ + "--cap-lints=allow", + ], + tags = [ + "cargo-bazel", + "crate-name=serde", + "manual", + "noclippy", + "norustfmt", + ], + version = "1.0.214", + visibility = ["//visibility:private"], +) + +alias( + name = "build_script_build", + actual = ":_bs", + tags = ["manual"], +) diff --git a/bazel/cargo/remote/BUILD.serde_derive-1.0.214.bazel b/bazel/cargo/remote/BUILD.serde_derive-1.0.214.bazel new file mode 100644 index 00000000..4c1cbddf --- /dev/null +++ b/bazel/cargo/remote/BUILD.serde_derive-1.0.214.bazel @@ -0,0 +1,89 @@ +############################################################################### +# @generated +# DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To +# regenerate this file, run the following: +# +# bazel run @//bazel/cargo:crates_vendor +############################################################################### + +load("@rules_rust//rust:defs.bzl", "rust_proc_macro") + +package(default_visibility = ["//visibility:public"]) + +rust_proc_macro( + name = "serde_derive", + srcs = glob( + include = ["**/*.rs"], + allow_empty = True, + ), + compile_data = glob( + include = ["**"], + allow_empty = True, + exclude = [ + "**/* *", + ".tmp_git_root/**/*", + "BUILD", + "BUILD.bazel", + "WORKSPACE", + "WORKSPACE.bazel", + ], + ), + crate_features = [ + "default", + ], + crate_root = "src/lib.rs", + edition = "2015", + rustc_flags = [ + "--cap-lints=allow", + ], + tags = [ + "cargo-bazel", + "crate-name=serde_derive", + "manual", + "noclippy", + "norustfmt", + ], + target_compatible_with = select({ + "@rules_rust//rust/platform:aarch64-apple-darwin": [], + "@rules_rust//rust/platform:aarch64-apple-ios": [], + "@rules_rust//rust/platform:aarch64-apple-ios-sim": [], + "@rules_rust//rust/platform:aarch64-fuchsia": [], + "@rules_rust//rust/platform:aarch64-linux-android": [], + "@rules_rust//rust/platform:aarch64-pc-windows-msvc": [], + "@rules_rust//rust/platform:aarch64-unknown-linux-gnu": [], + "@rules_rust//rust/platform:aarch64-unknown-nixos-gnu": [], + "@rules_rust//rust/platform:aarch64-unknown-nto-qnx710": [], + "@rules_rust//rust/platform:arm-unknown-linux-gnueabi": [], + "@rules_rust//rust/platform:armv7-linux-androideabi": [], + "@rules_rust//rust/platform:armv7-unknown-linux-gnueabi": [], + "@rules_rust//rust/platform:i686-apple-darwin": [], + "@rules_rust//rust/platform:i686-linux-android": [], + "@rules_rust//rust/platform:i686-pc-windows-msvc": [], + "@rules_rust//rust/platform:i686-unknown-freebsd": [], + "@rules_rust//rust/platform:i686-unknown-linux-gnu": [], + "@rules_rust//rust/platform:powerpc-unknown-linux-gnu": [], + "@rules_rust//rust/platform:riscv32imc-unknown-none-elf": [], + "@rules_rust//rust/platform:riscv64gc-unknown-none-elf": [], + "@rules_rust//rust/platform:s390x-unknown-linux-gnu": [], + "@rules_rust//rust/platform:thumbv7em-none-eabi": [], + "@rules_rust//rust/platform:thumbv8m.main-none-eabi": [], + "@rules_rust//rust/platform:wasm32-unknown-unknown": [], + "@rules_rust//rust/platform:wasm32-wasi": [], + "@rules_rust//rust/platform:x86_64-apple-darwin": [], + "@rules_rust//rust/platform:x86_64-apple-ios": [], + "@rules_rust//rust/platform:x86_64-fuchsia": [], + "@rules_rust//rust/platform:x86_64-linux-android": [], + "@rules_rust//rust/platform:x86_64-pc-windows-msvc": [], + "@rules_rust//rust/platform:x86_64-unknown-freebsd": [], + "@rules_rust//rust/platform:x86_64-unknown-linux-gnu": [], + "@rules_rust//rust/platform:x86_64-unknown-nixos-gnu": [], + "@rules_rust//rust/platform:x86_64-unknown-none": [], + "//conditions:default": ["@platforms//:incompatible"], + }), + version = "1.0.214", + deps = [ + "@crates_vendor__proc-macro2-1.0.89//:proc_macro2", + "@crates_vendor__quote-1.0.37//:quote", + "@crates_vendor__syn-2.0.87//:syn", + ], +) diff --git a/bazel/cargo/remote/BUILD.serde_json-1.0.132.bazel b/bazel/cargo/remote/BUILD.serde_json-1.0.132.bazel new file mode 100644 index 00000000..0bff7800 --- /dev/null +++ b/bazel/cargo/remote/BUILD.serde_json-1.0.132.bazel @@ -0,0 +1,152 @@ +############################################################################### +# @generated +# DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To +# regenerate this file, run the following: +# +# bazel run @//bazel/cargo:crates_vendor +############################################################################### + +load("@rules_rust//cargo:defs.bzl", "cargo_build_script") +load("@rules_rust//rust:defs.bzl", "rust_library") + +package(default_visibility = ["//visibility:public"]) + +rust_library( + name = "serde_json", + srcs = glob( + include = ["**/*.rs"], + allow_empty = True, + ), + compile_data = glob( + include = ["**"], + allow_empty = True, + exclude = [ + "**/* *", + ".tmp_git_root/**/*", + "BUILD", + "BUILD.bazel", + "WORKSPACE", + "WORKSPACE.bazel", + ], + ), + crate_features = [ + "default", + "std", + ], + crate_root = "src/lib.rs", + edition = "2021", + rustc_flags = [ + "--cap-lints=allow", + ], + tags = [ + "cargo-bazel", + "crate-name=serde_json", + "manual", + "noclippy", + "norustfmt", + ], + target_compatible_with = select({ + "@rules_rust//rust/platform:aarch64-apple-darwin": [], + "@rules_rust//rust/platform:aarch64-apple-ios": [], + "@rules_rust//rust/platform:aarch64-apple-ios-sim": [], + "@rules_rust//rust/platform:aarch64-fuchsia": [], + "@rules_rust//rust/platform:aarch64-linux-android": [], + "@rules_rust//rust/platform:aarch64-pc-windows-msvc": [], + "@rules_rust//rust/platform:aarch64-unknown-linux-gnu": [], + "@rules_rust//rust/platform:aarch64-unknown-nixos-gnu": [], + "@rules_rust//rust/platform:aarch64-unknown-nto-qnx710": [], + "@rules_rust//rust/platform:arm-unknown-linux-gnueabi": [], + "@rules_rust//rust/platform:armv7-linux-androideabi": [], + "@rules_rust//rust/platform:armv7-unknown-linux-gnueabi": [], + "@rules_rust//rust/platform:i686-apple-darwin": [], + "@rules_rust//rust/platform:i686-linux-android": [], + "@rules_rust//rust/platform:i686-pc-windows-msvc": [], + "@rules_rust//rust/platform:i686-unknown-freebsd": [], + "@rules_rust//rust/platform:i686-unknown-linux-gnu": [], + "@rules_rust//rust/platform:powerpc-unknown-linux-gnu": [], + "@rules_rust//rust/platform:riscv32imc-unknown-none-elf": [], + "@rules_rust//rust/platform:riscv64gc-unknown-none-elf": [], + "@rules_rust//rust/platform:s390x-unknown-linux-gnu": [], + "@rules_rust//rust/platform:thumbv7em-none-eabi": [], + "@rules_rust//rust/platform:thumbv8m.main-none-eabi": [], + "@rules_rust//rust/platform:wasm32-unknown-unknown": [], + "@rules_rust//rust/platform:wasm32-wasi": [], + "@rules_rust//rust/platform:x86_64-apple-darwin": [], + "@rules_rust//rust/platform:x86_64-apple-ios": [], + "@rules_rust//rust/platform:x86_64-fuchsia": [], + "@rules_rust//rust/platform:x86_64-linux-android": [], + "@rules_rust//rust/platform:x86_64-pc-windows-msvc": [], + "@rules_rust//rust/platform:x86_64-unknown-freebsd": [], + "@rules_rust//rust/platform:x86_64-unknown-linux-gnu": [], + "@rules_rust//rust/platform:x86_64-unknown-nixos-gnu": [], + "@rules_rust//rust/platform:x86_64-unknown-none": [], + "//conditions:default": ["@platforms//:incompatible"], + }), + version = "1.0.132", + deps = [ + "@crates_vendor__itoa-1.0.11//:itoa", + "@crates_vendor__memchr-2.7.4//:memchr", + "@crates_vendor__ryu-1.0.18//:ryu", + "@crates_vendor__serde-1.0.214//:serde", + "@crates_vendor__serde_json-1.0.132//:build_script_build", + ], +) + +cargo_build_script( + name = "_bs", + srcs = glob( + include = ["**/*.rs"], + allow_empty = True, + ), + compile_data = glob( + include = ["**"], + allow_empty = True, + exclude = [ + "**/* *", + "**/*.rs", + ".tmp_git_root/**/*", + "BUILD", + "BUILD.bazel", + "WORKSPACE", + "WORKSPACE.bazel", + ], + ), + crate_features = [ + "default", + "std", + ], + crate_name = "build_script_build", + crate_root = "build.rs", + data = glob( + include = ["**"], + allow_empty = True, + exclude = [ + "**/* *", + ".tmp_git_root/**/*", + "BUILD", + "BUILD.bazel", + "WORKSPACE", + "WORKSPACE.bazel", + ], + ), + edition = "2021", + pkg_name = "serde_json", + rustc_flags = [ + "--cap-lints=allow", + ], + tags = [ + "cargo-bazel", + "crate-name=serde_json", + "manual", + "noclippy", + "norustfmt", + ], + version = "1.0.132", + visibility = ["//visibility:private"], +) + +alias( + name = "build_script_build", + actual = ":_bs", + tags = ["manual"], +) diff --git a/bazel/cargo/remote/BUILD.syn-2.0.87.bazel b/bazel/cargo/remote/BUILD.syn-2.0.87.bazel new file mode 100644 index 00000000..ae6beb05 --- /dev/null +++ b/bazel/cargo/remote/BUILD.syn-2.0.87.bazel @@ -0,0 +1,93 @@ +############################################################################### +# @generated +# DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To +# regenerate this file, run the following: +# +# bazel run @//bazel/cargo:crates_vendor +############################################################################### + +load("@rules_rust//rust:defs.bzl", "rust_library") + +package(default_visibility = ["//visibility:public"]) + +rust_library( + name = "syn", + srcs = glob( + include = ["**/*.rs"], + allow_empty = True, + ), + compile_data = glob( + include = ["**"], + allow_empty = True, + exclude = [ + "**/* *", + ".tmp_git_root/**/*", + "BUILD", + "BUILD.bazel", + "WORKSPACE", + "WORKSPACE.bazel", + ], + ), + crate_features = [ + "clone-impls", + "derive", + "parsing", + "printing", + "proc-macro", + ], + crate_root = "src/lib.rs", + edition = "2021", + rustc_flags = [ + "--cap-lints=allow", + ], + tags = [ + "cargo-bazel", + "crate-name=syn", + "manual", + "noclippy", + "norustfmt", + ], + target_compatible_with = select({ + "@rules_rust//rust/platform:aarch64-apple-darwin": [], + "@rules_rust//rust/platform:aarch64-apple-ios": [], + "@rules_rust//rust/platform:aarch64-apple-ios-sim": [], + "@rules_rust//rust/platform:aarch64-fuchsia": [], + "@rules_rust//rust/platform:aarch64-linux-android": [], + "@rules_rust//rust/platform:aarch64-pc-windows-msvc": [], + "@rules_rust//rust/platform:aarch64-unknown-linux-gnu": [], + "@rules_rust//rust/platform:aarch64-unknown-nixos-gnu": [], + "@rules_rust//rust/platform:aarch64-unknown-nto-qnx710": [], + "@rules_rust//rust/platform:arm-unknown-linux-gnueabi": [], + "@rules_rust//rust/platform:armv7-linux-androideabi": [], + "@rules_rust//rust/platform:armv7-unknown-linux-gnueabi": [], + "@rules_rust//rust/platform:i686-apple-darwin": [], + "@rules_rust//rust/platform:i686-linux-android": [], + "@rules_rust//rust/platform:i686-pc-windows-msvc": [], + "@rules_rust//rust/platform:i686-unknown-freebsd": [], + "@rules_rust//rust/platform:i686-unknown-linux-gnu": [], + "@rules_rust//rust/platform:powerpc-unknown-linux-gnu": [], + "@rules_rust//rust/platform:riscv32imc-unknown-none-elf": [], + "@rules_rust//rust/platform:riscv64gc-unknown-none-elf": [], + "@rules_rust//rust/platform:s390x-unknown-linux-gnu": [], + "@rules_rust//rust/platform:thumbv7em-none-eabi": [], + "@rules_rust//rust/platform:thumbv8m.main-none-eabi": [], + "@rules_rust//rust/platform:wasm32-unknown-unknown": [], + "@rules_rust//rust/platform:wasm32-wasi": [], + "@rules_rust//rust/platform:x86_64-apple-darwin": [], + "@rules_rust//rust/platform:x86_64-apple-ios": [], + "@rules_rust//rust/platform:x86_64-fuchsia": [], + "@rules_rust//rust/platform:x86_64-linux-android": [], + "@rules_rust//rust/platform:x86_64-pc-windows-msvc": [], + "@rules_rust//rust/platform:x86_64-unknown-freebsd": [], + "@rules_rust//rust/platform:x86_64-unknown-linux-gnu": [], + "@rules_rust//rust/platform:x86_64-unknown-nixos-gnu": [], + "@rules_rust//rust/platform:x86_64-unknown-none": [], + "//conditions:default": ["@platforms//:incompatible"], + }), + version = "2.0.87", + deps = [ + "@crates_vendor__proc-macro2-1.0.89//:proc_macro2", + "@crates_vendor__quote-1.0.37//:quote", + "@crates_vendor__unicode-ident-1.0.13//:unicode_ident", + ], +) diff --git a/bazel/cargo/remote/BUILD.unicode-ident-1.0.13.bazel b/bazel/cargo/remote/BUILD.unicode-ident-1.0.13.bazel new file mode 100644 index 00000000..b074d002 --- /dev/null +++ b/bazel/cargo/remote/BUILD.unicode-ident-1.0.13.bazel @@ -0,0 +1,81 @@ +############################################################################### +# @generated +# DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To +# regenerate this file, run the following: +# +# bazel run @//bazel/cargo:crates_vendor +############################################################################### + +load("@rules_rust//rust:defs.bzl", "rust_library") + +package(default_visibility = ["//visibility:public"]) + +rust_library( + name = "unicode_ident", + srcs = glob( + include = ["**/*.rs"], + allow_empty = True, + ), + compile_data = glob( + include = ["**"], + allow_empty = True, + exclude = [ + "**/* *", + ".tmp_git_root/**/*", + "BUILD", + "BUILD.bazel", + "WORKSPACE", + "WORKSPACE.bazel", + ], + ), + crate_root = "src/lib.rs", + edition = "2018", + rustc_flags = [ + "--cap-lints=allow", + ], + tags = [ + "cargo-bazel", + "crate-name=unicode-ident", + "manual", + "noclippy", + "norustfmt", + ], + target_compatible_with = select({ + "@rules_rust//rust/platform:aarch64-apple-darwin": [], + "@rules_rust//rust/platform:aarch64-apple-ios": [], + "@rules_rust//rust/platform:aarch64-apple-ios-sim": [], + "@rules_rust//rust/platform:aarch64-fuchsia": [], + "@rules_rust//rust/platform:aarch64-linux-android": [], + "@rules_rust//rust/platform:aarch64-pc-windows-msvc": [], + "@rules_rust//rust/platform:aarch64-unknown-linux-gnu": [], + "@rules_rust//rust/platform:aarch64-unknown-nixos-gnu": [], + "@rules_rust//rust/platform:aarch64-unknown-nto-qnx710": [], + "@rules_rust//rust/platform:arm-unknown-linux-gnueabi": [], + "@rules_rust//rust/platform:armv7-linux-androideabi": [], + "@rules_rust//rust/platform:armv7-unknown-linux-gnueabi": [], + "@rules_rust//rust/platform:i686-apple-darwin": [], + "@rules_rust//rust/platform:i686-linux-android": [], + "@rules_rust//rust/platform:i686-pc-windows-msvc": [], + "@rules_rust//rust/platform:i686-unknown-freebsd": [], + "@rules_rust//rust/platform:i686-unknown-linux-gnu": [], + "@rules_rust//rust/platform:powerpc-unknown-linux-gnu": [], + "@rules_rust//rust/platform:riscv32imc-unknown-none-elf": [], + "@rules_rust//rust/platform:riscv64gc-unknown-none-elf": [], + "@rules_rust//rust/platform:s390x-unknown-linux-gnu": [], + "@rules_rust//rust/platform:thumbv7em-none-eabi": [], + "@rules_rust//rust/platform:thumbv8m.main-none-eabi": [], + "@rules_rust//rust/platform:wasm32-unknown-unknown": [], + "@rules_rust//rust/platform:wasm32-wasi": [], + "@rules_rust//rust/platform:x86_64-apple-darwin": [], + "@rules_rust//rust/platform:x86_64-apple-ios": [], + "@rules_rust//rust/platform:x86_64-fuchsia": [], + "@rules_rust//rust/platform:x86_64-linux-android": [], + "@rules_rust//rust/platform:x86_64-pc-windows-msvc": [], + "@rules_rust//rust/platform:x86_64-unknown-freebsd": [], + "@rules_rust//rust/platform:x86_64-unknown-linux-gnu": [], + "@rules_rust//rust/platform:x86_64-unknown-nixos-gnu": [], + "@rules_rust//rust/platform:x86_64-unknown-none": [], + "//conditions:default": ["@platforms//:incompatible"], + }), + version = "1.0.13", +) diff --git a/bazel/cargo/remote/defs.bzl b/bazel/cargo/remote/defs.bzl index e4051261..fcd06caa 100644 --- a/bazel/cargo/remote/defs.bzl +++ b/bazel/cargo/remote/defs.bzl @@ -310,11 +310,17 @@ _NORMAL_ALIASES = { _NORMAL_DEV_DEPENDENCIES = { "": { + _COMMON_CONDITION: { + "serde": Label("@crates_vendor__serde-1.0.214//:serde"), + "serde_json": Label("@crates_vendor__serde_json-1.0.132//:serde_json"), + }, }, } _NORMAL_DEV_ALIASES = { "": { + _COMMON_CONDITION: { + }, }, } @@ -335,6 +341,8 @@ _PROC_MACRO_DEV_DEPENDENCIES = { _PROC_MACRO_DEV_ALIASES = { "": { + _COMMON_CONDITION: { + }, }, } @@ -443,6 +451,16 @@ def crate_repositories(): build_file = Label("@proxy_wasm_rust_sdk//bazel/cargo/remote:BUILD.hashbrown-0.15.0.bazel"), ) + maybe( + http_archive, + name = "crates_vendor__itoa-1.0.11", + sha256 = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b", + type = "tar.gz", + urls = ["https://static.crates.io/crates/itoa/1.0.11/download"], + strip_prefix = "itoa-1.0.11", + build_file = Label("@proxy_wasm_rust_sdk//bazel/cargo/remote:BUILD.itoa-1.0.11.bazel"), + ) + maybe( http_archive, name = "crates_vendor__log-0.4.22", @@ -453,7 +471,99 @@ def crate_repositories(): build_file = Label("@proxy_wasm_rust_sdk//bazel/cargo/remote:BUILD.log-0.4.22.bazel"), ) + maybe( + http_archive, + name = "crates_vendor__memchr-2.7.4", + sha256 = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3", + type = "tar.gz", + urls = ["https://static.crates.io/crates/memchr/2.7.4/download"], + strip_prefix = "memchr-2.7.4", + build_file = Label("@proxy_wasm_rust_sdk//bazel/cargo/remote:BUILD.memchr-2.7.4.bazel"), + ) + + maybe( + http_archive, + name = "crates_vendor__proc-macro2-1.0.89", + sha256 = "f139b0662de085916d1fb67d2b4169d1addddda1919e696f3252b740b629986e", + type = "tar.gz", + urls = ["https://static.crates.io/crates/proc-macro2/1.0.89/download"], + strip_prefix = "proc-macro2-1.0.89", + build_file = Label("@proxy_wasm_rust_sdk//bazel/cargo/remote:BUILD.proc-macro2-1.0.89.bazel"), + ) + + maybe( + http_archive, + name = "crates_vendor__quote-1.0.37", + sha256 = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af", + type = "tar.gz", + urls = ["https://static.crates.io/crates/quote/1.0.37/download"], + strip_prefix = "quote-1.0.37", + build_file = Label("@proxy_wasm_rust_sdk//bazel/cargo/remote:BUILD.quote-1.0.37.bazel"), + ) + + maybe( + http_archive, + name = "crates_vendor__ryu-1.0.18", + sha256 = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f", + type = "tar.gz", + urls = ["https://static.crates.io/crates/ryu/1.0.18/download"], + strip_prefix = "ryu-1.0.18", + build_file = Label("@proxy_wasm_rust_sdk//bazel/cargo/remote:BUILD.ryu-1.0.18.bazel"), + ) + + maybe( + http_archive, + name = "crates_vendor__serde-1.0.214", + sha256 = "f55c3193aca71c12ad7890f1785d2b73e1b9f63a0bbc353c08ef26fe03fc56b5", + type = "tar.gz", + urls = ["https://static.crates.io/crates/serde/1.0.214/download"], + strip_prefix = "serde-1.0.214", + build_file = Label("@proxy_wasm_rust_sdk//bazel/cargo/remote:BUILD.serde-1.0.214.bazel"), + ) + + maybe( + http_archive, + name = "crates_vendor__serde_derive-1.0.214", + sha256 = "de523f781f095e28fa605cdce0f8307e451cc0fd14e2eb4cd2e98a355b147766", + type = "tar.gz", + urls = ["https://static.crates.io/crates/serde_derive/1.0.214/download"], + strip_prefix = "serde_derive-1.0.214", + build_file = Label("@proxy_wasm_rust_sdk//bazel/cargo/remote:BUILD.serde_derive-1.0.214.bazel"), + ) + + maybe( + http_archive, + name = "crates_vendor__serde_json-1.0.132", + sha256 = "d726bfaff4b320266d395898905d0eba0345aae23b54aee3a737e260fd46db03", + type = "tar.gz", + urls = ["https://static.crates.io/crates/serde_json/1.0.132/download"], + strip_prefix = "serde_json-1.0.132", + build_file = Label("@proxy_wasm_rust_sdk//bazel/cargo/remote:BUILD.serde_json-1.0.132.bazel"), + ) + + maybe( + http_archive, + name = "crates_vendor__syn-2.0.87", + sha256 = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d", + type = "tar.gz", + urls = ["https://static.crates.io/crates/syn/2.0.87/download"], + strip_prefix = "syn-2.0.87", + build_file = Label("@proxy_wasm_rust_sdk//bazel/cargo/remote:BUILD.syn-2.0.87.bazel"), + ) + + maybe( + http_archive, + name = "crates_vendor__unicode-ident-1.0.13", + sha256 = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe", + type = "tar.gz", + urls = ["https://static.crates.io/crates/unicode-ident/1.0.13/download"], + strip_prefix = "unicode-ident-1.0.13", + build_file = Label("@proxy_wasm_rust_sdk//bazel/cargo/remote:BUILD.unicode-ident-1.0.13.bazel"), + ) + return [ struct(repo = "crates_vendor__hashbrown-0.15.0", is_dev_dep = False), struct(repo = "crates_vendor__log-0.4.22", is_dev_dep = False), + struct(repo = "crates_vendor__serde-1.0.214", is_dev_dep = True), + struct(repo = "crates_vendor__serde_json-1.0.132", is_dev_dep = True), ]