[WIP] Encryption for secure values (#183)

This commit is contained in:
Gregory Schier
2025-04-15 07:18:26 -07:00
committed by GitHub
parent e114a85c39
commit 2e55a1bd6d
208 changed files with 4063 additions and 28698 deletions

View File

@@ -9,7 +9,7 @@ use crate::events::{
EmptyPayload, FilterRequest, FilterResponse, GetHttpAuthenticationConfigRequest,
GetHttpAuthenticationConfigResponse, GetHttpAuthenticationSummaryResponse,
GetHttpRequestActionsResponse, GetTemplateFunctionsResponse, ImportRequest, ImportResponse,
InternalEvent, InternalEventPayload, JsonPrimitive, RenderPurpose, WindowContext,
InternalEvent, InternalEventPayload, JsonPrimitive, PluginWindowContext, RenderPurpose,
};
use crate::nodejs::start_nodejs_plugin_runtime;
use crate::plugin_handle::PluginHandle;
@@ -30,6 +30,7 @@ use yaak_models::query_manager::QueryManagerExt;
use yaak_models::util::generate_id;
use yaak_templates::error::Error::RenderError;
use yaak_templates::error::Result as TemplateResult;
use crate::native_template_functions::template_function_secure;
#[derive(Clone)]
pub struct PluginManager {
@@ -100,7 +101,7 @@ impl PluginManager {
Ok(_) => {
info!("Plugin runtime client connected!");
plugin_manager
.initialize_all_plugins(&app_handle, &WindowContext::None)
.initialize_all_plugins(&app_handle, &PluginWindowContext::None)
.await
.expect("Failed to reload plugins");
}
@@ -172,14 +173,14 @@ impl PluginManager {
[bundled_plugin_dirs, installed_plugin_dirs].concat()
}
pub async fn uninstall(&self, window_context: &WindowContext, dir: &str) -> Result<()> {
pub async fn uninstall(&self, window_context: &PluginWindowContext, dir: &str) -> Result<()> {
let plugin = self.get_plugin_by_dir(dir).await.ok_or(PluginNotFoundErr(dir.to_string()))?;
self.remove_plugin(window_context, &plugin).await
}
async fn remove_plugin(
&self,
window_context: &WindowContext,
window_context: &PluginWindowContext,
plugin: &PluginHandle,
) -> Result<()> {
// Terminate the plugin
@@ -197,7 +198,7 @@ impl PluginManager {
pub async fn add_plugin_by_dir(
&self,
window_context: &WindowContext,
window_context: &PluginWindowContext,
dir: &str,
watch: bool,
) -> Result<()> {
@@ -240,7 +241,7 @@ impl PluginManager {
pub async fn initialize_all_plugins<R: Runtime>(
&self,
app_handle: &AppHandle<R>,
window_context: &WindowContext,
window_context: &PluginWindowContext,
) -> Result<()> {
let start = Instant::now();
let candidates = self.list_plugin_dirs(app_handle).await;
@@ -325,7 +326,7 @@ impl PluginManager {
async fn send_to_plugin_and_wait(
&self,
window_context: &WindowContext,
window_context: &PluginWindowContext,
plugin: &PluginHandle,
payload: &InternalEventPayload,
) -> Result<InternalEvent> {
@@ -336,7 +337,7 @@ impl PluginManager {
async fn send_and_wait(
&self,
window_context: &WindowContext,
window_context: &PluginWindowContext,
payload: &InternalEventPayload,
) -> Result<Vec<InternalEvent>> {
let plugins = { self.plugins.lock().await.clone() };
@@ -345,7 +346,7 @@ impl PluginManager {
async fn send_to_plugins_and_wait(
&self,
window_context: &WindowContext,
window_context: &PluginWindowContext,
payload: &InternalEventPayload,
plugins: Vec<PluginHandle>,
) -> Result<Vec<InternalEvent>> {
@@ -408,7 +409,7 @@ impl PluginManager {
) -> Result<Vec<GetHttpRequestActionsResponse>> {
let reply_events = self
.send_and_wait(
&WindowContext::from_window(window),
&PluginWindowContext::new(window),
&InternalEventPayload::GetHttpRequestActionsRequest(EmptyPayload {}),
)
.await?;
@@ -427,25 +428,31 @@ impl PluginManager {
&self,
window: &WebviewWindow<R>,
) -> Result<Vec<GetTemplateFunctionsResponse>> {
self.get_template_functions_with_context(&WindowContext::from_window(window)).await
self.get_template_functions_with_context(&PluginWindowContext::new(&window)).await
}
pub async fn get_template_functions_with_context(
&self,
window_context: &WindowContext,
window_context: &PluginWindowContext,
) -> Result<Vec<GetTemplateFunctionsResponse>> {
let reply_events = self
.send_and_wait(window_context, &InternalEventPayload::GetTemplateFunctionsRequest)
.await?;
let mut all_actions = Vec::new();
let mut result = Vec::new();
for event in reply_events {
if let InternalEventPayload::GetTemplateFunctionsResponse(resp) = event.payload {
all_actions.push(resp.clone());
result.push(resp.clone());
}
}
Ok(all_actions)
// Add Rust-based functions
result.push(GetTemplateFunctionsResponse {
plugin_ref_id: "__NATIVE__".to_string(), // Meh
functions: vec![template_function_secure()],
});
Ok(result)
}
pub async fn call_http_request_action<R: Runtime>(
@@ -457,7 +464,7 @@ impl PluginManager {
let plugin =
self.get_plugin_by_ref_id(ref_id.as_str()).await.ok_or(PluginNotFoundErr(ref_id))?;
let event = plugin.build_event_to_send(
&WindowContext::from_window(window),
&PluginWindowContext::new(window),
&InternalEventPayload::CallHttpRequestActionRequest(req),
None,
);
@@ -469,7 +476,7 @@ impl PluginManager {
&self,
window: &WebviewWindow<R>,
) -> Result<Vec<(PluginHandle, GetHttpAuthenticationSummaryResponse)>> {
let window_context = WindowContext::from_window(window);
let window_context = PluginWindowContext::new(window);
let reply_events = self
.send_and_wait(
&window_context,
@@ -508,7 +515,7 @@ impl PluginManager {
let context_id = format!("{:x}", md5::compute(request_id.to_string()));
let event = self
.send_to_plugin_and_wait(
&WindowContext::from_window(window),
&PluginWindowContext::new(window),
&plugin,
&InternalEventPayload::GetHttpAuthenticationConfigRequest(
GetHttpAuthenticationConfigRequest { values, context_id },
@@ -540,7 +547,7 @@ impl PluginManager {
let context_id = format!("{:x}", md5::compute(request_id.to_string()));
self.send_to_plugin_and_wait(
&WindowContext::from_window(window),
&PluginWindowContext::new(window),
&plugin,
&InternalEventPayload::CallHttpAuthenticationActionRequest(
CallHttpAuthenticationActionRequest {
@@ -581,7 +588,7 @@ impl PluginManager {
let event = self
.send_to_plugin_and_wait(
&WindowContext::from_window(window),
&PluginWindowContext::new(window),
&plugin,
&InternalEventPayload::CallHttpAuthenticationRequest(req),
)
@@ -597,7 +604,7 @@ impl PluginManager {
pub async fn call_template_function(
&self,
window_context: &WindowContext,
window_context: &PluginWindowContext,
fn_name: &str,
args: HashMap<String, String>,
purpose: RenderPurpose,
@@ -636,7 +643,7 @@ impl PluginManager {
) -> Result<ImportResponse> {
let reply_events = self
.send_and_wait(
&WindowContext::from_window(window),
&PluginWindowContext::new(window),
&InternalEventPayload::ImportRequest(ImportRequest {
content: content.to_string(),
}),
@@ -675,7 +682,7 @@ impl PluginManager {
let event = self
.send_to_plugin_and_wait(
&WindowContext::from_window(window),
&PluginWindowContext::new(window),
&plugin,
&InternalEventPayload::FilterRequest(FilterRequest {
filter: filter.to_string(),