From ea48e1216ae6972f4ad751320e5208add20d7f62 Mon Sep 17 00:00:00 2001 From: ZhuchkaTriplesix Date: Sun, 15 Nov 2026 12:58:42 +0300 Subject: [PATCH 1/2] feat(rust): keyring secret store for connection passwords (#1878) Wrap keyring-rs (memory backend for tests), persist Postgres passwords outside ProfileStore, and reload them on reconnect after restart. --- apps/tauri/src-tauri/Cargo.lock | 177 +++++++++++++++++- apps/tauri/src-tauri/Cargo.toml | 1 + apps/tauri/src-tauri/src/commands.rs | 18 ++ apps/tauri/src-tauri/src/lib.rs | 3 + apps/tauri/src-tauri/src/secrets/mod.rs | 8 + apps/tauri/src-tauri/src/secrets/store.rs | 214 ++++++++++++++++++++++ apps/tauri/src/stores/connections.ts | 10 +- apps/tauri/src/ui/NewConnectionDialog.vue | 2 +- 8 files changed, 420 insertions(+), 13 deletions(-) create mode 100644 apps/tauri/src-tauri/src/secrets/mod.rs create mode 100644 apps/tauri/src-tauri/src/secrets/store.rs diff --git a/apps/tauri/src-tauri/Cargo.lock b/apps/tauri/src-tauri/Cargo.lock index 6e01866d..08a0a430 100644 --- a/apps/tauri/src-tauri/Cargo.lock +++ b/apps/tauri/src-tauri/Cargo.lock @@ -555,6 +555,16 @@ dependencies = [ "version_check", ] +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "core-foundation" version = "0.10.1" @@ -578,7 +588,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "064badf302c3194842cf2c5d61f56cc88e54a759313879cdf03abdd27d0c3b97" dependencies = [ "bitflags 2.13.2", - "core-foundation", + "core-foundation 0.10.1", "core-graphics-types", "foreign-types", "libc", @@ -591,7 +601,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d44a101f213f6c4cdc1853d4b78aef6db6bdfa3468798cc1d9912f4735013eb" dependencies = [ "bitflags 2.13.2", - "core-foundation", + "core-foundation 0.10.1", "libc", ] @@ -752,6 +762,16 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "dbus-secret-service" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "708b509edf7889e53d7efb0ffadd994cc6c2345ccb62f55cfd6b0682165e4fa6" +dependencies = [ + "dbus", + "zeroize", +] + [[package]] name = "der" version = "0.7.10" @@ -2158,6 +2178,22 @@ dependencies = [ "serde", ] +[[package]] +name = "keyring" +version = "3.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eebcc3aff044e5944a8fbaf69eb277d11986064cba30c468730e8b9909fb551c" +dependencies = [ + "byteorder", + "dbus-secret-service", + "linux-keyutils", + "log", + "security-framework 2.11.1", + "security-framework 3.7.0", + "windows-sys 0.60.2", + "zeroize", +] + [[package]] name = "lazy_static" version = "1.5.1" @@ -2251,6 +2287,16 @@ version = "0.19.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4d9aae57673c1a235149777a74d152f3210ebd3e3b13346d2cdb6809e566bd3c" +[[package]] +name = "linux-keyutils" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83270a18e9f90d0707c41e9f35efada77b64c0e6f3f1810e71c8368a864d5590" +dependencies = [ + "bitflags 2.13.2", + "libc", +] + [[package]] name = "linux-raw-sys" version = "0.12.1" @@ -3101,6 +3147,7 @@ dependencies = [ "chrono", "dirs 5.0.1", "futures-util", + "keyring", "rusqlite", "serde", "serde_json", @@ -3467,6 +3514,42 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags 2.13.2", + "core-foundation 0.9.4", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework" +version = "3.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7f4bc775c73d9a02cde8bf7b2ec4c9d12743edf609006c7facc23998404cd1d" +dependencies = [ + "bitflags 2.13.2", + "core-foundation 0.10.1", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2691df843ecc5d231c0b14ece2acc3efb62c0a398c7e1d875f3983ce020e3" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "selectors" version = "0.38.0" @@ -4204,7 +4287,7 @@ checksum = "d5777b06fe6435126ae8d816eba269e050e1e10d302cf5461e9c49eccabc3548" dependencies = [ "bitflags 2.13.2", "block2", - "core-foundation", + "core-foundation 0.10.1", "core-graphics", "crossbeam-channel", "dbus", @@ -5458,6 +5541,15 @@ dependencies = [ "windows-targets 0.48.5", ] +[[package]] +name = "windows-sys" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" +dependencies = [ + "windows-targets 0.53.5", +] + [[package]] name = "windows-sys" version = "0.61.2" @@ -5497,6 +5589,23 @@ dependencies = [ "windows_x86_64_msvc 0.48.5", ] +[[package]] +name = "windows-targets" +version = "0.53.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3" +dependencies = [ + "windows-link", + "windows_aarch64_gnullvm 0.53.1", + "windows_aarch64_msvc 0.53.1", + "windows_i686_gnu 0.53.1", + "windows_i686_gnullvm", + "windows_i686_msvc 0.53.1", + "windows_x86_64_gnu 0.53.1", + "windows_x86_64_gnullvm 0.53.1", + "windows_x86_64_msvc 0.53.1", +] + [[package]] name = "windows-threading" version = "0.2.1" @@ -5527,6 +5636,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" + [[package]] name = "windows_aarch64_msvc" version = "0.42.2" @@ -5539,6 +5654,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" +[[package]] +name = "windows_aarch64_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" + [[package]] name = "windows_i686_gnu" version = "0.42.2" @@ -5551,6 +5672,18 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" +[[package]] +name = "windows_i686_gnu" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" + [[package]] name = "windows_i686_msvc" version = "0.42.2" @@ -5563,6 +5696,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" +[[package]] +name = "windows_i686_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" + [[package]] name = "windows_x86_64_gnu" version = "0.42.2" @@ -5575,6 +5714,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" +[[package]] +name = "windows_x86_64_gnu" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" + [[package]] name = "windows_x86_64_gnullvm" version = "0.42.2" @@ -5587,6 +5732,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" + [[package]] name = "windows_x86_64_msvc" version = "0.42.2" @@ -5599,6 +5750,12 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" +[[package]] +name = "windows_x86_64_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" + [[package]] name = "winnow" version = "0.5.40" @@ -5842,6 +5999,20 @@ name = "zeroize" version = "1.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e13084392c5e4bc371903e2935a5eaeed24905a7511356b883835e18a78f6879" +dependencies = [ + "zeroize_derive", +] + +[[package]] +name = "zeroize_derive" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c50655cbb0fe3fc43170059e702f1ce5e19b84cec58dc87b037a09935c2f328" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] [[package]] name = "zerotrie" diff --git a/apps/tauri/src-tauri/Cargo.toml b/apps/tauri/src-tauri/Cargo.toml index 7e38207d..5060b3ac 100644 --- a/apps/tauri/src-tauri/Cargo.toml +++ b/apps/tauri/src-tauri/Cargo.toml @@ -30,6 +30,7 @@ sqlx = { version = "0.8", default-features = false, features = [ ] } futures-util = "0.3" chrono = { version = "0.4", default-features = false, features = ["clock", "std"] } +keyring = { version = "3", features = ["apple-native", "windows-native", "linux-native-sync-persistent"] } [profile.release] codegen-units = 1 diff --git a/apps/tauri/src-tauri/src/commands.rs b/apps/tauri/src-tauri/src/commands.rs index 864ac252..f643fe90 100644 --- a/apps/tauri/src-tauri/src/commands.rs +++ b/apps/tauri/src-tauri/src/commands.rs @@ -3,6 +3,7 @@ use crate::connection::{ SchemaObject, SchemaObjectKind, SqlObjectKind, SqlObjectNode, SqliteOverview, TableSchema, }; use crate::profiles::{ConnectionProfile, ProfileStore, ProfileStoreError}; +use crate::secrets::SharedSecretStore; use tauri::ipc::Channel; use tauri::State; @@ -63,7 +64,10 @@ pub fn profiles_upsert( pub fn profiles_delete( id: String, store: State<'_, ProfileStore>, + secrets: State<'_, SharedSecretStore>, ) -> Result { + // Best-effort secret cleanup — profile row is source of truth for "gone". + let _ = secrets.delete_password(&id); store.delete(&id) } @@ -135,6 +139,7 @@ pub fn profiles_connect_postgres( folder_id: Option, id: Option, store: State<'_, ProfileStore>, + secrets: State<'_, SharedSecretStore>, registry: State<'_, ConnectionRegistry>, ) -> Result { let display_name = { @@ -185,6 +190,19 @@ pub fn profiles_connect_postgres( .upsert(&profile) .map_err(|e| ConnectionError::io(e.to_string()))?; + // Resolve password: explicit form value wins; else OS keyring (#1878). + let password = match password { + Some(p) => { + secrets + .set_password(&profile.id, &p) + .map_err(|e| ConnectionError::io(format!("keyring write: {e}")))?; + Some(p) + } + None => secrets + .get_password(&profile.id) + .map_err(|e| ConnectionError::io(format!("keyring read: {e}")))?, + }; + if !registry.is_connected(&ConnectionId::from(profile.id.as_str())) { registry.connect(ConnectionConfig::Postgres { host, diff --git a/apps/tauri/src-tauri/src/lib.rs b/apps/tauri/src-tauri/src/lib.rs index 7b645cae..597c5b8c 100644 --- a/apps/tauri/src-tauri/src/lib.rs +++ b/apps/tauri/src-tauri/src/lib.rs @@ -1,6 +1,7 @@ mod commands; mod connection; mod profiles; +mod secrets; pub use connection::{ ColumnMeta, ConnectionConfig, ConnectionError, ConnectionId, ConnectionManager, @@ -8,6 +9,7 @@ pub use connection::{ SqlObjectKind, SqlObjectNode, SqliteOverview, TableSchema, }; pub use profiles::{ConnectionProfile, ProfileStore, ProfileStoreError}; +pub use secrets::{KeyringSecretStore, MemorySecretStore, SecretError, SecretStore, SharedSecretStore}; use commands::{ db_connect_postgres, db_connect_sqlite, db_describe_object, db_disconnect, db_execute_query, @@ -43,6 +45,7 @@ pub fn run() { .plugin(tauri_plugin_opener::init()) .plugin(tauri_plugin_dialog::init()) .manage(ConnectionRegistry::new()) + .manage(KeyringSecretStore::shared()) .setup(|app| { use tauri::Manager; let store = ProfileStore::open_default().map_err(|e| { diff --git a/apps/tauri/src-tauri/src/secrets/mod.rs b/apps/tauri/src-tauri/src/secrets/mod.rs new file mode 100644 index 00000000..b9237eff --- /dev/null +++ b/apps/tauri/src-tauri/src/secrets/mod.rs @@ -0,0 +1,8 @@ +//! OS keyring for connection secrets (Flutter `ConnectionSecretsStore` parity). +//! Passwords never land in ProfileStore — only here (#1878 / #1847). + +mod store; + +pub use store::{ + KeyringSecretStore, MemorySecretStore, SecretError, SecretStore, SharedSecretStore, +}; diff --git a/apps/tauri/src-tauri/src/secrets/store.rs b/apps/tauri/src-tauri/src/secrets/store.rs new file mode 100644 index 00000000..3d52e665 --- /dev/null +++ b/apps/tauri/src-tauri/src/secrets/store.rs @@ -0,0 +1,214 @@ +//! keyring-rs wrapper keyed by connection profile id. + +use serde::Serialize; +use std::collections::HashMap; +use std::sync::{Arc, Mutex}; + +/// Keyring service id — stable across Querya Tauri builds. +pub const SERVICE: &str = "com.queryahub.querya_tauri"; + +fn password_account(profile_id: &str) -> String { + format!("querya.tauri.v1.conn.{profile_id}.password") +} + +#[derive(Debug, Clone, Serialize)] +#[serde(tag = "kind", rename_all = "snake_case")] +pub enum SecretError { + Invalid { message: String }, + Backend { message: String }, +} + +impl SecretError { + pub fn invalid(message: impl Into) -> Self { + Self::Invalid { + message: message.into(), + } + } + + pub fn backend(message: impl Into) -> Self { + Self::Backend { + message: message.into(), + } + } +} + +impl std::fmt::Display for SecretError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Self::Invalid { message } | Self::Backend { message } => f.write_str(message), + } + } +} + +impl std::error::Error for SecretError {} + +impl From for SecretError { + fn from(value: keyring::Error) -> Self { + Self::backend(value.to_string()) + } +} + +/// Pluggable secret backend (OS keyring in production, memory in tests). +pub trait SecretStore: Send + Sync { + fn set_password(&self, profile_id: &str, password: &str) -> Result<(), SecretError>; + fn get_password(&self, profile_id: &str) -> Result, SecretError>; + fn delete_password(&self, profile_id: &str) -> Result<(), SecretError>; +} + +pub type SharedSecretStore = Arc; + +/// In-memory store for unit tests (never touches the OS keyring). +#[derive(Default)] +pub struct MemorySecretStore { + map: Mutex>, +} + +impl MemorySecretStore { + pub fn new() -> Self { + Self::default() + } + + pub fn shared() -> SharedSecretStore { + Arc::new(Self::new()) + } +} + +impl SecretStore for MemorySecretStore { + fn set_password(&self, profile_id: &str, password: &str) -> Result<(), SecretError> { + let id = profile_id.trim(); + if id.is_empty() { + return Err(SecretError::invalid("profile id is empty")); + } + self.map + .lock() + .map_err(|_| SecretError::backend("secret store lock poisoned"))? + .insert(password_account(id), password.to_owned()); + Ok(()) + } + + fn get_password(&self, profile_id: &str) -> Result, SecretError> { + let id = profile_id.trim(); + if id.is_empty() { + return Err(SecretError::invalid("profile id is empty")); + } + Ok(self + .map + .lock() + .map_err(|_| SecretError::backend("secret store lock poisoned"))? + .get(&password_account(id)) + .cloned()) + } + + fn delete_password(&self, profile_id: &str) -> Result<(), SecretError> { + let id = profile_id.trim(); + if id.is_empty() { + return Err(SecretError::invalid("profile id is empty")); + } + self.map + .lock() + .map_err(|_| SecretError::backend("secret store lock poisoned"))? + .remove(&password_account(id)); + Ok(()) + } +} + +/// OS keyring via `keyring` crate (Keychain / Credential Manager / Secret Service). +pub struct KeyringSecretStore; + +impl KeyringSecretStore { + pub fn new() -> Self { + Self + } + + pub fn shared() -> SharedSecretStore { + Arc::new(Self::new()) + } + + fn entry(profile_id: &str) -> Result { + let id = profile_id.trim(); + if id.is_empty() { + return Err(SecretError::invalid("profile id is empty")); + } + keyring::Entry::new(SERVICE, &password_account(id)).map_err(Into::into) + } +} + +impl Default for KeyringSecretStore { + fn default() -> Self { + Self::new() + } +} + +impl SecretStore for KeyringSecretStore { + fn set_password(&self, profile_id: &str, password: &str) -> Result<(), SecretError> { + Self::entry(profile_id)?.set_password(password)?; + Ok(()) + } + + fn get_password(&self, profile_id: &str) -> Result, SecretError> { + match Self::entry(profile_id)?.get_password() { + Ok(p) => Ok(Some(p)), + Err(keyring::Error::NoEntry) => Ok(None), + Err(e) => Err(e.into()), + } + } + + fn delete_password(&self, profile_id: &str) -> Result<(), SecretError> { + match Self::entry(profile_id)?.delete_credential() { + Ok(()) => Ok(()), + Err(keyring::Error::NoEntry) => Ok(()), + Err(e) => Err(e.into()), + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn memory_round_trip() { + let store = MemorySecretStore::new(); + store.set_password("p1", "s3cret").unwrap(); + assert_eq!(store.get_password("p1").unwrap().as_deref(), Some("s3cret")); + store.delete_password("p1").unwrap(); + assert_eq!(store.get_password("p1").unwrap(), None); + } + + #[test] + fn memory_rejects_empty_id() { + let store = MemorySecretStore::new(); + assert!(matches!( + store.set_password(" ", "x"), + Err(SecretError::Invalid { .. }) + )); + } + + /// Platform keyring — skipped when the OS secret service is unavailable (CI). + #[test] + fn keyring_round_trip_or_skip() { + if std::env::var_os("QUERYA_SKIP_KEYRING").is_some() { + eprintln!("skip keyring live test (QUERYA_SKIP_KEYRING)"); + return; + } + let store = KeyringSecretStore::new(); + let id = format!( + "test-{}", + std::time::SystemTime::now() + .duration_since(std::time::UNIX_EPOCH) + .unwrap() + .as_nanos() + ); + match store.set_password(&id, "roundtrip-secret") { + Ok(()) => {} + Err(e) => { + eprintln!("skip keyring live test: {e}"); + return; + } + } + let got = store.get_password(&id).expect("get"); + assert_eq!(got.as_deref(), Some("roundtrip-secret")); + store.delete_password(&id).expect("delete"); + assert_eq!(store.get_password(&id).unwrap(), None); + } +} diff --git a/apps/tauri/src/stores/connections.ts b/apps/tauri/src/stores/connections.ts index 7bd92de3..ca709e32 100644 --- a/apps/tauri/src/stores/connections.ts +++ b/apps/tauri/src/stores/connections.ts @@ -295,16 +295,8 @@ export const useConnectionsStore = defineStore("connections", () => { id: conn.id, }); } + // Prefer in-memory cache; otherwise Rust loads from OS keyring (#1878). const password = sessionPasswords.get(id) ?? null; - if (!password) { - const status = useShellStatusStore(); - status.setQueryMetrics({ - message: - "Postgres password not in session — reconnect via New Connection (keyring later)", - busy: false, - }); - throw new Error("postgres password required"); - } return connectPostgres({ name: conn.name, host: conn.host ?? "localhost", diff --git a/apps/tauri/src/ui/NewConnectionDialog.vue b/apps/tauri/src/ui/NewConnectionDialog.vue index 40cb2c7c..0ab3c132 100644 --- a/apps/tauri/src/ui/NewConnectionDialog.vue +++ b/apps/tauri/src/ui/NewConnectionDialog.vue @@ -546,7 +546,7 @@ onUnmounted(() => window.removeEventListener("keydown", onKey, true)); />

- Password stays in-session only until OS keyring lands. + Password is stored in the OS keyring (not in the profile database).

{{ error }}

From ac1bb8aed7e181903d06b812a228033e4cb452ef Mon Sep 17 00:00:00 2001 From: ZhuchkaTriplesix Date: Sun, 15 Nov 2026 13:02:53 +0300 Subject: [PATCH 2/2] fix(rust): bundle ConnectPostgresRequest to satisfy clippy -D warnings --- apps/tauri/src-tauri/src/commands.rs | 44 ++++++++++++++----- .../src-tauri/src/connection/postgres.rs | 2 +- apps/tauri/src/api/connection.ts | 18 ++++---- 3 files changed, 45 insertions(+), 19 deletions(-) diff --git a/apps/tauri/src-tauri/src/commands.rs b/apps/tauri/src-tauri/src/commands.rs index f643fe90..10080235 100644 --- a/apps/tauri/src-tauri/src/commands.rs +++ b/apps/tauri/src-tauri/src/commands.rs @@ -4,9 +4,24 @@ use crate::connection::{ }; use crate::profiles::{ConnectionProfile, ProfileStore, ProfileStoreError}; use crate::secrets::SharedSecretStore; +use serde::Deserialize; use tauri::ipc::Channel; use tauri::State; +/// Bundled IPC args for Postgres save+connect (keeps clippy under the limit). +#[derive(Debug, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct ConnectPostgresRequest { + pub name: String, + pub host: String, + pub port: u16, + pub database: String, + pub user: String, + pub password: Option, + pub folder_id: Option, + pub id: Option, +} + #[tauri::command] pub fn db_connect_sqlite( path: String, @@ -130,18 +145,22 @@ pub fn profiles_connect_sqlite( /// Save Postgres profile metadata (no password) and open a live session. #[tauri::command] pub fn profiles_connect_postgres( - name: String, - host: String, - port: u16, - database: String, - user: String, - password: Option, - folder_id: Option, - id: Option, + request: ConnectPostgresRequest, store: State<'_, ProfileStore>, secrets: State<'_, SharedSecretStore>, registry: State<'_, ConnectionRegistry>, ) -> Result { + let ConnectPostgresRequest { + name, + host, + port, + database, + user, + password, + folder_id, + id, + } = request; + let display_name = { let t = name.trim(); if t.is_empty() { @@ -179,8 +198,13 @@ pub fn profiles_connect_postgres( p }), None => { - let mut p = - ConnectionProfile::new_postgres(display_name, host.clone(), port, database.clone(), user.clone()); + let mut p = ConnectionProfile::new_postgres( + display_name, + host.clone(), + port, + database.clone(), + user.clone(), + ); p.folder_id = folder_id; p } diff --git a/apps/tauri/src-tauri/src/connection/postgres.rs b/apps/tauri/src-tauri/src/connection/postgres.rs index 1f5ee17e..dc4d9419 100644 --- a/apps/tauri/src-tauri/src/connection/postgres.rs +++ b/apps/tauri/src-tauri/src/connection/postgres.rs @@ -154,7 +154,7 @@ pub fn open_postgres(params: PostgresConnectParams) -> ConnectionResult { return invoke("profiles_connect_postgres", { - name: opts.name, - host: opts.host, - port: opts.port, - database: opts.database, - user: opts.user, - password: opts.password ?? null, - folderId: opts.folderId ?? null, - id: opts.id ?? null, + request: { + name: opts.name, + host: opts.host, + port: opts.port, + database: opts.database, + user: opts.user, + password: opts.password ?? null, + folderId: opts.folderId ?? null, + id: opts.id ?? null, + }, }); }