Skip to content

Commit

Permalink
feat: proxywasm secret methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ruslanti committed Oct 22, 2024
1 parent 92feb17 commit 4bdd8d1
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
43 changes: 43 additions & 0 deletions src/proxywasm.rs
Original file line number Diff line number Diff line change
@@ -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<Option<Vec<u8>>, 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),
}
}
}
}

0 comments on commit 4bdd8d1

Please sign in to comment.