diff --git a/src/lib.rs b/src/lib.rs index 8aae5f6..da433a0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,6 +16,8 @@ use crate::gcore::fastedge::http::{Error as HttpError, Method, Request, Response /// Implementation of Outbound HTTP component mod http_client; +/// FastEdge ProxyWasm module extension +pub mod proxywasm; pub mod wasi_nn { #![allow(missing_docs)] diff --git a/src/proxywasm.rs b/src/proxywasm.rs new file mode 100644 index 0000000..8e58ea0 --- /dev/null +++ b/src/proxywasm.rs @@ -0,0 +1,43 @@ +extern "C" { + fn proxy_get_secret( + key_data: *const u8, + key_size: usize, + return_value_data: *mut *mut u8, + return_value_size: *mut usize, + ) -> u32; +} + +/// ProxyWasm secret interface +pub mod secret { + use crate::proxywasm::proxy_get_secret; + use std::ptr::null_mut; + + /// Get secret method. + /// return None if secret not found for given key + pub fn get(key: &str) -> Result>, u32> { + let mut return_data: *mut u8 = null_mut(); + let mut return_size: usize = 0; + unsafe { + match proxy_get_secret( + key.as_ptr(), + key.len(), + &mut return_data, + &mut return_size, + ) { + 0 => { + if !return_data.is_null() { + Ok(Some(Vec::from_raw_parts( + return_data, + return_size, + return_size, + ))) + } else { + Ok(None) + } + } + 1 => Ok(None), + status => panic!("unexpected status: {}", status), + } + } + } +} \ No newline at end of file