mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-26 03:11:12 +01:00
Fix authentication actions being called with unrendered args
This commit is contained in:
@@ -7,7 +7,7 @@ use crate::http_request::{resolve_http_request, send_http_request};
|
|||||||
use crate::import::import_data;
|
use crate::import::import_data;
|
||||||
use crate::models_ext::{BlobManagerExt, QueryManagerExt};
|
use crate::models_ext::{BlobManagerExt, QueryManagerExt};
|
||||||
use crate::notifications::YaakNotifier;
|
use crate::notifications::YaakNotifier;
|
||||||
use crate::render::{render_grpc_request, render_template};
|
use crate::render::{render_grpc_request, render_json_value, render_template};
|
||||||
use crate::updates::{UpdateMode, UpdateTrigger, YaakUpdater};
|
use crate::updates::{UpdateMode, UpdateTrigger, YaakUpdater};
|
||||||
use crate::uri_scheme::handle_deep_link;
|
use crate::uri_scheme::handle_deep_link;
|
||||||
use error::Result as YaakResult;
|
use error::Result as YaakResult;
|
||||||
@@ -1057,14 +1057,54 @@ async fn cmd_get_http_authentication_summaries<R: Runtime>(
|
|||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn cmd_get_http_authentication_config<R: Runtime>(
|
async fn cmd_get_http_authentication_config<R: Runtime>(
|
||||||
window: WebviewWindow<R>,
|
window: WebviewWindow<R>,
|
||||||
|
app_handle: AppHandle<R>,
|
||||||
plugin_manager: State<'_, PluginManager>,
|
plugin_manager: State<'_, PluginManager>,
|
||||||
|
encryption_manager: State<'_, EncryptionManager>,
|
||||||
auth_name: &str,
|
auth_name: &str,
|
||||||
values: HashMap<String, JsonPrimitive>,
|
values: HashMap<String, JsonPrimitive>,
|
||||||
model: AnyModel,
|
model: AnyModel,
|
||||||
_environment_id: Option<&str>,
|
environment_id: Option<&str>,
|
||||||
) -> YaakResult<GetHttpAuthenticationConfigResponse> {
|
) -> YaakResult<GetHttpAuthenticationConfigResponse> {
|
||||||
|
// Extract workspace_id and folder_id from the model to resolve the environment chain
|
||||||
|
let (workspace_id, folder_id) = match &model {
|
||||||
|
AnyModel::HttpRequest(r) => (r.workspace_id.clone(), r.folder_id.clone()),
|
||||||
|
AnyModel::GrpcRequest(r) => (r.workspace_id.clone(), r.folder_id.clone()),
|
||||||
|
AnyModel::WebsocketRequest(r) => (r.workspace_id.clone(), r.folder_id.clone()),
|
||||||
|
AnyModel::Folder(f) => (f.workspace_id.clone(), f.folder_id.clone()),
|
||||||
|
AnyModel::Workspace(w) => (w.id.clone(), None),
|
||||||
|
_ => return Err(GenericError("Unsupported model type for authentication config".into())),
|
||||||
|
};
|
||||||
|
|
||||||
|
// Resolve environment chain and render the values for token lookup
|
||||||
|
let environment_chain = app_handle.db().resolve_environments(
|
||||||
|
&workspace_id,
|
||||||
|
folder_id.as_deref(),
|
||||||
|
environment_id,
|
||||||
|
)?;
|
||||||
|
let plugin_manager_arc = Arc::new((*plugin_manager).clone());
|
||||||
|
let encryption_manager_arc = Arc::new((*encryption_manager).clone());
|
||||||
|
let cb = PluginTemplateCallback::new(
|
||||||
|
plugin_manager_arc,
|
||||||
|
encryption_manager_arc,
|
||||||
|
&window.plugin_context(),
|
||||||
|
RenderPurpose::Preview,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Convert HashMap<String, JsonPrimitive> to serde_json::Value for rendering
|
||||||
|
let values_json: serde_json::Value = serde_json::to_value(&values)?;
|
||||||
|
let rendered_json =
|
||||||
|
render_json_value(values_json, environment_chain, &cb, &RenderOptions::throw()).await?;
|
||||||
|
|
||||||
|
// Convert back to HashMap<String, JsonPrimitive>
|
||||||
|
let rendered_values: HashMap<String, JsonPrimitive> = serde_json::from_value(rendered_json)?;
|
||||||
|
|
||||||
Ok(plugin_manager
|
Ok(plugin_manager
|
||||||
.get_http_authentication_config(&window.plugin_context(), auth_name, values, model.id())
|
.get_http_authentication_config(
|
||||||
|
&window.plugin_context(),
|
||||||
|
auth_name,
|
||||||
|
rendered_values,
|
||||||
|
model.id(),
|
||||||
|
)
|
||||||
.await?)
|
.await?)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1111,19 +1151,54 @@ async fn cmd_call_grpc_request_action<R: Runtime>(
|
|||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn cmd_call_http_authentication_action<R: Runtime>(
|
async fn cmd_call_http_authentication_action<R: Runtime>(
|
||||||
window: WebviewWindow<R>,
|
window: WebviewWindow<R>,
|
||||||
|
app_handle: AppHandle<R>,
|
||||||
plugin_manager: State<'_, PluginManager>,
|
plugin_manager: State<'_, PluginManager>,
|
||||||
|
encryption_manager: State<'_, EncryptionManager>,
|
||||||
auth_name: &str,
|
auth_name: &str,
|
||||||
action_index: i32,
|
action_index: i32,
|
||||||
values: HashMap<String, JsonPrimitive>,
|
values: HashMap<String, JsonPrimitive>,
|
||||||
model: AnyModel,
|
model: AnyModel,
|
||||||
_environment_id: Option<&str>,
|
environment_id: Option<&str>,
|
||||||
) -> YaakResult<()> {
|
) -> YaakResult<()> {
|
||||||
|
// Extract workspace_id and folder_id from the model to resolve the environment chain
|
||||||
|
let (workspace_id, folder_id) = match &model {
|
||||||
|
AnyModel::HttpRequest(r) => (r.workspace_id.clone(), r.folder_id.clone()),
|
||||||
|
AnyModel::GrpcRequest(r) => (r.workspace_id.clone(), r.folder_id.clone()),
|
||||||
|
AnyModel::WebsocketRequest(r) => (r.workspace_id.clone(), r.folder_id.clone()),
|
||||||
|
AnyModel::Folder(f) => (f.workspace_id.clone(), f.folder_id.clone()),
|
||||||
|
AnyModel::Workspace(w) => (w.id.clone(), None),
|
||||||
|
_ => return Err(GenericError("Unsupported model type for authentication action".into())),
|
||||||
|
};
|
||||||
|
|
||||||
|
// Resolve environment chain and render the values
|
||||||
|
let environment_chain = app_handle.db().resolve_environments(
|
||||||
|
&workspace_id,
|
||||||
|
folder_id.as_deref(),
|
||||||
|
environment_id,
|
||||||
|
)?;
|
||||||
|
let plugin_manager_arc = Arc::new((*plugin_manager).clone());
|
||||||
|
let encryption_manager_arc = Arc::new((*encryption_manager).clone());
|
||||||
|
let cb = PluginTemplateCallback::new(
|
||||||
|
plugin_manager_arc,
|
||||||
|
encryption_manager_arc,
|
||||||
|
&window.plugin_context(),
|
||||||
|
RenderPurpose::Send,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Convert HashMap<String, JsonPrimitive> to serde_json::Value for rendering
|
||||||
|
let values_json: serde_json::Value = serde_json::to_value(&values)?;
|
||||||
|
let rendered_json =
|
||||||
|
render_json_value(values_json, environment_chain, &cb, &RenderOptions::throw()).await?;
|
||||||
|
|
||||||
|
// Convert back to HashMap<String, JsonPrimitive>
|
||||||
|
let rendered_values: HashMap<String, JsonPrimitive> = serde_json::from_value(rendered_json)?;
|
||||||
|
|
||||||
Ok(plugin_manager
|
Ok(plugin_manager
|
||||||
.call_http_authentication_action(
|
.call_http_authentication_action(
|
||||||
&window.plugin_context(),
|
&window.plugin_context(),
|
||||||
auth_name,
|
auth_name,
|
||||||
action_index,
|
action_index,
|
||||||
values,
|
rendered_values,
|
||||||
&model.id(),
|
&model.id(),
|
||||||
)
|
)
|
||||||
.await?)
|
.await?)
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ export type CookieExpires = { "AtUtc": string } | "SessionEnd";
|
|||||||
|
|
||||||
export type CookieJar = { model: "cookie_jar", id: string, createdAt: string, updatedAt: string, workspaceId: string, cookies: Array<Cookie>, name: string, };
|
export type CookieJar = { model: "cookie_jar", id: string, createdAt: string, updatedAt: string, workspaceId: string, cookies: Array<Cookie>, name: string, };
|
||||||
|
|
||||||
|
export type DnsOverride = { hostname: string, ipv4: Array<string>, ipv6: Array<string>, enabled?: boolean, };
|
||||||
|
|
||||||
export type EditorKeymap = "default" | "vim" | "vscode" | "emacs";
|
export type EditorKeymap = "default" | "vim" | "vscode" | "emacs";
|
||||||
|
|
||||||
export type EncryptedKey = { encryptedKey: string, };
|
export type EncryptedKey = { encryptedKey: string, };
|
||||||
@@ -77,6 +79,6 @@ export type WebsocketEventType = "binary" | "close" | "frame" | "open" | "ping"
|
|||||||
|
|
||||||
export type WebsocketRequest = { model: "websocket_request", id: string, createdAt: string, updatedAt: string, workspaceId: string, folderId: string | null, authentication: Record<string, any>, authenticationType: string | null, description: string, headers: Array<HttpRequestHeader>, message: string, name: string, sortPriority: number, url: string, urlParameters: Array<HttpUrlParameter>, };
|
export type WebsocketRequest = { model: "websocket_request", id: string, createdAt: string, updatedAt: string, workspaceId: string, folderId: string | null, authentication: Record<string, any>, authenticationType: string | null, description: string, headers: Array<HttpRequestHeader>, message: string, name: string, sortPriority: number, url: string, urlParameters: Array<HttpUrlParameter>, };
|
||||||
|
|
||||||
export type Workspace = { model: "workspace", id: string, createdAt: string, updatedAt: string, authentication: Record<string, any>, authenticationType: string | null, description: string, headers: Array<HttpRequestHeader>, name: string, encryptionKeyChallenge: string | null, settingValidateCertificates: boolean, settingFollowRedirects: boolean, settingRequestTimeout: number, };
|
export type Workspace = { model: "workspace", id: string, createdAt: string, updatedAt: string, authentication: Record<string, any>, authenticationType: string | null, description: string, headers: Array<HttpRequestHeader>, name: string, encryptionKeyChallenge: string | null, settingValidateCertificates: boolean, settingFollowRedirects: boolean, settingRequestTimeout: number, settingDnsOverrides: Array<DnsOverride>, };
|
||||||
|
|
||||||
export type WorkspaceMeta = { model: "workspace_meta", id: string, workspaceId: string, createdAt: string, updatedAt: string, encryptionKey: EncryptedKey | null, settingSyncDir: string | null, };
|
export type WorkspaceMeta = { model: "workspace_meta", id: string, workspaceId: string, createdAt: string, updatedAt: string, encryptionKey: EncryptedKey | null, settingSyncDir: string | null, };
|
||||||
|
|||||||
Reference in New Issue
Block a user