feat(plugin): add plugin framework workflow
This commit is contained in:
247 files changed
+33841
-2256
No files matched your search
@@ -20,6 +20,9 @@ system-fonts = ["font-kit"]
|
||||
[dependencies]
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = { version = "1.0", features = ["arbitrary_precision", "preserve_order"] }
|
||||
semver = "1"
|
||||
ed25519-dalek = "2"
|
||||
fs2 = "0.4"
|
||||
utoipa = { version = "5.5", optional = true }
|
||||
unicode-width = "0.2"
|
||||
unicode-ident = "1"
|
||||
|
||||
@@ -2850,6 +2850,35 @@
|
||||
"userAdmin": false,
|
||||
"driverManagement": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"dbType": "plugin",
|
||||
"label": "Plugin",
|
||||
"runtimeMode": "external",
|
||||
"mcpMode": "unsupported",
|
||||
"singleConnectionPool": false,
|
||||
"metadataConnectionScoped": false,
|
||||
"skipTcpProbe": true,
|
||||
"supportLevel": "connect",
|
||||
"specializedSurface": true,
|
||||
"capabilities": {
|
||||
"queryExecution": false,
|
||||
"metadataBrowse": false,
|
||||
"objectBrowser": false,
|
||||
"objectSource": false,
|
||||
"schemaSearch": false,
|
||||
"diagram": false,
|
||||
"tableDataEdit": false,
|
||||
"tableStructureEdit": false,
|
||||
"tableImport": false,
|
||||
"dataTransfer": false,
|
||||
"sqlFileExecution": false,
|
||||
"databaseCreate": false,
|
||||
"fieldLineage": false,
|
||||
"sqlExplain": false,
|
||||
"userAdmin": false,
|
||||
"driverManagement": false
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
use dbx_core::plugins::{
|
||||
PluginMarketplace, PluginMarketplaceInstallRequest, PluginSignatureStatus, OFFICIAL_PLUGIN_REPOSITORY_ID,
|
||||
};
|
||||
|
||||
const APP_VERSION: &str = "0.5.68";
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
if let Err(error) = run().await {
|
||||
eprintln!("plugin marketplace smoke failed: {error}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
async fn run() -> Result<(), String> {
|
||||
let store = tempfile::tempdir().map_err(|error| error.to_string())?;
|
||||
let marketplace = PluginMarketplace::new(store.path().to_path_buf(), APP_VERSION)?;
|
||||
let results = marketplace.fetch_catalogs().await;
|
||||
let official = results
|
||||
.iter()
|
||||
.find(|result| result.repository.id == OFFICIAL_PLUGIN_REPOSITORY_ID)
|
||||
.ok_or("Official DBX Marketplace result is missing")?;
|
||||
if let Some(error) = &official.error {
|
||||
return Err(error.clone());
|
||||
}
|
||||
let catalog = official.catalog.as_ref().ok_or("Official DBX Marketplace catalog is missing")?;
|
||||
let mut arguments = std::env::args().skip(1);
|
||||
let Some(plugin_id) = arguments.next() else {
|
||||
println!("plugin marketplace smoke passed: fetched {} official catalog entries", catalog.plugins.len());
|
||||
return Ok(());
|
||||
};
|
||||
let version = arguments.next();
|
||||
if arguments.next().is_some() {
|
||||
return Err("Usage: plugin_marketplace_smoke [plugin-id] [version]".to_string());
|
||||
}
|
||||
if !catalog.plugins.iter().any(|plugin| plugin.id == plugin_id) {
|
||||
return Err(format!("Official DBX Marketplace does not list '{plugin_id}'"));
|
||||
}
|
||||
let installed = marketplace
|
||||
.install(PluginMarketplaceInstallRequest {
|
||||
repository_id: OFFICIAL_PLUGIN_REPOSITORY_ID.to_string(),
|
||||
plugin_id: plugin_id.clone(),
|
||||
version,
|
||||
})
|
||||
.await?;
|
||||
if installed.plugin.manifest.id != plugin_id {
|
||||
return Err(format!("Expected plugin '{plugin_id}', got '{}'", installed.plugin.manifest.id));
|
||||
}
|
||||
match installed.signature {
|
||||
PluginSignatureStatus::Trusted { key_id } => {
|
||||
println!("plugin marketplace smoke passed: catalog -> release download -> sha256 -> signature {key_id} -> install");
|
||||
}
|
||||
signature => return Err(format!("Unexpected marketplace signature status: {signature:?}")),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
use std::collections::BTreeMap;
|
||||
use std::path::PathBuf;
|
||||
use std::time::Duration;
|
||||
|
||||
use dbx_core::models::connection::ConnectionConfig;
|
||||
use dbx_core::plugins::{PluginHost, PluginInstallPolicy, PluginPackageInstaller, PluginRegistry, PluginTrustStore};
|
||||
use serde_json::{json, Value};
|
||||
|
||||
const PLUGIN_ID: &str = "dbx.example.hello";
|
||||
const APP_VERSION: &str = "0.5.68";
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
if let Err(error) = run().await {
|
||||
eprintln!("plugin package smoke failed: {error}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
async fn run() -> Result<(), String> {
|
||||
let package = std::env::args().nth(1).map(PathBuf::from).ok_or("Usage: plugin_package_smoke <package.dbxp>")?;
|
||||
let store = tempfile::tempdir().map_err(|error| error.to_string())?;
|
||||
let trusted_keys = std::env::var("DBX_PLUGIN_SMOKE_TRUSTED_KEYS_JSON")
|
||||
.ok()
|
||||
.map(|raw| serde_json::from_str::<BTreeMap<String, String>>(&raw).map_err(|error| error.to_string()))
|
||||
.transpose()?;
|
||||
let (installer, policy) = match trusted_keys {
|
||||
Some(keys) => (
|
||||
PluginPackageInstaller::with_trust_store(
|
||||
store.path().to_path_buf(),
|
||||
APP_VERSION.to_string(),
|
||||
PluginTrustStore::from_base64_keys(keys)?,
|
||||
),
|
||||
PluginInstallPolicy::LocalSigned,
|
||||
),
|
||||
None => (
|
||||
PluginPackageInstaller::new(store.path().to_path_buf(), APP_VERSION.to_string())?,
|
||||
PluginInstallPolicy::LocalDevelopment,
|
||||
),
|
||||
};
|
||||
let installed = installer.install_file(&package, policy)?;
|
||||
if installed.plugin.manifest.id != PLUGIN_ID {
|
||||
return Err(format!("Expected plugin '{PLUGIN_ID}', got '{}'", installed.plugin.manifest.id));
|
||||
}
|
||||
|
||||
let registry = PluginRegistry::new_with_app_version(store.path().to_path_buf(), APP_VERSION);
|
||||
let plugin_icon = installed.plugin.manifest.icon.as_deref().ok_or("Example plugin does not declare an icon")?;
|
||||
let provider_icon = installed
|
||||
.plugin
|
||||
.manifest
|
||||
.connection_provider("dbx.example.hello.connection")?
|
||||
.and_then(|provider| provider.icon)
|
||||
.ok_or("Example connection provider does not declare an icon")?;
|
||||
for icon in [plugin_icon, provider_icon.as_str()] {
|
||||
let asset = registry.read_asset(PLUGIN_ID, icon)?;
|
||||
if !asset.content_type.starts_with("image/") || asset.bytes.is_empty() {
|
||||
return Err(format!("Invalid packaged plugin icon '{icon}'"));
|
||||
}
|
||||
}
|
||||
let host = PluginHost::new(registry);
|
||||
let mut events = host.subscribe_events();
|
||||
let config: ConnectionConfig = serde_json::from_value(json!({
|
||||
"id": "hello-smoke-connection",
|
||||
"name": "Hello smoke connection",
|
||||
"db_type": "plugin",
|
||||
"driver_profile": "plugin",
|
||||
"host": "localhost",
|
||||
"port": 22,
|
||||
"username": "",
|
||||
"password": "",
|
||||
"database": null,
|
||||
"external_config": { "greeting": "Hello" },
|
||||
"plugin_id": PLUGIN_ID,
|
||||
"plugin_connection_provider": "dbx.example.hello.connection",
|
||||
"plugin_connection_type": "hello",
|
||||
"connection_secrets": { "api_token": "smoke-secret" }
|
||||
}))
|
||||
.map_err(|error| error.to_string())?;
|
||||
|
||||
let test = host.test_connection(&config, "localhost", 22).await?;
|
||||
if !test.message.contains("localhost:22") {
|
||||
return Err(format!("Unexpected connection-test result: {}", test.message));
|
||||
}
|
||||
|
||||
let action = host.invoke_connection_action(&config, "suggest-greeting", "localhost", 22).await?;
|
||||
if action.message.as_deref() != Some("Greeting updated by the plugin action.")
|
||||
|| action.field_values.get("greeting").and_then(Value::as_str) != Some("Hello from plugin action")
|
||||
{
|
||||
return Err(format!("Unexpected connection-action result: {action:?}"));
|
||||
}
|
||||
|
||||
let handle = host.connect_connection(&config, "localhost", 22).await?;
|
||||
if !handle.is_running() {
|
||||
return Err("Plugin connection handle is not running".to_string());
|
||||
}
|
||||
let greeting: Value = host
|
||||
.invoke(
|
||||
PLUGIN_ID,
|
||||
"hello/greet",
|
||||
json!({ "connectionId": config.id, "name": "Smoke" }),
|
||||
None,
|
||||
Some(Duration::from_secs(5)),
|
||||
)
|
||||
.await?;
|
||||
if greeting.get("message").and_then(Value::as_str) != Some("Hello, Smoke, from Hello smoke connection!") {
|
||||
return Err(format!("Unexpected greeting: {greeting}"));
|
||||
}
|
||||
let files = host
|
||||
.list_filesystem_entries(
|
||||
PLUGIN_ID,
|
||||
"dbx.example.hello.files",
|
||||
Some(&config.id),
|
||||
Some("hello:/"),
|
||||
None,
|
||||
Some(20),
|
||||
)
|
||||
.await?;
|
||||
if !files.entries.iter().any(|entry| entry.name == "README.txt") {
|
||||
return Err(format!("Unexpected filesystem listing: {files:?}"));
|
||||
}
|
||||
let preview = host
|
||||
.read_filesystem_file(PLUGIN_ID, "dbx.example.hello.files", Some(&config.id), "hello:/README.txt", Some(1024))
|
||||
.await?;
|
||||
if preview.truncated || preview.data_base64.is_empty() {
|
||||
return Err(format!("Unexpected filesystem preview: {preview:?}"));
|
||||
}
|
||||
|
||||
let mut saw_connected = false;
|
||||
let mut saw_finished = false;
|
||||
for _ in 0..4 {
|
||||
let event = tokio::time::timeout(Duration::from_secs(2), events.recv())
|
||||
.await
|
||||
.map_err(|_| "Timed out waiting for plugin events".to_string())?
|
||||
.map_err(|error| error.to_string())?;
|
||||
if event.method == "hello/connectionChanged"
|
||||
&& event.params.get("state").and_then(Value::as_str) == Some("connected")
|
||||
{
|
||||
saw_connected = true;
|
||||
}
|
||||
if event.method == "hello/progress" && event.params.get("stage").and_then(Value::as_str) == Some("finished") {
|
||||
saw_finished = true;
|
||||
}
|
||||
if saw_connected && saw_finished {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if !saw_connected || !saw_finished {
|
||||
return Err(format!("Missing expected events: connected={saw_connected}, finished={saw_finished}"));
|
||||
}
|
||||
|
||||
handle.disconnect().await?;
|
||||
host.stop_all().await;
|
||||
installer.uninstall(PLUGIN_ID)?;
|
||||
if !PluginRegistry::new_with_app_version(store.path().to_path_buf(), APP_VERSION).list_installed()?.is_empty() {
|
||||
return Err("Plugin store is not empty after uninstall".to_string());
|
||||
}
|
||||
|
||||
println!("plugin package smoke passed: install -> assets -> action -> test -> connect -> invoke -> filesystem -> events -> disconnect -> uninstall");
|
||||
Ok(())
|
||||
}
|
||||
@@ -204,6 +204,10 @@ fn connection_config(id: &str, database: BenchDatabase) -> Result<ConnectionConf
|
||||
gbase_server: String::new(),
|
||||
informix_server: String::new(),
|
||||
external_config: None,
|
||||
plugin_id: None,
|
||||
plugin_connection_provider: None,
|
||||
plugin_connection_type: None,
|
||||
connection_secrets: Default::default(),
|
||||
jdbc_driver_class: None,
|
||||
jdbc_driver_paths: Vec::new(),
|
||||
one_time: false,
|
||||
|
||||
@@ -763,6 +763,10 @@ mod tests {
|
||||
gbase_server: String::new(),
|
||||
informix_server: String::new(),
|
||||
external_config: None,
|
||||
plugin_id: None,
|
||||
plugin_connection_provider: None,
|
||||
plugin_connection_type: None,
|
||||
connection_secrets: Default::default(),
|
||||
jdbc_driver_class: None,
|
||||
jdbc_driver_paths: Vec::new(),
|
||||
one_time: false,
|
||||
|
||||
@@ -190,13 +190,12 @@ mod tests {
|
||||
permissions.set_mode(0o755);
|
||||
std::fs::set_permissions(&executable, permissions).unwrap();
|
||||
|
||||
let plugin = InstalledPlugin {
|
||||
manifest: PluginManifest {
|
||||
let plugin = InstalledPlugin::new(
|
||||
PluginManifest {
|
||||
id: "jdbc".to_string(),
|
||||
name: "JDBC".to_string(),
|
||||
version: "test".to_string(),
|
||||
protocol_version: 1,
|
||||
description: String::new(),
|
||||
executable: Some("plugin.sh".to_string()),
|
||||
drivers: vec![PluginDriverManifest {
|
||||
id: "jdbc".to_string(),
|
||||
@@ -204,9 +203,11 @@ mod tests {
|
||||
kind: "external".to_string(),
|
||||
database_type: Some("jdbc".to_string()),
|
||||
}],
|
||||
..PluginManifest::default()
|
||||
},
|
||||
path: dir.clone(),
|
||||
};
|
||||
dir.clone(),
|
||||
env!("CARGO_PKG_VERSION"),
|
||||
);
|
||||
let session = Arc::new(
|
||||
PluginDriverSession::start_for_test(plugin, "jdbc".to_string(), PluginRuntimeEnv::default()).await.unwrap(),
|
||||
);
|
||||
|
||||
@@ -1490,6 +1490,10 @@ for line in sys.stdin:
|
||||
gbase_server: String::new(),
|
||||
informix_server: String::new(),
|
||||
external_config: None,
|
||||
plugin_id: None,
|
||||
plugin_connection_provider: None,
|
||||
plugin_connection_type: None,
|
||||
connection_secrets: Default::default(),
|
||||
jdbc_driver_class: None,
|
||||
jdbc_driver_paths: Vec::new(),
|
||||
one_time: false,
|
||||
|
||||
@@ -15,7 +15,7 @@ use crate::ai::AiConfigItem;
|
||||
use crate::connection_secrets::{
|
||||
CASSANDRA_KEYSTORE_PASSWORD_KEY, CASSANDRA_TRUSTSTORE_PASSWORD_KEY, MQ_AUTH_API_KEY_VALUE_KEY,
|
||||
MQ_AUTH_CLIENT_SECRET_KEY, MQ_AUTH_PASSWORD_KEY, MQ_AUTH_TOKEN_KEY, MQ_TOKEN_SIGNING_KEY, NACOS_AUTH_PASSWORD_KEY,
|
||||
NACOS_RNACOS_CONSOLE_PASSWORD_KEY,
|
||||
NACOS_RNACOS_CONSOLE_PASSWORD_KEY, PLUGIN_CONNECTION_SECRET_PREFIX,
|
||||
};
|
||||
use crate::models::connection::{ConnectionConfig, DatabaseType, TransportLayerConfig};
|
||||
use crate::saved_sql::SavedSqlLibrary;
|
||||
@@ -973,6 +973,7 @@ fn scrub_connection_secrets(config: &mut ConnectionConfig) {
|
||||
scrub_mq_external_config_secrets(config);
|
||||
scrub_nacos_auth_secrets(config);
|
||||
scrub_cassandra_tls_secrets(config);
|
||||
config.connection_secrets.clear();
|
||||
}
|
||||
|
||||
fn scrub_mqtt_auth_secrets(config: &mut ConnectionConfig) {
|
||||
@@ -1008,6 +1009,14 @@ async fn build_sensitive_payload(
|
||||
if config.save_password {
|
||||
push_secret(&mut connection_secrets, &config.id, "password", &config.password);
|
||||
}
|
||||
for (key, secret) in &config.connection_secrets {
|
||||
push_secret(
|
||||
&mut connection_secrets,
|
||||
&config.id,
|
||||
&format!("{PLUGIN_CONNECTION_SECRET_PREFIX}{key}"),
|
||||
secret,
|
||||
);
|
||||
}
|
||||
push_secret(&mut connection_secrets, &config.id, "init_script", config.init_script.as_deref().unwrap_or(""));
|
||||
for (index, layer) in config.transport_layers.iter().enumerate() {
|
||||
match layer {
|
||||
@@ -1225,6 +1234,7 @@ async fn apply_sensitive_payload(
|
||||
if !SECRET_KEYS.contains(&secret.key.as_str())
|
||||
&& !secret.key.starts_with(SSH_TUNNEL_SECRET_PREFIX)
|
||||
&& !secret.key.starts_with(TRANSPORT_LAYER_SECRET_PREFIX)
|
||||
&& !secret.key.starts_with(PLUGIN_CONNECTION_SECRET_PREFIX)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -1264,6 +1274,7 @@ async fn clear_connection_secrets(storage: &Storage, connections: &[ConnectionCo
|
||||
for key in SECRET_KEYS {
|
||||
storage.delete_secret(&config.id, key).await?;
|
||||
}
|
||||
storage.delete_secret_prefix(&config.id, PLUGIN_CONNECTION_SECRET_PREFIX).await?;
|
||||
for (index, layer) in config.transport_layers.iter().enumerate() {
|
||||
match layer {
|
||||
TransportLayerConfig::Ssh(_) => {
|
||||
@@ -1654,7 +1665,7 @@ mod tests {
|
||||
use crate::ai::{AiApiStyle, AiAuthMethod, AiConfig, AiConfigItem};
|
||||
use crate::connection_secrets::{
|
||||
CASSANDRA_KEYSTORE_PASSWORD_KEY, CASSANDRA_TRUSTSTORE_PASSWORD_KEY, NACOS_AUTH_PASSWORD_KEY,
|
||||
NACOS_RNACOS_CONSOLE_PASSWORD_KEY,
|
||||
NACOS_RNACOS_CONSOLE_PASSWORD_KEY, PLUGIN_CONNECTION_SECRET_PREFIX,
|
||||
};
|
||||
use crate::models::connection::{
|
||||
default_redis_key_separator, ConnectionConfig, DatabaseType, SshTunnelConfig, TransportLayerConfig,
|
||||
@@ -1847,6 +1858,10 @@ mod tests {
|
||||
gbase_server: String::new(),
|
||||
informix_server: String::new(),
|
||||
external_config: None,
|
||||
plugin_id: None,
|
||||
plugin_connection_provider: None,
|
||||
plugin_connection_type: None,
|
||||
connection_secrets: Default::default(),
|
||||
jdbc_driver_class: None,
|
||||
jdbc_driver_paths: Vec::new(),
|
||||
one_time: false,
|
||||
@@ -1934,6 +1949,10 @@ mod tests {
|
||||
"password": password
|
||||
}
|
||||
})),
|
||||
plugin_id: None,
|
||||
plugin_connection_provider: None,
|
||||
plugin_connection_type: None,
|
||||
connection_secrets: Default::default(),
|
||||
jdbc_driver_class: None,
|
||||
jdbc_driver_paths: Vec::new(),
|
||||
one_time: false,
|
||||
@@ -2187,6 +2206,10 @@ mod tests {
|
||||
gbase_server: String::new(),
|
||||
informix_server: String::new(),
|
||||
external_config: None,
|
||||
plugin_id: None,
|
||||
plugin_connection_provider: None,
|
||||
plugin_connection_type: None,
|
||||
connection_secrets: Default::default(),
|
||||
jdbc_driver_class: None,
|
||||
jdbc_driver_paths: Vec::new(),
|
||||
one_time: false,
|
||||
@@ -2649,6 +2672,28 @@ mod tests {
|
||||
}));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn plugin_connection_secrets_are_scrubbed_from_public_sync_metadata() {
|
||||
let storage = Storage::open(&temp_db_path("plugin-public-sync")).await.unwrap();
|
||||
let mut config = postgres_connection("plugin", "");
|
||||
config.db_type = DatabaseType::Plugin;
|
||||
config.plugin_id = Some("example.plugin".to_string());
|
||||
config.plugin_connection_provider = Some("example.connection".to_string());
|
||||
config.connection_secrets.insert("api_token".to_string(), "plugin-secret".to_string());
|
||||
storage.save_connections(std::slice::from_ref(&config)).await.unwrap();
|
||||
|
||||
let snapshot = build_sync_snapshot(&storage, "test-version", None, Some("sync-pass")).await.unwrap();
|
||||
let public_json = serde_json::to_string(&snapshot.connections).unwrap();
|
||||
assert!(!public_json.contains("plugin-secret"));
|
||||
let encrypted = snapshot.encrypted_secrets.as_ref().expect("encrypted secrets");
|
||||
let decrypted = decrypt_sensitive_payload(encrypted, "sync-pass").unwrap();
|
||||
assert!(decrypted.connection_secrets.iter().any(|secret| {
|
||||
secret.connection_id == "plugin"
|
||||
&& secret.key == format!("{PLUGIN_CONNECTION_SECRET_PREFIX}api_token")
|
||||
&& secret.secret == "plugin-secret"
|
||||
}));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn sync_restore_does_not_revive_password_when_connection_disables_saving() {
|
||||
let source = Storage::open(&temp_db_path("sync-no-save-password-source")).await.unwrap();
|
||||
|
||||
@@ -29,7 +29,7 @@ use crate::models::connection::{
|
||||
use crate::mongo_oidc::MongoOidcBrowserOpener;
|
||||
use crate::nacos::config::{NACOS_CONSOLE_SESSION_PASSWORD, NACOS_PRIMARY_SESSION_PASSWORD};
|
||||
use crate::path_utils::expand_tilde;
|
||||
use crate::plugins::{PluginDriverSession, PluginRegistry, PluginRuntimeEnv};
|
||||
use crate::plugins::{PluginConnectionHandle, PluginDriverSession, PluginHost, PluginRegistry, PluginRuntimeEnv};
|
||||
use crate::query_cancel::RunningQueries;
|
||||
use crate::session_credentials::SessionCredentialStore;
|
||||
use crate::storage::{normalize_duckdb_worker_max_processes, Storage, DUCKDB_WORKER_MAX_PROCESSES_DEFAULT};
|
||||
@@ -110,6 +110,7 @@ pub enum PoolKind {
|
||||
config: Arc<ConnectionConfig>,
|
||||
session: Arc<PluginDriverSession>,
|
||||
},
|
||||
PluginConnection(PluginConnectionHandle),
|
||||
/// Message queue admin connection (not a data query pool; serves as a
|
||||
/// marker that this connection_id is a valid MQ admin connection).
|
||||
MessageQueue,
|
||||
@@ -331,6 +332,7 @@ pub struct AppState {
|
||||
pub http_tunnels: HttpTunnelManager,
|
||||
pub storage: Storage,
|
||||
pub plugins: PluginRegistry,
|
||||
pub plugin_host: PluginHost,
|
||||
pub agent_manager: crate::agent_manager::AgentManager,
|
||||
pub nacos_registry: crate::nacos::NacosAdminRegistry,
|
||||
duckdb_worker_process_isolation: AtomicBool,
|
||||
@@ -1345,6 +1347,7 @@ impl AppState {
|
||||
app_version: impl Into<String>,
|
||||
) -> Self {
|
||||
let data_dir = storage.data_dir().to_path_buf();
|
||||
let app_version = app_version.into();
|
||||
Self {
|
||||
connections: Arc::new(RwLock::new(ConnectionPoolRegistry::new())),
|
||||
task_supervisor: TaskSupervisor::new(),
|
||||
@@ -1357,7 +1360,8 @@ impl AppState {
|
||||
proxy_tunnels: ProxyTunnelManager::new(),
|
||||
http_tunnels: HttpTunnelManager::new(),
|
||||
storage,
|
||||
plugins: PluginRegistry::new(plugin_dir),
|
||||
plugins: PluginRegistry::new_with_app_version(plugin_dir.clone(), app_version.clone()),
|
||||
plugin_host: PluginHost::new(PluginRegistry::new_with_app_version(plugin_dir, app_version.clone())),
|
||||
agent_manager: crate::agent_manager::AgentManager::new_with_base_dir_and_app_version(
|
||||
agent_dir,
|
||||
app_version,
|
||||
@@ -2777,6 +2781,7 @@ impl AppState {
|
||||
}
|
||||
self.external_driver_pool("jdbc", &jdbc_config).await?
|
||||
}
|
||||
DatabaseType::Plugin => return Err("Plugin-owned connections use the plugin host".to_string()),
|
||||
#[cfg(feature = "mq-admin")]
|
||||
DatabaseType::MessageQueue => {
|
||||
// MQ admin connections don't hold a data query pool. We just test
|
||||
@@ -3833,6 +3838,7 @@ impl AppState {
|
||||
| PoolKind::MessageQueue
|
||||
| PoolKind::Nacos
|
||||
| PoolKind::Consul(_) => false,
|
||||
PoolKind::PluginConnection(handle) => !handle.is_running(),
|
||||
#[cfg(feature = "mq-admin")]
|
||||
PoolKind::Mqtt(_) => false,
|
||||
}
|
||||
@@ -4867,6 +4873,7 @@ impl AppState {
|
||||
| PoolKind::MessageQueue
|
||||
| PoolKind::Nacos
|
||||
| PoolKind::Consul(_) => true,
|
||||
PoolKind::PluginConnection(handle) => handle.is_running(),
|
||||
#[cfg(feature = "mq-admin")]
|
||||
PoolKind::Mqtt(_) => true,
|
||||
PoolKind::Redis(redis) => match db::redis_driver::test_connection(redis).await {
|
||||
@@ -4971,6 +4978,20 @@ impl AppState {
|
||||
self.pool_routing_control().close_removed(removed).await;
|
||||
}
|
||||
|
||||
pub async fn remove_plugin_connection_pools(&self, plugin_id: &str) {
|
||||
let removed = self.drain_plugin_connection_pools(plugin_id).await;
|
||||
self.pool_routing_control().close_removed(removed).await;
|
||||
}
|
||||
|
||||
pub async fn invoke_plugin_connection_action(
|
||||
&self,
|
||||
config: ConnectionConfig,
|
||||
action_id: &str,
|
||||
) -> Result<crate::plugins::PluginConnectionActionResult, String> {
|
||||
let (host, port) = self.connection_host_port(&config.id, &config).await?;
|
||||
self.plugin_host.invoke_connection_action(&config, action_id, &host, port).await
|
||||
}
|
||||
|
||||
async fn drain_connection_pools(&self, connection_id: &str) -> Vec<(String, PoolKind)> {
|
||||
let pool_prefix = format!("{connection_id}:");
|
||||
let keys_to_remove: Vec<String> = self
|
||||
@@ -5063,6 +5084,34 @@ impl AppState {
|
||||
removed
|
||||
}
|
||||
|
||||
async fn drain_plugin_connection_pools(&self, plugin_id: &str) -> Vec<(String, PoolKind)> {
|
||||
let keys_to_remove: Vec<String> = self
|
||||
.connections
|
||||
.read()
|
||||
.await
|
||||
.iter()
|
||||
.filter_map(|(key, pool)| match pool {
|
||||
PoolKind::PluginConnection(handle) if handle.plugin_id == plugin_id => Some(key.clone()),
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
self.stop_keepalive_tasks(&keys_to_remove).await;
|
||||
{
|
||||
let mut activity = self.pool_activity.write().await;
|
||||
for key in &keys_to_remove {
|
||||
activity.remove(key);
|
||||
}
|
||||
}
|
||||
let mut conns = self.connections.write().await;
|
||||
let mut removed = Vec::with_capacity(keys_to_remove.len());
|
||||
for key in keys_to_remove {
|
||||
if let Some(pool) = conns.remove(&key) {
|
||||
removed.push((key, pool));
|
||||
}
|
||||
}
|
||||
removed
|
||||
}
|
||||
|
||||
async fn uses_forwarded_transport(&self, connection_id: &str) -> bool {
|
||||
let configs = self.configs.read().await;
|
||||
configs.get(connection_id).is_some_and(|config| config.has_effective_transport_layers())
|
||||
@@ -5601,7 +5650,41 @@ fn pool_key_for_session_role(
|
||||
|
||||
#[cfg(test)]
|
||||
fn clone_pool_kind(pool: &PoolKind) -> PoolKind {
|
||||
pool.clone()
|
||||
match pool {
|
||||
PoolKind::Mysql(p, mode) => PoolKind::Mysql(p.clone(), *mode),
|
||||
PoolKind::Postgres(p) => PoolKind::Postgres(p.clone()),
|
||||
PoolKind::Sqlite(p) => PoolKind::Sqlite(p.clone()),
|
||||
PoolKind::Rqlite(client) => PoolKind::Rqlite(client.clone()),
|
||||
PoolKind::Turso(client) => PoolKind::Turso(client.clone()),
|
||||
PoolKind::CloudflareD1(client) => PoolKind::CloudflareD1(client.clone()),
|
||||
#[cfg(feature = "duckdb-sidecar")]
|
||||
PoolKind::DuckDbWorker(client) => PoolKind::DuckDbWorker(client.clone()),
|
||||
#[cfg(not(feature = "duckdb-sidecar"))]
|
||||
PoolKind::DuckDbWorker(_) => PoolKind::DuckDbWorker(()),
|
||||
PoolKind::MongoDb(client) => PoolKind::MongoDb(client.clone()),
|
||||
PoolKind::DynamoDb(client) => PoolKind::DynamoDb(client.clone()),
|
||||
PoolKind::ClickHouse(client) => PoolKind::ClickHouse(client.clone()),
|
||||
PoolKind::SqlServer(client) => PoolKind::SqlServer(client.clone()),
|
||||
PoolKind::Elasticsearch(client) => PoolKind::Elasticsearch(client.clone()),
|
||||
PoolKind::Easysearch(client) => PoolKind::Easysearch(client.clone()),
|
||||
PoolKind::Meilisearch(client) => PoolKind::Meilisearch(client.clone()),
|
||||
PoolKind::HBase(client) => PoolKind::HBase(client.clone()),
|
||||
PoolKind::VectorDb(client) => PoolKind::VectorDb(client.clone()),
|
||||
PoolKind::InfluxDb(client) => PoolKind::InfluxDb(client.clone()),
|
||||
PoolKind::InfluxDb3(client) => PoolKind::InfluxDb3(client.clone()),
|
||||
PoolKind::VictoriaMetrics(client) => PoolKind::VictoriaMetrics(client.clone()),
|
||||
PoolKind::Agent(client) => PoolKind::Agent(client.clone()),
|
||||
PoolKind::ExternalDriver { driver_id, config, session } => {
|
||||
PoolKind::ExternalDriver { driver_id: driver_id.clone(), config: config.clone(), session: session.clone() }
|
||||
}
|
||||
PoolKind::PluginConnection(handle) => PoolKind::PluginConnection(handle.clone()),
|
||||
PoolKind::MessageQueue => PoolKind::MessageQueue,
|
||||
PoolKind::Nacos => PoolKind::Nacos,
|
||||
PoolKind::Consul(client) => PoolKind::Consul(client.clone()),
|
||||
#[cfg(feature = "mq-admin")]
|
||||
PoolKind::Mqtt(client) => PoolKind::Mqtt(Arc::clone(client)),
|
||||
PoolKind::Redis(_) => panic!("clone_pool_kind not supported for Redis — handled separately"),
|
||||
}
|
||||
}
|
||||
|
||||
async fn close_pool_kind(pool: PoolKind) -> Result<(), String> {
|
||||
@@ -5668,6 +5751,9 @@ async fn close_pool_kind(pool: PoolKind) -> Result<(), String> {
|
||||
PoolKind::ExternalDriver { session, .. } => {
|
||||
session.shutdown().await;
|
||||
}
|
||||
PoolKind::PluginConnection(handle) => {
|
||||
handle.disconnect().await?;
|
||||
}
|
||||
PoolKind::MessageQueue => {}
|
||||
PoolKind::Nacos => {}
|
||||
PoolKind::Consul(_) => {}
|
||||
@@ -6078,6 +6164,10 @@ mod tests {
|
||||
gbase_server: String::new(),
|
||||
informix_server: String::new(),
|
||||
external_config: None,
|
||||
plugin_id: None,
|
||||
plugin_connection_provider: None,
|
||||
plugin_connection_type: None,
|
||||
connection_secrets: Default::default(),
|
||||
jdbc_driver_class: None,
|
||||
jdbc_driver_paths: Vec::new(),
|
||||
one_time: false,
|
||||
|
||||
@@ -27,6 +27,7 @@ pub const MQTT_AUTH_PASSWORD_KEY: &str = "mqtt.auth.password";
|
||||
pub const CASSANDRA_TLS_SECRET_PREFIX: &str = "cassandra.tls.";
|
||||
pub const CASSANDRA_TRUSTSTORE_PASSWORD_KEY: &str = "cassandra.tls.truststore_password";
|
||||
pub const CASSANDRA_KEYSTORE_PASSWORD_KEY: &str = "cassandra.tls.keystore_password";
|
||||
pub const PLUGIN_CONNECTION_SECRET_PREFIX: &str = "plugin_connection.";
|
||||
|
||||
pub trait ConnectionSecretStore {
|
||||
fn set_secret(&self, connection_id: &str, key: &str, secret: &str) -> Result<(), String>;
|
||||
@@ -947,6 +948,10 @@ mod tests {
|
||||
gbase_server: String::new(),
|
||||
informix_server: String::new(),
|
||||
external_config: None,
|
||||
plugin_id: None,
|
||||
plugin_connection_provider: None,
|
||||
plugin_connection_type: None,
|
||||
connection_secrets: Default::default(),
|
||||
jdbc_driver_class: None,
|
||||
jdbc_driver_paths: Vec::new(),
|
||||
one_time: false,
|
||||
|
||||
@@ -7334,6 +7334,10 @@ mod tests {
|
||||
gbase_server: String::new(),
|
||||
informix_server: String::new(),
|
||||
external_config: None,
|
||||
plugin_id: None,
|
||||
plugin_connection_provider: None,
|
||||
plugin_connection_type: None,
|
||||
connection_secrets: HashMap::new(),
|
||||
jdbc_driver_class: None,
|
||||
jdbc_driver_paths: Vec::new(),
|
||||
one_time: false,
|
||||
|
||||
@@ -196,6 +196,19 @@ pub struct ConnectionConfig {
|
||||
/// Typed configuration for external tabular sources.
|
||||
#[serde(default)]
|
||||
pub external_config: Option<serde_json::Value>,
|
||||
/// Owning plugin for a first-class plugin connection.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub plugin_id: Option<String>,
|
||||
/// `connection-provider` contribution id inside `plugin_id`.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub plugin_connection_provider: Option<String>,
|
||||
/// Provider-defined connection kind, such as `ssh` or `s3`.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub plugin_connection_type: Option<String>,
|
||||
/// Provider-defined sensitive values. Persistence moves these into the
|
||||
/// connection secret store rather than keeping them in `config_json`.
|
||||
#[serde(default, skip_serializing_if = "HashMap::is_empty")]
|
||||
pub connection_secrets: HashMap<String, String>,
|
||||
#[serde(default)]
|
||||
pub jdbc_driver_class: Option<String>,
|
||||
#[serde(default)]
|
||||
@@ -632,6 +645,14 @@ struct ConnectionConfigData {
|
||||
#[serde(default)]
|
||||
pub external_config: Option<serde_json::Value>,
|
||||
#[serde(default)]
|
||||
pub plugin_id: Option<String>,
|
||||
#[serde(default)]
|
||||
pub plugin_connection_provider: Option<String>,
|
||||
#[serde(default)]
|
||||
pub plugin_connection_type: Option<String>,
|
||||
#[serde(default)]
|
||||
pub connection_secrets: HashMap<String, String>,
|
||||
#[serde(default)]
|
||||
pub jdbc_driver_class: Option<String>,
|
||||
#[serde(default)]
|
||||
pub jdbc_driver_paths: Vec<String>,
|
||||
@@ -702,6 +723,10 @@ impl From<ConnectionConfigData> for ConnectionConfig {
|
||||
gbase_server: data.gbase_server,
|
||||
informix_server: data.informix_server,
|
||||
external_config: data.external_config,
|
||||
plugin_id: data.plugin_id,
|
||||
plugin_connection_provider: data.plugin_connection_provider,
|
||||
plugin_connection_type: data.plugin_connection_type,
|
||||
connection_secrets: data.connection_secrets,
|
||||
jdbc_driver_class: data.jdbc_driver_class,
|
||||
jdbc_driver_paths: data.jdbc_driver_paths,
|
||||
one_time: data.one_time,
|
||||
@@ -1173,6 +1198,11 @@ impl ConnectionConfig {
|
||||
format!("{scheme}://{host}:{port}")
|
||||
}
|
||||
DatabaseType::Jdbc => "jdbc:<redacted>".to_string(),
|
||||
DatabaseType::Plugin => format!(
|
||||
"plugin://{}/{}",
|
||||
self.plugin_id.as_deref().unwrap_or("unknown"),
|
||||
self.plugin_connection_type.as_deref().unwrap_or("unknown")
|
||||
),
|
||||
DatabaseType::MessageQueue => self.message_queue_admin_url(),
|
||||
DatabaseType::Mqtt => self.mqtt_broker_url(),
|
||||
DatabaseType::Nacos => self.nacos_admin_url(),
|
||||
@@ -1451,6 +1481,11 @@ impl ConnectionConfig {
|
||||
DatabaseType::Jdbc => {
|
||||
self.connection_string.as_deref().filter(|value| !value.is_empty()).unwrap_or("jdbc:").to_string()
|
||||
}
|
||||
DatabaseType::Plugin => format!(
|
||||
"plugin://{}/{}",
|
||||
self.plugin_id.as_deref().unwrap_or("unknown"),
|
||||
self.plugin_connection_type.as_deref().unwrap_or("unknown")
|
||||
),
|
||||
DatabaseType::MessageQueue => self.message_queue_admin_url(),
|
||||
DatabaseType::Mqtt => self.mqtt_broker_url(),
|
||||
DatabaseType::Nacos => self.nacos_admin_url(),
|
||||
@@ -2753,6 +2788,10 @@ mod tests {
|
||||
gbase_server: String::new(),
|
||||
informix_server: String::new(),
|
||||
external_config: None,
|
||||
plugin_id: None,
|
||||
plugin_connection_provider: None,
|
||||
plugin_connection_type: None,
|
||||
connection_secrets: Default::default(),
|
||||
jdbc_driver_class: None,
|
||||
jdbc_driver_paths: Vec::new(),
|
||||
one_time: false,
|
||||
|
||||
@@ -228,6 +228,10 @@ mod tests {
|
||||
etcd_endpoints: String::new(),
|
||||
gbase_server: String::new(),
|
||||
informix_server: String::new(),
|
||||
plugin_id: None,
|
||||
plugin_connection_provider: None,
|
||||
plugin_connection_type: None,
|
||||
connection_secrets: Default::default(),
|
||||
external_config: Some(value),
|
||||
jdbc_driver_class: None,
|
||||
jdbc_driver_paths: Vec::new(),
|
||||
|
||||
@@ -948,6 +948,10 @@ mod tests {
|
||||
etcd_endpoints: String::new(),
|
||||
gbase_server: String::new(),
|
||||
informix_server: String::new(),
|
||||
plugin_id: None,
|
||||
plugin_connection_provider: None,
|
||||
plugin_connection_type: None,
|
||||
connection_secrets: Default::default(),
|
||||
external_config: Some(serde_json::json!({
|
||||
"systemKind": "pulsar",
|
||||
"adminUrl": "http://127.0.0.1:8080",
|
||||
|
||||
@@ -416,6 +416,10 @@ mod tests {
|
||||
gbase_server: String::new(),
|
||||
informix_server: String::new(),
|
||||
external_config: Some(value),
|
||||
plugin_id: None,
|
||||
plugin_connection_provider: None,
|
||||
plugin_connection_type: None,
|
||||
connection_secrets: Default::default(),
|
||||
jdbc_driver_class: None,
|
||||
jdbc_driver_paths: Vec::new(),
|
||||
one_time: false,
|
||||
|
||||
@@ -692,6 +692,10 @@ mod tests {
|
||||
gbase_server: String::new(),
|
||||
informix_server: String::new(),
|
||||
external_config: Some(serde_json::json!({ "serverAddr": "http://127.0.0.1:9" })),
|
||||
plugin_id: None,
|
||||
plugin_connection_provider: None,
|
||||
plugin_connection_type: None,
|
||||
connection_secrets: std::collections::HashMap::new(),
|
||||
jdbc_driver_class: None,
|
||||
jdbc_driver_paths: Vec::new(),
|
||||
one_time: false,
|
||||
@@ -770,6 +774,10 @@ mod tests {
|
||||
gbase_server: String::new(),
|
||||
informix_server: String::new(),
|
||||
external_config: Some(serde_json::json!({ "serverAddr": "http://127.0.0.1:9" })),
|
||||
plugin_id: None,
|
||||
plugin_connection_provider: None,
|
||||
plugin_connection_type: None,
|
||||
connection_secrets: std::collections::HashMap::new(),
|
||||
jdbc_driver_class: None,
|
||||
jdbc_driver_paths: Vec::new(),
|
||||
one_time: false,
|
||||
|
||||
+319
-390
@@ -1,52 +1,98 @@
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::Stdio;
|
||||
use std::sync::atomic::{AtomicU64, Ordering};
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
use serde::de::DeserializeOwned;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tokio::io::{AsyncBufReadExt, AsyncReadExt, AsyncWriteExt, BufReader};
|
||||
use tokio::process::{Child, ChildStdin, ChildStdout, Command};
|
||||
use tokio::sync::Mutex;
|
||||
use tokio::time::timeout;
|
||||
use serde::Serialize;
|
||||
use tokio::process::Command;
|
||||
|
||||
const PLUGIN_REQUEST_TIMEOUT: Duration = Duration::from_secs(30);
|
||||
pub const SUPPORTED_PLUGIN_PROTOCOL_VERSION: u32 = 1;
|
||||
mod assets;
|
||||
mod filesystem;
|
||||
mod host;
|
||||
mod installer;
|
||||
mod manifest;
|
||||
mod marketplace;
|
||||
mod runtime;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct PluginManifest {
|
||||
pub id: String,
|
||||
pub name: String,
|
||||
#[serde(default)]
|
||||
pub version: String,
|
||||
#[serde(default = "default_plugin_protocol_version")]
|
||||
pub protocol_version: u32,
|
||||
#[serde(default)]
|
||||
pub description: String,
|
||||
#[serde(default)]
|
||||
pub executable: Option<String>,
|
||||
#[serde(default)]
|
||||
pub drivers: Vec<PluginDriverManifest>,
|
||||
}
|
||||
pub use assets::PluginUiAsset;
|
||||
pub use filesystem::{
|
||||
PluginFilesystemEntry, PluginFilesystemEntryKind, PluginFilesystemListResult, PluginFilesystemMutationResult,
|
||||
PluginFilesystemReadResult, DEFAULT_PLUGIN_FILESYSTEM_PAGE_SIZE, DEFAULT_PLUGIN_FILESYSTEM_PREVIEW_BYTES,
|
||||
MAX_PLUGIN_FILESYSTEM_INLINE_WRITE_BYTES, MAX_PLUGIN_FILESYSTEM_PAGE_SIZE, MAX_PLUGIN_FILESYSTEM_PREVIEW_BYTES,
|
||||
PLUGIN_FILESYSTEM_CREATE_DIRECTORY_METHOD, PLUGIN_FILESYSTEM_DELETE_METHOD, PLUGIN_FILESYSTEM_LIST_METHOD,
|
||||
PLUGIN_FILESYSTEM_READ_METHOD, PLUGIN_FILESYSTEM_RENAME_METHOD, PLUGIN_FILESYSTEM_WRITE_METHOD,
|
||||
};
|
||||
pub use host::{ActivePluginSession, PluginConnectionActionResult, PluginConnectionHandle, PluginHost};
|
||||
pub use installer::{
|
||||
PluginInstallPolicy, PluginInstallResponse, PluginInstallResult, PluginPackageInstaller, PluginRollbackResponse,
|
||||
PluginRollbackResult, PluginSignatureStatus, PluginTrustStore, PluginTrustedKey, DBXP_EXTENSION,
|
||||
MAX_PLUGIN_PACKAGE_BYTES, PLUGIN_CHECKSUMS_FILE, PLUGIN_SIGNATURE_FILE,
|
||||
};
|
||||
pub use marketplace::{
|
||||
PluginMarketplace, PluginMarketplaceArtifact, PluginMarketplaceCatalog, PluginMarketplaceInstallRequest,
|
||||
PluginMarketplaceLocalization, PluginMarketplacePlugin, PluginMarketplaceRepositoryMetadata,
|
||||
PluginMarketplaceVersion, PluginRepository, PluginRepositoryCatalogResult, PluginRepositoryKind,
|
||||
PluginRepositoryStore, MAX_PLUGIN_CATALOG_BYTES, OFFICIAL_PLUGIN_REPOSITORY_ID, SUPPORTED_PLUGIN_CATALOG_VERSION,
|
||||
};
|
||||
|
||||
fn default_plugin_protocol_version() -> u32 {
|
||||
1
|
||||
}
|
||||
pub use manifest::{
|
||||
current_plugin_target, resolve_safe_plugin_path, PluginBackendEntrypoint, PluginBackendTransport,
|
||||
PluginCompatibility, PluginConnectionActionContribution, PluginConnectionActionVariant, PluginConnectionActionWhen,
|
||||
PluginConnectionCapability, PluginConnectionProviderContribution, PluginContribution, PluginDriverManifest,
|
||||
PluginEngines, PluginEntrypoints, PluginFilesystemCapability, PluginFilesystemProviderContribution,
|
||||
PluginFormFieldBinding, PluginFormFieldDefinition, PluginFormFieldOption, PluginFormFieldType, PluginManifest,
|
||||
PluginUiEntrypoint, PluginWorkbenchContribution, PLUGIN_CONNECTION_ACTION_METHOD, PLUGIN_CONNECTION_CONNECT_METHOD,
|
||||
PLUGIN_CONNECTION_DISCONNECT_METHOD, PLUGIN_CONNECTION_TEST_METHOD, SUPPORTED_PLUGIN_HOST_API_VERSION,
|
||||
SUPPORTED_PLUGIN_MANIFEST_VERSION, SUPPORTED_PLUGIN_PERMISSIONS, SUPPORTED_PLUGIN_PROTOCOL_VERSION,
|
||||
};
|
||||
pub use runtime::{
|
||||
PluginBinaryMessage, PluginEvent, PluginHandshake, PluginHandshakeIdentity, PluginSessionState,
|
||||
PluginSessionStatus, PluginSidecarSession, PLUGIN_REQUEST_TIMEOUT,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct PluginDriverManifest {
|
||||
pub id: String,
|
||||
pub label: String,
|
||||
pub kind: String,
|
||||
#[serde(default)]
|
||||
pub database_type: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct InstalledPlugin {
|
||||
pub manifest: PluginManifest,
|
||||
pub path: PathBuf,
|
||||
pub compatibility: PluginCompatibility,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct InstalledPluginInfo {
|
||||
pub manifest: PluginManifest,
|
||||
pub compatibility: PluginCompatibilityInfo,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct PluginCompatibilityInfo {
|
||||
pub compatible: bool,
|
||||
#[serde(skip_serializing_if = "Vec::is_empty")]
|
||||
pub errors: Vec<String>,
|
||||
#[serde(skip_serializing_if = "Vec::is_empty")]
|
||||
pub warnings: Vec<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub target: Option<String>,
|
||||
}
|
||||
|
||||
impl InstalledPlugin {
|
||||
pub fn new(manifest: PluginManifest, path: PathBuf, app_version: &str) -> Self {
|
||||
let compatibility = manifest.compatibility(&path, app_version);
|
||||
Self { manifest, path, compatibility }
|
||||
}
|
||||
|
||||
pub fn info(&self) -> InstalledPluginInfo {
|
||||
InstalledPluginInfo {
|
||||
manifest: self.manifest.clone(),
|
||||
compatibility: PluginCompatibilityInfo {
|
||||
compatible: self.compatibility.compatible,
|
||||
errors: self.compatibility.errors.clone(),
|
||||
warnings: self.compatibility.warnings.clone(),
|
||||
target: self.compatibility.target.clone(),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
@@ -74,17 +120,26 @@ impl PluginRuntimeEnv {
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct PluginRegistry {
|
||||
root_dir: PathBuf,
|
||||
app_version: String,
|
||||
}
|
||||
|
||||
impl PluginRegistry {
|
||||
pub fn new(root_dir: PathBuf) -> Self {
|
||||
Self { root_dir }
|
||||
Self::new_with_app_version(root_dir, env!("CARGO_PKG_VERSION"))
|
||||
}
|
||||
|
||||
pub fn new_with_app_version(root_dir: PathBuf, app_version: impl Into<String>) -> Self {
|
||||
Self { root_dir, app_version: app_version.into() }
|
||||
}
|
||||
|
||||
pub fn root_dir(&self) -> &Path {
|
||||
&self.root_dir
|
||||
}
|
||||
|
||||
pub fn app_version(&self) -> &str {
|
||||
&self.app_version
|
||||
}
|
||||
|
||||
pub fn list_installed(&self) -> Result<Vec<InstalledPlugin>, String> {
|
||||
let entries = match std::fs::read_dir(&self.root_dir) {
|
||||
Ok(entries) => entries,
|
||||
@@ -95,18 +150,43 @@ impl PluginRegistry {
|
||||
let mut plugins = Vec::new();
|
||||
for entry in entries {
|
||||
let entry = entry.map_err(|err| err.to_string())?;
|
||||
let path = entry.path();
|
||||
if !path.is_dir() {
|
||||
let container_path = entry.path();
|
||||
if !container_path.is_dir() {
|
||||
continue;
|
||||
}
|
||||
let path = match installer::resolve_active_plugin_dir(&container_path) {
|
||||
Ok(Some(path)) => path,
|
||||
Ok(None) => continue,
|
||||
Err(error) => {
|
||||
plugins.push(unavailable_plugin(container_path, error));
|
||||
continue;
|
||||
}
|
||||
};
|
||||
let manifest_path = path.join("manifest.json");
|
||||
if !manifest_path.exists() {
|
||||
continue;
|
||||
}
|
||||
let raw = std::fs::read_to_string(&manifest_path).map_err(|err| err.to_string())?;
|
||||
let manifest: PluginManifest = serde_json::from_str(&raw)
|
||||
.map_err(|err| format!("Failed to parse plugin manifest {}: {err}", manifest_path.display()))?;
|
||||
plugins.push(InstalledPlugin { manifest, path });
|
||||
let raw = match std::fs::read_to_string(&manifest_path) {
|
||||
Ok(raw) => raw,
|
||||
Err(error) => {
|
||||
plugins.push(unavailable_plugin(
|
||||
container_path,
|
||||
format!("Failed to read plugin manifest {}: {error}", manifest_path.display()),
|
||||
));
|
||||
continue;
|
||||
}
|
||||
};
|
||||
let manifest: PluginManifest = match serde_json::from_str(&raw) {
|
||||
Ok(manifest) => manifest,
|
||||
Err(error) => {
|
||||
plugins.push(unavailable_plugin(
|
||||
container_path,
|
||||
format!("Failed to parse plugin manifest {}: {error}", manifest_path.display()),
|
||||
));
|
||||
continue;
|
||||
}
|
||||
};
|
||||
plugins.push(InstalledPlugin::new(manifest, path, &self.app_version));
|
||||
}
|
||||
plugins.sort_by(|a, b| a.manifest.id.cmp(&b.manifest.id));
|
||||
Ok(plugins)
|
||||
@@ -114,14 +194,19 @@ impl PluginRegistry {
|
||||
|
||||
pub fn find_driver(&self, driver_id: &str) -> Result<Option<InstalledPlugin>, String> {
|
||||
Ok(self.list_installed()?.into_iter().find(|plugin| {
|
||||
plugin
|
||||
.manifest
|
||||
.drivers
|
||||
.iter()
|
||||
.any(|driver| driver.id == driver_id || driver.database_type.as_deref() == Some(driver_id))
|
||||
plugin.compatibility.compatible
|
||||
&& plugin
|
||||
.manifest
|
||||
.drivers
|
||||
.iter()
|
||||
.any(|driver| driver.id == driver_id || driver.database_type.as_deref() == Some(driver_id))
|
||||
}))
|
||||
}
|
||||
|
||||
pub fn find_plugin(&self, plugin_id: &str) -> Result<Option<InstalledPlugin>, String> {
|
||||
Ok(self.list_installed()?.into_iter().find(|plugin| plugin.manifest.id == plugin_id))
|
||||
}
|
||||
|
||||
pub async fn invoke_driver<T>(&self, driver_id: &str, method: &str, params: serde_json::Value) -> Result<T, String>
|
||||
where
|
||||
T: DeserializeOwned,
|
||||
@@ -155,14 +240,11 @@ impl PluginRegistry {
|
||||
{
|
||||
let plugin =
|
||||
self.find_driver(driver_id)?.ok_or_else(|| format!("Plugin driver '{driver_id}' is not installed"))?;
|
||||
ensure_plugin_protocol_compatible(&plugin.manifest)?;
|
||||
let invoke = invoke_plugin(&plugin, driver_id, method, params, &env);
|
||||
match timeout_duration {
|
||||
Some(duration) => timeout(duration, invoke).await.map_err(|_| {
|
||||
format!("Plugin '{}' timed out after {} seconds", plugin.manifest.id, duration.as_secs())
|
||||
})?,
|
||||
None => invoke.await,
|
||||
}
|
||||
ensure_plugin_compatible(&plugin)?;
|
||||
let session = PluginSidecarSession::start(plugin, self.app_version.clone(), env).await?;
|
||||
let result = session.invoke_with_timeout(method, params, Some(driver_id), timeout_duration).await;
|
||||
session.shutdown().await;
|
||||
result
|
||||
}
|
||||
|
||||
pub async fn start_driver_session(&self, driver_id: &str) -> Result<Arc<PluginDriverSession>, String> {
|
||||
@@ -176,85 +258,57 @@ impl PluginRegistry {
|
||||
) -> Result<Arc<PluginDriverSession>, String> {
|
||||
let plugin =
|
||||
self.find_driver(driver_id)?.ok_or_else(|| format!("Plugin driver '{driver_id}' is not installed"))?;
|
||||
ensure_plugin_protocol_compatible(&plugin.manifest)?;
|
||||
PluginDriverSession::start(plugin, driver_id.to_string(), env).await.map(Arc::new)
|
||||
ensure_plugin_compatible(&plugin)?;
|
||||
PluginDriverSession::start(plugin, driver_id.to_string(), self.app_version.clone(), env).await.map(Arc::new)
|
||||
}
|
||||
}
|
||||
|
||||
fn ensure_plugin_protocol_compatible(manifest: &PluginManifest) -> Result<(), String> {
|
||||
if manifest.protocol_version == SUPPORTED_PLUGIN_PROTOCOL_VERSION {
|
||||
fn unavailable_plugin(path: PathBuf, error: String) -> InstalledPlugin {
|
||||
let id = path
|
||||
.file_name()
|
||||
.and_then(|name| name.to_str())
|
||||
.filter(|name| !name.is_empty())
|
||||
.unwrap_or("invalid-plugin")
|
||||
.to_string();
|
||||
InstalledPlugin {
|
||||
manifest: PluginManifest {
|
||||
id: id.clone(),
|
||||
name: id,
|
||||
version: "0.0.0-invalid".to_string(),
|
||||
description: error.clone(),
|
||||
..PluginManifest::default()
|
||||
},
|
||||
path,
|
||||
compatibility: PluginCompatibility {
|
||||
compatible: false,
|
||||
errors: vec![error],
|
||||
target: Some(current_plugin_target()),
|
||||
..PluginCompatibility::default()
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn ensure_plugin_compatible(plugin: &InstalledPlugin) -> Result<(), String> {
|
||||
if plugin.compatibility.compatible {
|
||||
return Ok(());
|
||||
}
|
||||
Err(format!(
|
||||
"Plugin '{}' uses protocol version {}, but this DBX build supports protocol version {}",
|
||||
manifest.id, manifest.protocol_version, SUPPORTED_PLUGIN_PROTOCOL_VERSION
|
||||
))
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
struct PluginRequest {
|
||||
jsonrpc: &'static str,
|
||||
id: u64,
|
||||
driver: String,
|
||||
method: String,
|
||||
params: serde_json::Value,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct PluginResponse {
|
||||
id: u64,
|
||||
#[serde(default)]
|
||||
result: Option<serde_json::Value>,
|
||||
#[serde(default)]
|
||||
error: Option<PluginError>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct PluginError {
|
||||
message: String,
|
||||
Err(format!("Plugin '{}' is incompatible: {}", plugin.manifest.id, plugin.compatibility.errors.join("; ")))
|
||||
}
|
||||
|
||||
pub struct PluginDriverSession {
|
||||
plugin: InstalledPlugin,
|
||||
sidecar: Arc<PluginSidecarSession>,
|
||||
driver_id: String,
|
||||
process: Mutex<PluginProcess>,
|
||||
next_request_id: AtomicU64,
|
||||
}
|
||||
|
||||
struct PluginProcess {
|
||||
child: Child,
|
||||
stdin: ChildStdin,
|
||||
stdout: BufReader<ChildStdout>,
|
||||
}
|
||||
|
||||
impl PluginDriverSession {
|
||||
async fn start(plugin: InstalledPlugin, driver_id: String, env: PluginRuntimeEnv) -> Result<Self, String> {
|
||||
let mut child = spawn_plugin_child(&plugin, &env)?;
|
||||
let stdin = child.stdin.take().ok_or("Plugin stdin unavailable")?;
|
||||
let stdout = child.stdout.take().ok_or("Plugin stdout unavailable")?;
|
||||
if let Some(stderr) = child.stderr.take() {
|
||||
let plugin_id = plugin.manifest.id.clone();
|
||||
tokio::spawn(async move {
|
||||
let mut stderr = BufReader::new(stderr);
|
||||
loop {
|
||||
match read_plugin_line(&mut stderr, "stderr").await {
|
||||
Ok(line) => log::warn!("[plugin:{plugin_id}] {}", line.trim_end()),
|
||||
Err(err) if err.contains("end of stream") => break,
|
||||
Err(err) => {
|
||||
log::warn!("[plugin:{plugin_id}] failed to read stderr: {err}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
plugin,
|
||||
driver_id,
|
||||
process: Mutex::new(PluginProcess { child, stdin, stdout: BufReader::new(stdout) }),
|
||||
next_request_id: AtomicU64::new(1),
|
||||
})
|
||||
async fn start(
|
||||
plugin: InstalledPlugin,
|
||||
driver_id: String,
|
||||
app_version: String,
|
||||
env: PluginRuntimeEnv,
|
||||
) -> Result<Self, String> {
|
||||
let sidecar = PluginSidecarSession::start(plugin, app_version, env).await?;
|
||||
Ok(Self { sidecar, driver_id })
|
||||
}
|
||||
|
||||
pub async fn invoke<T>(&self, method: &str, params: serde_json::Value) -> Result<T, String>
|
||||
@@ -273,68 +327,27 @@ impl PluginDriverSession {
|
||||
where
|
||||
T: DeserializeOwned,
|
||||
{
|
||||
let request_id = self.next_request_id.fetch_add(1, Ordering::Relaxed);
|
||||
let invoke = async {
|
||||
let mut process = self.process.lock().await;
|
||||
self.invoke_locked(&mut process, request_id, method, params).await
|
||||
};
|
||||
match timeout_duration {
|
||||
Some(duration) => match timeout(duration, invoke).await {
|
||||
Ok(result) => result,
|
||||
Err(_) => {
|
||||
self.kill().await;
|
||||
Err(format!("Plugin '{}' timed out after {} seconds", self.plugin.manifest.id, duration.as_secs()))
|
||||
}
|
||||
},
|
||||
None => invoke.await,
|
||||
}
|
||||
}
|
||||
|
||||
async fn invoke_locked<T>(
|
||||
&self,
|
||||
process: &mut PluginProcess,
|
||||
request_id: u64,
|
||||
method: &str,
|
||||
params: serde_json::Value,
|
||||
) -> Result<T, String>
|
||||
where
|
||||
T: DeserializeOwned,
|
||||
{
|
||||
let request = PluginRequest {
|
||||
jsonrpc: "2.0",
|
||||
id: request_id,
|
||||
driver: self.driver_id.clone(),
|
||||
method: method.to_string(),
|
||||
params,
|
||||
};
|
||||
let line = encode_plugin_request_line(&request)?;
|
||||
process.stdin.write_all(&line).await.map_err(|err| err.to_string())?;
|
||||
process.stdin.flush().await.map_err(|err| err.to_string())?;
|
||||
|
||||
let stdout = &mut process.stdout;
|
||||
let child = &mut process.child;
|
||||
read_decoded_plugin_response(&self.plugin, request_id, stdout, || {
|
||||
let status = child.try_wait().map_err(|err| err.to_string())?;
|
||||
Ok(match status {
|
||||
Some(status) => format!("Plugin '{}' exited with status {}", self.plugin.manifest.id, status),
|
||||
None => format!("Plugin '{}' closed stdout without a response", self.plugin.manifest.id),
|
||||
})
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
async fn kill(&self) {
|
||||
let mut process = self.process.lock().await;
|
||||
let _ = process.child.kill().await;
|
||||
self.sidecar.invoke_with_timeout(method, params, Some(&self.driver_id), timeout_duration).await
|
||||
}
|
||||
|
||||
pub async fn shutdown(&self) {
|
||||
self.kill().await;
|
||||
self.sidecar.shutdown().await;
|
||||
}
|
||||
|
||||
pub async fn pid(&self) -> Option<u32> {
|
||||
let process = self.process.lock().await;
|
||||
process.child.id()
|
||||
self.sidecar.pid().await
|
||||
}
|
||||
|
||||
pub fn subscribe_events(&self) -> tokio::sync::broadcast::Receiver<PluginEvent> {
|
||||
self.sidecar.subscribe_events()
|
||||
}
|
||||
|
||||
pub fn subscribe_binary(&self) -> tokio::sync::broadcast::Receiver<PluginBinaryMessage> {
|
||||
self.sidecar.subscribe_binary()
|
||||
}
|
||||
|
||||
pub async fn send_binary(&self, channel: &str, data: &[u8]) -> Result<(), String> {
|
||||
self.sidecar.send_binary(channel, data).await
|
||||
}
|
||||
|
||||
#[cfg(all(test, unix))]
|
||||
@@ -343,216 +356,15 @@ impl PluginDriverSession {
|
||||
driver_id: String,
|
||||
env: PluginRuntimeEnv,
|
||||
) -> Result<Self, String> {
|
||||
Self::start(plugin, driver_id, env).await
|
||||
Self::start(plugin, driver_id, env!("CARGO_PKG_VERSION").to_string(), env).await
|
||||
}
|
||||
}
|
||||
|
||||
async fn invoke_plugin<T>(
|
||||
plugin: &InstalledPlugin,
|
||||
driver_id: &str,
|
||||
method: &str,
|
||||
params: serde_json::Value,
|
||||
env: &PluginRuntimeEnv,
|
||||
) -> Result<T, String>
|
||||
where
|
||||
T: DeserializeOwned,
|
||||
{
|
||||
let mut child = spawn_plugin_child(plugin, env)?;
|
||||
|
||||
let request =
|
||||
PluginRequest { jsonrpc: "2.0", id: 1, driver: driver_id.to_string(), method: method.to_string(), params };
|
||||
let line = encode_plugin_request_line(&request)?;
|
||||
|
||||
let mut stdin = child.stdin.take().ok_or("Plugin stdin unavailable")?;
|
||||
stdin.write_all(&line).await.map_err(|err| err.to_string())?;
|
||||
drop(stdin);
|
||||
|
||||
let stdout = child.stdout.take().ok_or("Plugin stdout unavailable")?;
|
||||
let mut stderr = child.stderr.take().ok_or("Plugin stderr unavailable")?;
|
||||
let mut reader = BufReader::new(stdout);
|
||||
let response_result = read_decoded_plugin_response(plugin, request.id, &mut reader, || {
|
||||
Ok(format!("Plugin '{}' exited without a response", plugin.manifest.id))
|
||||
})
|
||||
.await;
|
||||
let mut stderr_bytes = Vec::new();
|
||||
stderr.read_to_end(&mut stderr_bytes).await.map_err(|err| err.to_string())?;
|
||||
let stderr_text = String::from_utf8_lossy(&stderr_bytes).into_owned();
|
||||
let status = child.wait().await.map_err(|err| err.to_string())?;
|
||||
|
||||
let response = match response_result {
|
||||
Ok(response) => response,
|
||||
Err(err) if err.contains("end of stream") => {
|
||||
let stderr = stderr_text.trim().to_string();
|
||||
return Err(if stderr.is_empty() {
|
||||
format!("Plugin '{}' exited without a response", plugin.manifest.id)
|
||||
} else {
|
||||
format!("Plugin '{}' exited without a response: {stderr}", plugin.manifest.id)
|
||||
});
|
||||
}
|
||||
Err(err) => return Err(err),
|
||||
};
|
||||
if !status.success() {
|
||||
let stderr = stderr_text.trim().to_string();
|
||||
return Err(if stderr.is_empty() {
|
||||
format!("Plugin '{}' exited with status {}", plugin.manifest.id, status)
|
||||
} else {
|
||||
format!("Plugin '{}' failed: {stderr}", plugin.manifest.id)
|
||||
});
|
||||
}
|
||||
|
||||
Ok(response)
|
||||
}
|
||||
|
||||
fn encode_plugin_request_line(request: &PluginRequest) -> Result<Vec<u8>, String> {
|
||||
let mut bytes = Vec::new();
|
||||
serde_json::to_writer(&mut bytes, request).map_err(|err| err.to_string())?;
|
||||
bytes.push(b'\n');
|
||||
Ok(bytes)
|
||||
}
|
||||
|
||||
fn spawn_plugin_child(plugin: &InstalledPlugin, env: &PluginRuntimeEnv) -> Result<Child, String> {
|
||||
let executable = plugin
|
||||
.manifest
|
||||
.executable
|
||||
.as_deref()
|
||||
.filter(|value| !value.is_empty())
|
||||
.ok_or_else(|| format!("Plugin '{}' does not declare an executable", plugin.manifest.id))?;
|
||||
let executable_path = resolve_plugin_executable(&plugin.path, executable);
|
||||
|
||||
let mut command = crate::process::new_tokio_command(&executable_path);
|
||||
command
|
||||
.current_dir(&plugin.path)
|
||||
.stdin(Stdio::piped())
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.kill_on_drop(true);
|
||||
env.apply_to(&mut command);
|
||||
|
||||
command.spawn().map_err(|err| format!("Failed to start plugin '{}': {err}", plugin.manifest.id))
|
||||
}
|
||||
|
||||
async fn read_plugin_line<R>(reader: &mut R, context: &str) -> Result<String, String>
|
||||
where
|
||||
R: tokio::io::AsyncBufRead + Unpin,
|
||||
{
|
||||
let mut bytes = Vec::new();
|
||||
reader.read_until(b'\n', &mut bytes).await.map_err(|err| format!("Failed to read plugin {context}: {err}"))?;
|
||||
if bytes.is_empty() {
|
||||
return Err(format!("Failed to read plugin {context}: end of stream"));
|
||||
}
|
||||
Ok(String::from_utf8_lossy(&bytes).into_owned())
|
||||
}
|
||||
|
||||
async fn read_decoded_plugin_response<T, R, F>(
|
||||
plugin: &InstalledPlugin,
|
||||
request_id: u64,
|
||||
reader: &mut R,
|
||||
end_of_stream_message: F,
|
||||
) -> Result<T, String>
|
||||
where
|
||||
T: DeserializeOwned,
|
||||
R: tokio::io::AsyncBufRead + Unpin,
|
||||
F: FnMut() -> Result<String, String>,
|
||||
{
|
||||
let mut end_of_stream_message = end_of_stream_message;
|
||||
const MAX_NOISY_LINES: usize = 20;
|
||||
for _ in 0..MAX_NOISY_LINES {
|
||||
let line = match read_plugin_line(reader, "response").await {
|
||||
Ok(line) => line,
|
||||
Err(err) if err.contains("end of stream") => return Err(end_of_stream_message()?),
|
||||
Err(err) => return Err(err),
|
||||
};
|
||||
match decode_plugin_response(plugin, request_id, &line) {
|
||||
Ok(response) => return Ok(response),
|
||||
Err(err) if err.starts_with(&format!("Failed to parse plugin '{}' response:", plugin.manifest.id)) => {
|
||||
log::warn!("[plugin:{}] ignored non-protocol stdout: {}", plugin.manifest.id, line.trim_end());
|
||||
}
|
||||
Err(err) => return Err(err),
|
||||
}
|
||||
}
|
||||
match read_plugin_line(reader, "response").await {
|
||||
Ok(_) => {
|
||||
Err(format!("Plugin '{}' wrote too many non-protocol stdout lines before its response", plugin.manifest.id))
|
||||
}
|
||||
Err(err) if err.contains("end of stream") => Err(end_of_stream_message()?),
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
}
|
||||
|
||||
fn decode_plugin_response<T>(plugin: &InstalledPlugin, request_id: u64, response_line: &str) -> Result<T, String>
|
||||
where
|
||||
T: DeserializeOwned,
|
||||
{
|
||||
let response: PluginResponse = serde_json::from_str(response_line)
|
||||
.map_err(|err| format!("Failed to parse plugin '{}' response: {err}", plugin.manifest.id))?;
|
||||
if response.id != request_id {
|
||||
return Err(format!("Plugin '{}' returned mismatched response id", plugin.manifest.id));
|
||||
}
|
||||
if let Some(error) = response.error {
|
||||
return Err(error.message);
|
||||
}
|
||||
let result = response.result.unwrap_or(serde_json::Value::Null);
|
||||
serde_json::from_value(result)
|
||||
.map_err(|err| format!("Failed to decode plugin '{}' result: {err}", plugin.manifest.id))
|
||||
}
|
||||
|
||||
fn resolve_plugin_executable(plugin_dir: &Path, executable: &str) -> PathBuf {
|
||||
let path = PathBuf::from(executable);
|
||||
let resolved = if path.is_absolute() { path } else { plugin_dir.join(path) };
|
||||
|
||||
#[cfg(windows)]
|
||||
{
|
||||
let bat = resolved.with_extension("bat");
|
||||
if bat.exists() {
|
||||
return bat;
|
||||
}
|
||||
}
|
||||
|
||||
resolved
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{read_decoded_plugin_response, read_plugin_line, InstalledPlugin, PluginManifest};
|
||||
use super::{InstalledPlugin, PluginContribution, PluginManifest, PluginRegistry};
|
||||
#[cfg(unix)]
|
||||
use super::{PluginDriverManifest, PluginDriverSession, PluginRuntimeEnv};
|
||||
use std::path::PathBuf;
|
||||
use tokio::io::BufReader;
|
||||
|
||||
#[tokio::test]
|
||||
async fn reads_non_utf8_plugin_lines_lossily() {
|
||||
let bytes = vec![b'{', b'"', b'e', b'r', b'r', b'o', b'r', b'"', b':', 0xB2, 0xE2, b'}', b'\n'];
|
||||
let mut reader = BufReader::new(std::io::Cursor::new(bytes));
|
||||
|
||||
let line = read_plugin_line(&mut reader, "response").await.expect("line should be readable");
|
||||
|
||||
assert_eq!(line, format!("{{\"error\":{}}}\n", "\u{fffd}\u{fffd}"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn skips_noisy_plugin_stdout_before_json_response() {
|
||||
let plugin = InstalledPlugin {
|
||||
manifest: PluginManifest {
|
||||
id: "jdbc".to_string(),
|
||||
name: "JDBC".to_string(),
|
||||
version: "test".to_string(),
|
||||
protocol_version: 1,
|
||||
description: String::new(),
|
||||
executable: None,
|
||||
drivers: Vec::new(),
|
||||
},
|
||||
path: PathBuf::new(),
|
||||
};
|
||||
let bytes = b"driver banner\n{\"id\":1,\"result\":{\"ok\":true}}\n";
|
||||
let mut reader = BufReader::new(std::io::Cursor::new(bytes));
|
||||
|
||||
let result: serde_json::Value =
|
||||
read_decoded_plugin_response(&plugin, 1, &mut reader, || Ok("closed".to_string()))
|
||||
.await
|
||||
.expect("response should decode after noisy line");
|
||||
|
||||
assert_eq!(result["ok"], true);
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[tokio::test]
|
||||
@@ -568,8 +380,8 @@ mod tests {
|
||||
permissions.set_mode(0o755);
|
||||
std::fs::set_permissions(&executable, permissions).unwrap();
|
||||
}
|
||||
let plugin = InstalledPlugin {
|
||||
manifest: PluginManifest {
|
||||
let plugin = InstalledPlugin::new(
|
||||
PluginManifest {
|
||||
id: "jdbc".to_string(),
|
||||
name: "JDBC".to_string(),
|
||||
version: "test".to_string(),
|
||||
@@ -582,13 +394,21 @@ mod tests {
|
||||
kind: "external".to_string(),
|
||||
database_type: Some("jdbc".to_string()),
|
||||
}],
|
||||
contributions: Vec::new(),
|
||||
..PluginManifest::default()
|
||||
},
|
||||
path: dir.clone(),
|
||||
};
|
||||
dir.clone(),
|
||||
env!("CARGO_PKG_VERSION"),
|
||||
);
|
||||
|
||||
let session = PluginDriverSession::start(plugin, "jdbc".to_string(), PluginRuntimeEnv::default())
|
||||
.await
|
||||
.expect("session should start");
|
||||
let session = PluginDriverSession::start(
|
||||
plugin,
|
||||
"jdbc".to_string(),
|
||||
env!("CARGO_PKG_VERSION").to_string(),
|
||||
PluginRuntimeEnv::default(),
|
||||
)
|
||||
.await
|
||||
.expect("session should start");
|
||||
let pid = session.pid().await.expect("child should have a pid");
|
||||
|
||||
session.shutdown().await;
|
||||
@@ -608,4 +428,113 @@ mod tests {
|
||||
.map(|status| status.success())
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn preserves_typed_contributions_in_manifest_round_trip() {
|
||||
let manifest: PluginManifest = serde_json::from_value(serde_json::json!({
|
||||
"manifest_version": 1,
|
||||
"id": "sample",
|
||||
"name": "Sample",
|
||||
"version": "1.0.0",
|
||||
"publisher": "example",
|
||||
"engines": { "host_api": "1" },
|
||||
"contributions": [{
|
||||
"type": "connection-provider",
|
||||
"id": "sample.connection",
|
||||
"database_type": "sample",
|
||||
"fields": []
|
||||
}]
|
||||
}))
|
||||
.expect("manifest should parse");
|
||||
|
||||
assert!(matches!(
|
||||
&manifest.contributions[0],
|
||||
PluginContribution::ConnectionProvider(provider) if provider.id == "sample.connection"
|
||||
));
|
||||
let serialized = serde_json::to_value(manifest).expect("manifest should serialize");
|
||||
assert_eq!(serialized["contributions"][0]["database_type"], "sample");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn registry_lists_frontend_contributions_from_disk() {
|
||||
let root = std::env::temp_dir().join(format!("dbx-plugin-registry-test-{}", uuid::Uuid::new_v4()));
|
||||
let plugin_dir = root.join("sample");
|
||||
std::fs::create_dir_all(&plugin_dir).expect("plugin directory should be created");
|
||||
std::fs::write(
|
||||
plugin_dir.join("manifest.json"),
|
||||
serde_json::json!({
|
||||
"manifest_version": 1,
|
||||
"id": "sample",
|
||||
"name": "Sample",
|
||||
"version": "1.0.0",
|
||||
"publisher": "example",
|
||||
"engines": { "host_api": "1" },
|
||||
"contributions": [{
|
||||
"type": "connection-provider",
|
||||
"id": "sample.connection",
|
||||
"database_type": "sample",
|
||||
"fields": []
|
||||
}]
|
||||
})
|
||||
.to_string(),
|
||||
)
|
||||
.expect("manifest should be written");
|
||||
|
||||
let plugins = PluginRegistry::new(root.clone()).list_installed().expect("plugins should be listed");
|
||||
|
||||
assert_eq!(plugins.len(), 1);
|
||||
assert!(matches!(
|
||||
&plugins[0].manifest.contributions[0],
|
||||
PluginContribution::ConnectionProvider(provider) if provider.id == "sample.connection"
|
||||
));
|
||||
let _ = std::fs::remove_dir_all(root);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn registry_keeps_other_plugins_visible_when_one_manifest_is_corrupt() {
|
||||
let root = std::env::temp_dir().join(format!("dbx-plugin-corrupt-registry-test-{}", uuid::Uuid::new_v4()));
|
||||
let valid = root.join("valid");
|
||||
let corrupt = root.join("corrupt");
|
||||
std::fs::create_dir_all(&valid).unwrap();
|
||||
std::fs::create_dir_all(&corrupt).unwrap();
|
||||
std::fs::write(
|
||||
valid.join("manifest.json"),
|
||||
serde_json::json!({ "id": "valid", "name": "Valid", "drivers": [] }).to_string(),
|
||||
)
|
||||
.unwrap();
|
||||
std::fs::write(corrupt.join("manifest.json"), "{").unwrap();
|
||||
|
||||
let plugins = PluginRegistry::new(root.clone()).list_installed().unwrap();
|
||||
|
||||
assert_eq!(plugins.len(), 2);
|
||||
assert!(plugins.iter().any(|plugin| plugin.manifest.id == "valid" && plugin.compatibility.compatible));
|
||||
assert!(plugins.iter().any(|plugin| {
|
||||
plugin.manifest.id == "corrupt"
|
||||
&& !plugin.compatibility.compatible
|
||||
&& plugin.compatibility.errors.iter().any(|error| error.contains("Failed to parse"))
|
||||
}));
|
||||
let _ = std::fs::remove_dir_all(root);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn installed_plugin_info_hides_runtime_paths() {
|
||||
let plugin = InstalledPlugin::new(
|
||||
PluginManifest {
|
||||
manifest_version: 1,
|
||||
id: "sample".to_string(),
|
||||
name: "Sample".to_string(),
|
||||
version: "1.0.0".to_string(),
|
||||
publisher: "example".to_string(),
|
||||
..PluginManifest::default()
|
||||
},
|
||||
std::path::PathBuf::from("/private/plugin/install"),
|
||||
env!("CARGO_PKG_VERSION"),
|
||||
);
|
||||
let serialized = serde_json::to_value(plugin.info()).unwrap();
|
||||
|
||||
assert!(serialized.get("path").is_none());
|
||||
assert!(serialized["compatibility"].get("backend_executable").is_none());
|
||||
assert!(serialized["compatibility"].get("ui_entry").is_none());
|
||||
assert!(serialized["compatibility"].get("ui_root").is_none());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
use std::path::{Component, Path, PathBuf};
|
||||
|
||||
use sha2::{Digest, Sha256};
|
||||
|
||||
use super::{InstalledPlugin, PluginRegistry};
|
||||
|
||||
const MAX_PLUGIN_UI_ASSET_BYTES: u64 = 32 * 1024 * 1024;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct PluginUiAsset {
|
||||
pub content_type: String,
|
||||
pub bytes: Vec<u8>,
|
||||
pub etag: String,
|
||||
}
|
||||
|
||||
impl PluginRegistry {
|
||||
pub fn read_asset(&self, plugin_id: &str, relative_path: &str) -> Result<PluginUiAsset, String> {
|
||||
let plugin = self.find_plugin(plugin_id)?.ok_or_else(|| format!("Plugin '{plugin_id}' is not installed"))?;
|
||||
let relative = validate_asset_path(relative_path)?;
|
||||
let path = plugin.path.join(relative);
|
||||
read_asset_file(plugin_id, &plugin.path, &path)
|
||||
}
|
||||
|
||||
pub fn read_ui_entry(&self, plugin_id: &str) -> Result<PluginUiAsset, String> {
|
||||
let plugin = self.compatible_ui_plugin(plugin_id)?;
|
||||
let entry = plugin
|
||||
.compatibility
|
||||
.ui_entry
|
||||
.as_ref()
|
||||
.ok_or_else(|| format!("Plugin '{plugin_id}' does not provide a UI entrypoint"))?;
|
||||
let root = plugin
|
||||
.compatibility
|
||||
.ui_root
|
||||
.as_ref()
|
||||
.ok_or_else(|| format!("Plugin '{plugin_id}' does not provide a UI root"))?;
|
||||
read_asset_file(plugin_id, root, entry)
|
||||
}
|
||||
|
||||
pub fn read_ui_asset(&self, plugin_id: &str, relative_path: &str) -> Result<PluginUiAsset, String> {
|
||||
let plugin = self.compatible_ui_plugin(plugin_id)?;
|
||||
let root = plugin
|
||||
.compatibility
|
||||
.ui_root
|
||||
.as_ref()
|
||||
.ok_or_else(|| format!("Plugin '{plugin_id}' does not provide a UI root"))?;
|
||||
let relative = validate_asset_path(relative_path)?;
|
||||
let path = root.join(relative);
|
||||
read_asset_file(plugin_id, root, &path)
|
||||
}
|
||||
|
||||
fn compatible_ui_plugin(&self, plugin_id: &str) -> Result<InstalledPlugin, String> {
|
||||
let plugin = self.find_plugin(plugin_id)?.ok_or_else(|| format!("Plugin '{plugin_id}' is not installed"))?;
|
||||
if !plugin.compatibility.compatible {
|
||||
return Err(format!("Plugin '{plugin_id}' is incompatible: {}", plugin.compatibility.errors.join("; ")));
|
||||
}
|
||||
if plugin.manifest.entrypoints.ui.is_none() {
|
||||
return Err(format!("Plugin '{plugin_id}' does not provide a UI entrypoint"));
|
||||
}
|
||||
Ok(plugin)
|
||||
}
|
||||
}
|
||||
|
||||
fn read_asset_file(plugin_id: &str, root: &Path, path: &Path) -> Result<PluginUiAsset, String> {
|
||||
let canonical_root = std::fs::canonicalize(root)
|
||||
.map_err(|error| format!("Failed to resolve plugin asset root {}: {error}", root.display()))?;
|
||||
let canonical_path = std::fs::canonicalize(path)
|
||||
.map_err(|error| format!("Plugin UI asset does not exist {}: {error}", path.display()))?;
|
||||
if !canonical_path.starts_with(&canonical_root) {
|
||||
return Err(format!("Plugin asset escapes plugin '{plugin_id}': {}", path.display()));
|
||||
}
|
||||
let metadata = std::fs::metadata(&canonical_path).map_err(|error| error.to_string())?;
|
||||
if !metadata.is_file() {
|
||||
return Err(format!("Plugin UI asset is not a file: {}", canonical_path.display()));
|
||||
}
|
||||
if metadata.len() > MAX_PLUGIN_UI_ASSET_BYTES {
|
||||
return Err(format!("Plugin UI asset exceeds {MAX_PLUGIN_UI_ASSET_BYTES} bytes"));
|
||||
}
|
||||
let bytes = std::fs::read(&canonical_path).map_err(|error| error.to_string())?;
|
||||
let etag = format!("\"{}\"", hex_digest(Sha256::digest(&bytes)));
|
||||
Ok(PluginUiAsset { content_type: content_type(&canonical_path).to_string(), bytes, etag })
|
||||
}
|
||||
|
||||
fn validate_asset_path(relative_path: &str) -> Result<PathBuf, String> {
|
||||
let path = Path::new(relative_path);
|
||||
if path.as_os_str().is_empty() || path.is_absolute() {
|
||||
return Err("Plugin UI asset path must be a non-empty relative path".to_string());
|
||||
}
|
||||
if path.components().any(|component| !matches!(component, Component::Normal(_))) {
|
||||
return Err(format!("Plugin UI asset path is unsafe: {relative_path}"));
|
||||
}
|
||||
Ok(path.to_path_buf())
|
||||
}
|
||||
|
||||
fn content_type(path: &Path) -> &'static str {
|
||||
match path.extension().and_then(|extension| extension.to_str()).map(str::to_ascii_lowercase).as_deref() {
|
||||
Some("html" | "htm") => "text/html; charset=utf-8",
|
||||
Some("js" | "mjs") => "text/javascript; charset=utf-8",
|
||||
Some("css") => "text/css; charset=utf-8",
|
||||
Some("json" | "map") => "application/json; charset=utf-8",
|
||||
Some("svg") => "image/svg+xml",
|
||||
Some("png") => "image/png",
|
||||
Some("jpg" | "jpeg") => "image/jpeg",
|
||||
Some("gif") => "image/gif",
|
||||
Some("webp") => "image/webp",
|
||||
Some("ico") => "image/x-icon",
|
||||
Some("woff") => "font/woff",
|
||||
Some("woff2") => "font/woff2",
|
||||
Some("wasm") => "application/wasm",
|
||||
Some("txt") => "text/plain; charset=utf-8",
|
||||
_ => "application/octet-stream",
|
||||
}
|
||||
}
|
||||
|
||||
fn hex_digest(bytes: impl AsRef<[u8]>) -> String {
|
||||
use std::fmt::Write as _;
|
||||
|
||||
bytes.as_ref().iter().fold(String::with_capacity(64), |mut output, byte| {
|
||||
let _ = write!(output, "{byte:02x}");
|
||||
output
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::PluginRegistry;
|
||||
|
||||
#[test]
|
||||
fn serves_assets_inside_declared_ui_root() {
|
||||
let root = tempfile::tempdir().unwrap();
|
||||
let plugin_dir = root.path().join("sample");
|
||||
std::fs::create_dir_all(plugin_dir.join("ui")).unwrap();
|
||||
std::fs::write(plugin_dir.join("ui/index.html"), "<h1>Hello</h1>").unwrap();
|
||||
std::fs::write(plugin_dir.join("ui/app.js"), "console.log('hello')").unwrap();
|
||||
std::fs::write(
|
||||
plugin_dir.join("manifest.json"),
|
||||
serde_json::json!({
|
||||
"manifest_version": 1,
|
||||
"id": "sample",
|
||||
"name": "Sample",
|
||||
"version": "1.0.0",
|
||||
"publisher": "dbx",
|
||||
"engines": { "dbx": ">=0.1.0", "host_api": "^1.0" },
|
||||
"entrypoints": { "ui": { "root": "ui", "entry": "ui/index.html" } }
|
||||
})
|
||||
.to_string(),
|
||||
)
|
||||
.unwrap();
|
||||
let registry = PluginRegistry::new_with_app_version(root.path().to_path_buf(), "0.5.67");
|
||||
|
||||
let entry = registry.read_ui_entry("sample").unwrap();
|
||||
assert_eq!(entry.content_type, "text/html; charset=utf-8");
|
||||
assert_eq!(entry.bytes, b"<h1>Hello</h1>");
|
||||
assert!(registry.read_ui_asset("sample", "app.js").is_ok());
|
||||
assert!(registry.read_ui_asset("sample", "../manifest.json").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn serves_package_assets_without_a_ui_entrypoint() {
|
||||
let root = tempfile::tempdir().unwrap();
|
||||
let plugin_dir = root.path().join("sample");
|
||||
std::fs::create_dir_all(plugin_dir.join("assets")).unwrap();
|
||||
std::fs::write(plugin_dir.join("assets/icon.svg"), "<svg/>").unwrap();
|
||||
std::fs::write(
|
||||
plugin_dir.join("manifest.json"),
|
||||
serde_json::json!({
|
||||
"manifest_version": 1,
|
||||
"id": "sample",
|
||||
"name": "Sample",
|
||||
"version": "1.0.0",
|
||||
"publisher": "dbx",
|
||||
"engines": { "dbx": ">=0.1.0", "host_api": "^1.0" },
|
||||
"icon": "assets/icon.svg"
|
||||
})
|
||||
.to_string(),
|
||||
)
|
||||
.unwrap();
|
||||
let registry = PluginRegistry::new_with_app_version(root.path().to_path_buf(), "0.5.67");
|
||||
|
||||
let icon = registry.read_asset("sample", "assets/icon.svg").unwrap();
|
||||
assert_eq!(icon.content_type, "image/svg+xml");
|
||||
assert_eq!(icon.bytes, b"<svg/>");
|
||||
assert!(registry.read_asset("sample", "../outside.svg").is_err());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,536 @@
|
||||
use std::time::Duration;
|
||||
|
||||
use base64::Engine;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::{PluginFilesystemCapability, PluginFilesystemProviderContribution, PluginHost, PLUGIN_REQUEST_TIMEOUT};
|
||||
|
||||
pub const PLUGIN_FILESYSTEM_LIST_METHOD: &str = "filesystem/list";
|
||||
pub const PLUGIN_FILESYSTEM_READ_METHOD: &str = "filesystem/read";
|
||||
pub const PLUGIN_FILESYSTEM_WRITE_METHOD: &str = "filesystem/write";
|
||||
pub const PLUGIN_FILESYSTEM_CREATE_DIRECTORY_METHOD: &str = "filesystem/createDirectory";
|
||||
pub const PLUGIN_FILESYSTEM_DELETE_METHOD: &str = "filesystem/delete";
|
||||
pub const PLUGIN_FILESYSTEM_RENAME_METHOD: &str = "filesystem/rename";
|
||||
pub const DEFAULT_PLUGIN_FILESYSTEM_PAGE_SIZE: u32 = 200;
|
||||
pub const MAX_PLUGIN_FILESYSTEM_PAGE_SIZE: u32 = 1_000;
|
||||
pub const DEFAULT_PLUGIN_FILESYSTEM_PREVIEW_BYTES: u64 = 256 * 1024;
|
||||
pub const MAX_PLUGIN_FILESYSTEM_PREVIEW_BYTES: u64 = 4 * 1024 * 1024;
|
||||
pub const MAX_PLUGIN_FILESYSTEM_INLINE_WRITE_BYTES: u64 = 4 * 1024 * 1024;
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct PluginFilesystemListRequest<'a> {
|
||||
provider_id: &'a str,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
connection_id: Option<&'a str>,
|
||||
uri: &'a str,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
cursor: Option<&'a str>,
|
||||
limit: u32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct PluginFilesystemReadRequest<'a> {
|
||||
provider_id: &'a str,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
connection_id: Option<&'a str>,
|
||||
uri: &'a str,
|
||||
max_bytes: u64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct PluginFilesystemWriteRequest<'a> {
|
||||
provider_id: &'a str,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
connection_id: Option<&'a str>,
|
||||
uri: &'a str,
|
||||
data_base64: &'a str,
|
||||
create: bool,
|
||||
overwrite: bool,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
etag: Option<&'a str>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct PluginFilesystemCreateDirectoryRequest<'a> {
|
||||
provider_id: &'a str,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
connection_id: Option<&'a str>,
|
||||
uri: &'a str,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct PluginFilesystemDeleteRequest<'a> {
|
||||
provider_id: &'a str,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
connection_id: Option<&'a str>,
|
||||
uri: &'a str,
|
||||
recursive: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct PluginFilesystemRenameRequest<'a> {
|
||||
provider_id: &'a str,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
connection_id: Option<&'a str>,
|
||||
source_uri: &'a str,
|
||||
target_uri: &'a str,
|
||||
overwrite: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub enum PluginFilesystemEntryKind {
|
||||
File,
|
||||
Directory,
|
||||
Symlink,
|
||||
Other,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct PluginFilesystemEntry {
|
||||
pub name: String,
|
||||
pub uri: String,
|
||||
pub kind: PluginFilesystemEntryKind,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub size: Option<u64>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub modified_at: Option<String>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub content_type: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct PluginFilesystemListResult {
|
||||
#[serde(default)]
|
||||
pub entries: Vec<PluginFilesystemEntry>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub next_cursor: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct PluginFilesystemReadResult {
|
||||
pub data_base64: String,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub content_type: Option<String>,
|
||||
#[serde(default)]
|
||||
pub truncated: bool,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub etag: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct PluginFilesystemMutationResult {
|
||||
#[serde(default = "default_true")]
|
||||
pub success: bool,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub message: Option<String>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub entry: Option<PluginFilesystemEntry>,
|
||||
}
|
||||
|
||||
fn default_true() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
impl PluginHost {
|
||||
pub async fn list_filesystem_entries(
|
||||
&self,
|
||||
plugin_id: &str,
|
||||
provider_id: &str,
|
||||
connection_id: Option<&str>,
|
||||
uri: Option<&str>,
|
||||
cursor: Option<&str>,
|
||||
limit: Option<u32>,
|
||||
) -> Result<PluginFilesystemListResult, String> {
|
||||
let provider = self.resolve_filesystem_provider(plugin_id, provider_id)?;
|
||||
let uri = resolve_filesystem_uri(&provider, uri)?;
|
||||
let limit = limit.unwrap_or(DEFAULT_PLUGIN_FILESYSTEM_PAGE_SIZE).clamp(1, MAX_PLUGIN_FILESYSTEM_PAGE_SIZE);
|
||||
let request = PluginFilesystemListRequest {
|
||||
provider_id,
|
||||
connection_id: normalized_optional_value(connection_id),
|
||||
uri: &uri,
|
||||
cursor: normalized_optional_value(cursor),
|
||||
limit,
|
||||
};
|
||||
let result: PluginFilesystemListResult = self
|
||||
.invoke(
|
||||
plugin_id,
|
||||
PLUGIN_FILESYSTEM_LIST_METHOD,
|
||||
serde_json::to_value(request).map_err(|error| error.to_string())?,
|
||||
None,
|
||||
Some(PLUGIN_REQUEST_TIMEOUT),
|
||||
)
|
||||
.await?;
|
||||
validate_list_result(&provider, &result, limit)?;
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
pub async fn read_filesystem_file(
|
||||
&self,
|
||||
plugin_id: &str,
|
||||
provider_id: &str,
|
||||
connection_id: Option<&str>,
|
||||
uri: &str,
|
||||
max_bytes: Option<u64>,
|
||||
) -> Result<PluginFilesystemReadResult, String> {
|
||||
let provider = self.resolve_filesystem_provider(plugin_id, provider_id)?;
|
||||
ensure_provider_capability(plugin_id, &provider, PluginFilesystemCapability::Read)?;
|
||||
let uri = resolve_filesystem_uri(&provider, Some(uri))?;
|
||||
let max_bytes =
|
||||
max_bytes.unwrap_or(DEFAULT_PLUGIN_FILESYSTEM_PREVIEW_BYTES).clamp(1, MAX_PLUGIN_FILESYSTEM_PREVIEW_BYTES);
|
||||
let request = PluginFilesystemReadRequest {
|
||||
provider_id,
|
||||
connection_id: normalized_optional_value(connection_id),
|
||||
uri: &uri,
|
||||
max_bytes,
|
||||
};
|
||||
let result: PluginFilesystemReadResult = self
|
||||
.invoke(
|
||||
plugin_id,
|
||||
PLUGIN_FILESYSTEM_READ_METHOD,
|
||||
serde_json::to_value(request).map_err(|error| error.to_string())?,
|
||||
None,
|
||||
Some(Duration::from_secs(30)),
|
||||
)
|
||||
.await?;
|
||||
validate_read_result(&result, max_bytes)?;
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
pub async fn write_filesystem_file(
|
||||
&self,
|
||||
plugin_id: &str,
|
||||
provider_id: &str,
|
||||
connection_id: Option<&str>,
|
||||
uri: &str,
|
||||
data_base64: &str,
|
||||
create: bool,
|
||||
overwrite: bool,
|
||||
etag: Option<&str>,
|
||||
) -> Result<PluginFilesystemMutationResult, String> {
|
||||
let provider = self.resolve_filesystem_provider(plugin_id, provider_id)?;
|
||||
ensure_provider_capability(plugin_id, &provider, PluginFilesystemCapability::Write)?;
|
||||
let uri = resolve_filesystem_uri(&provider, Some(uri))?;
|
||||
validate_inline_write_data(data_base64)?;
|
||||
let request = PluginFilesystemWriteRequest {
|
||||
provider_id,
|
||||
connection_id: normalized_optional_value(connection_id),
|
||||
uri: &uri,
|
||||
data_base64,
|
||||
create,
|
||||
overwrite,
|
||||
etag: normalized_optional_value(etag),
|
||||
};
|
||||
let result =
|
||||
self.invoke_filesystem_mutation(plugin_id, &provider, PLUGIN_FILESYSTEM_WRITE_METHOD, request).await?;
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
pub async fn create_filesystem_directory(
|
||||
&self,
|
||||
plugin_id: &str,
|
||||
provider_id: &str,
|
||||
connection_id: Option<&str>,
|
||||
uri: &str,
|
||||
) -> Result<PluginFilesystemMutationResult, String> {
|
||||
let provider = self.resolve_filesystem_provider(plugin_id, provider_id)?;
|
||||
ensure_provider_capability(plugin_id, &provider, PluginFilesystemCapability::Mkdir)?;
|
||||
let uri = resolve_filesystem_uri(&provider, Some(uri))?;
|
||||
let request = PluginFilesystemCreateDirectoryRequest {
|
||||
provider_id,
|
||||
connection_id: normalized_optional_value(connection_id),
|
||||
uri: &uri,
|
||||
};
|
||||
self.invoke_filesystem_mutation(plugin_id, &provider, PLUGIN_FILESYSTEM_CREATE_DIRECTORY_METHOD, request).await
|
||||
}
|
||||
|
||||
pub async fn delete_filesystem_entry(
|
||||
&self,
|
||||
plugin_id: &str,
|
||||
provider_id: &str,
|
||||
connection_id: Option<&str>,
|
||||
uri: &str,
|
||||
recursive: bool,
|
||||
) -> Result<PluginFilesystemMutationResult, String> {
|
||||
let provider = self.resolve_filesystem_provider(plugin_id, provider_id)?;
|
||||
ensure_provider_capability(plugin_id, &provider, PluginFilesystemCapability::Delete)?;
|
||||
let uri = resolve_filesystem_uri(&provider, Some(uri))?;
|
||||
let request = PluginFilesystemDeleteRequest {
|
||||
provider_id,
|
||||
connection_id: normalized_optional_value(connection_id),
|
||||
uri: &uri,
|
||||
recursive,
|
||||
};
|
||||
self.invoke_filesystem_mutation(plugin_id, &provider, PLUGIN_FILESYSTEM_DELETE_METHOD, request).await
|
||||
}
|
||||
|
||||
pub async fn rename_filesystem_entry(
|
||||
&self,
|
||||
plugin_id: &str,
|
||||
provider_id: &str,
|
||||
connection_id: Option<&str>,
|
||||
source_uri: &str,
|
||||
target_uri: &str,
|
||||
overwrite: bool,
|
||||
) -> Result<PluginFilesystemMutationResult, String> {
|
||||
let provider = self.resolve_filesystem_provider(plugin_id, provider_id)?;
|
||||
ensure_provider_capability(plugin_id, &provider, PluginFilesystemCapability::Rename)?;
|
||||
let source_uri = resolve_filesystem_uri(&provider, Some(source_uri))?;
|
||||
let target_uri = resolve_filesystem_uri(&provider, Some(target_uri))?;
|
||||
let request = PluginFilesystemRenameRequest {
|
||||
provider_id,
|
||||
connection_id: normalized_optional_value(connection_id),
|
||||
source_uri: &source_uri,
|
||||
target_uri: &target_uri,
|
||||
overwrite,
|
||||
};
|
||||
self.invoke_filesystem_mutation(plugin_id, &provider, PLUGIN_FILESYSTEM_RENAME_METHOD, request).await
|
||||
}
|
||||
|
||||
async fn invoke_filesystem_mutation<T: Serialize>(
|
||||
&self,
|
||||
plugin_id: &str,
|
||||
provider: &PluginFilesystemProviderContribution,
|
||||
method: &str,
|
||||
request: T,
|
||||
) -> Result<PluginFilesystemMutationResult, String> {
|
||||
let result: PluginFilesystemMutationResult = self
|
||||
.invoke(
|
||||
plugin_id,
|
||||
method,
|
||||
serde_json::to_value(request).map_err(|error| error.to_string())?,
|
||||
None,
|
||||
Some(Duration::from_secs(30)),
|
||||
)
|
||||
.await?;
|
||||
validate_mutation_result(provider, &result)?;
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
fn resolve_filesystem_provider(
|
||||
&self,
|
||||
plugin_id: &str,
|
||||
provider_id: &str,
|
||||
) -> Result<PluginFilesystemProviderContribution, String> {
|
||||
let plugin =
|
||||
self.registry().find_plugin(plugin_id)?.ok_or_else(|| format!("Plugin '{plugin_id}' is not installed"))?;
|
||||
if !plugin.compatibility.compatible {
|
||||
return Err(format!("Plugin '{plugin_id}' is incompatible: {}", plugin.compatibility.errors.join("; ")));
|
||||
}
|
||||
plugin
|
||||
.manifest
|
||||
.filesystem_provider(provider_id)?
|
||||
.ok_or_else(|| format!("Filesystem provider '{plugin_id}/{provider_id}' is not declared"))
|
||||
}
|
||||
}
|
||||
|
||||
fn normalized_optional_value(value: Option<&str>) -> Option<&str> {
|
||||
value.map(str::trim).filter(|value| !value.is_empty())
|
||||
}
|
||||
|
||||
fn resolve_filesystem_uri(
|
||||
provider: &PluginFilesystemProviderContribution,
|
||||
requested_uri: Option<&str>,
|
||||
) -> Result<String, String> {
|
||||
let uri = requested_uri
|
||||
.map(str::trim)
|
||||
.filter(|uri| !uri.is_empty())
|
||||
.map(ToOwned::to_owned)
|
||||
.or_else(|| provider.root_uri.clone())
|
||||
.unwrap_or_else(|| format!("{}:/", provider.schemes[0]));
|
||||
if uri.len() > 4_096 || uri.chars().any(char::is_control) {
|
||||
return Err("Plugin filesystem URI is invalid".to_string());
|
||||
}
|
||||
let scheme = uri.split_once(':').map(|(scheme, _)| scheme).unwrap_or_default();
|
||||
if !provider.schemes.iter().any(|candidate| candidate == scheme) {
|
||||
return Err(format!("Filesystem URI scheme '{scheme}' is not handled by provider '{}'", provider.id));
|
||||
}
|
||||
Ok(uri)
|
||||
}
|
||||
|
||||
fn validate_list_result(
|
||||
provider: &PluginFilesystemProviderContribution,
|
||||
result: &PluginFilesystemListResult,
|
||||
requested_limit: u32,
|
||||
) -> Result<(), String> {
|
||||
let maximum_entries = usize::try_from(requested_limit).unwrap_or(usize::MAX);
|
||||
if result.entries.len() > maximum_entries {
|
||||
return Err(format!(
|
||||
"Filesystem provider '{}' returned {} entries for a limit of {requested_limit}",
|
||||
provider.id,
|
||||
result.entries.len()
|
||||
));
|
||||
}
|
||||
if result.next_cursor.as_ref().is_some_and(|cursor| cursor.is_empty() || cursor.len() > 4_096) {
|
||||
return Err(format!("Filesystem provider '{}' returned an invalid cursor", provider.id));
|
||||
}
|
||||
for entry in &result.entries {
|
||||
validate_entry(provider, entry)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn validate_entry(
|
||||
provider: &PluginFilesystemProviderContribution,
|
||||
entry: &PluginFilesystemEntry,
|
||||
) -> Result<(), String> {
|
||||
if entry.name.trim().is_empty() || entry.name.len() > 1_024 || entry.name.chars().any(char::is_control) {
|
||||
return Err(format!("Filesystem provider '{}' returned an invalid entry name", provider.id));
|
||||
}
|
||||
resolve_filesystem_uri(provider, Some(&entry.uri))?;
|
||||
if entry.modified_at.as_ref().is_some_and(|value| value.len() > 128) {
|
||||
return Err(format!("Filesystem provider '{}' returned an invalid modified timestamp", provider.id));
|
||||
}
|
||||
if entry.content_type.as_ref().is_some_and(|value| value.len() > 256 || value.chars().any(char::is_control)) {
|
||||
return Err(format!("Filesystem provider '{}' returned an invalid content type", provider.id));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn validate_read_result(result: &PluginFilesystemReadResult, max_bytes: u64) -> Result<(), String> {
|
||||
if result.content_type.as_ref().is_some_and(|value| value.len() > 256 || value.chars().any(char::is_control)) {
|
||||
return Err("Filesystem provider returned an invalid content type".to_string());
|
||||
}
|
||||
if result.etag.as_ref().is_some_and(|value| value.len() > 512 || value.chars().any(char::is_control)) {
|
||||
return Err("Filesystem provider returned an invalid etag".to_string());
|
||||
}
|
||||
let estimated_bytes = result.data_base64.len().saturating_mul(3) / 4;
|
||||
if estimated_bytes as u64 > max_bytes.saturating_add(2) {
|
||||
return Err(format!("Filesystem provider returned more than the requested {max_bytes} bytes"));
|
||||
}
|
||||
let decoded = base64::engine::general_purpose::STANDARD
|
||||
.decode(&result.data_base64)
|
||||
.map_err(|error| format!("Filesystem provider returned invalid base64 data: {error}"))?;
|
||||
if decoded.len() as u64 > max_bytes {
|
||||
return Err(format!("Filesystem provider returned more than the requested {max_bytes} bytes"));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn validate_inline_write_data(data_base64: &str) -> Result<(), String> {
|
||||
let estimated_bytes = data_base64.len().saturating_mul(3) / 4;
|
||||
if estimated_bytes as u64 > MAX_PLUGIN_FILESYSTEM_INLINE_WRITE_BYTES.saturating_add(2) {
|
||||
return Err(format!(
|
||||
"Inline plugin filesystem writes are limited to {MAX_PLUGIN_FILESYSTEM_INLINE_WRITE_BYTES} bytes"
|
||||
));
|
||||
}
|
||||
let decoded = base64::engine::general_purpose::STANDARD
|
||||
.decode(data_base64)
|
||||
.map_err(|error| format!("Plugin filesystem write contains invalid base64 data: {error}"))?;
|
||||
if decoded.len() as u64 > MAX_PLUGIN_FILESYSTEM_INLINE_WRITE_BYTES {
|
||||
return Err(format!(
|
||||
"Inline plugin filesystem writes are limited to {MAX_PLUGIN_FILESYSTEM_INLINE_WRITE_BYTES} bytes"
|
||||
));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn validate_mutation_result(
|
||||
provider: &PluginFilesystemProviderContribution,
|
||||
result: &PluginFilesystemMutationResult,
|
||||
) -> Result<(), String> {
|
||||
if !result.success {
|
||||
return Err(result.message.clone().unwrap_or_else(|| "Plugin filesystem operation failed".to_string()));
|
||||
}
|
||||
if result.message.as_ref().is_some_and(|message| message.len() > 4_096 || message.chars().any(char::is_control)) {
|
||||
return Err(format!("Filesystem provider '{}' returned an invalid operation message", provider.id));
|
||||
}
|
||||
if let Some(entry) = &result.entry {
|
||||
validate_entry(provider, entry)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn ensure_provider_capability(
|
||||
plugin_id: &str,
|
||||
provider: &PluginFilesystemProviderContribution,
|
||||
capability: PluginFilesystemCapability,
|
||||
) -> Result<(), String> {
|
||||
if provider.has_capability(capability) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(format!(
|
||||
"Filesystem provider '{plugin_id}/{}' does not declare {} capability",
|
||||
provider.id,
|
||||
capability.as_str()
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{resolve_filesystem_uri, validate_inline_write_data, validate_list_result, validate_read_result};
|
||||
use crate::plugins::{
|
||||
PluginFilesystemCapability, PluginFilesystemEntry, PluginFilesystemEntryKind, PluginFilesystemListResult,
|
||||
PluginFilesystemProviderContribution, PluginFilesystemReadResult,
|
||||
};
|
||||
|
||||
fn provider() -> PluginFilesystemProviderContribution {
|
||||
PluginFilesystemProviderContribution {
|
||||
id: "sample.files".to_string(),
|
||||
label: "Sample files".to_string(),
|
||||
schemes: vec!["sample".to_string()],
|
||||
description: None,
|
||||
capabilities: vec![PluginFilesystemCapability::Read],
|
||||
root_uri: Some("sample:/home".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resolves_declared_root_and_rejects_other_schemes() {
|
||||
assert_eq!(resolve_filesystem_uri(&provider(), None).unwrap(), "sample:/home");
|
||||
assert!(resolve_filesystem_uri(&provider(), Some("other:/tmp")).unwrap_err().contains("not handled"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn validates_list_limits_and_entry_uris() {
|
||||
let valid = PluginFilesystemListResult {
|
||||
entries: vec![PluginFilesystemEntry {
|
||||
name: "README.txt".to_string(),
|
||||
uri: "sample:/README.txt".to_string(),
|
||||
kind: PluginFilesystemEntryKind::File,
|
||||
size: Some(5),
|
||||
modified_at: None,
|
||||
content_type: Some("text/plain".to_string()),
|
||||
}],
|
||||
next_cursor: None,
|
||||
};
|
||||
validate_list_result(&provider(), &valid, 1).unwrap();
|
||||
assert!(validate_list_result(&provider(), &valid, 0).unwrap_err().contains("limit of 0"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_invalid_or_oversized_file_preview() {
|
||||
let invalid = PluginFilesystemReadResult {
|
||||
data_base64: "not base64".to_string(),
|
||||
content_type: None,
|
||||
truncated: false,
|
||||
etag: None,
|
||||
};
|
||||
assert!(validate_read_result(&invalid, 16).unwrap_err().contains("invalid base64"));
|
||||
|
||||
let oversized = PluginFilesystemReadResult {
|
||||
data_base64: "YWJjZA==".to_string(),
|
||||
content_type: None,
|
||||
truncated: false,
|
||||
etag: None,
|
||||
};
|
||||
assert!(validate_read_result(&oversized, 3).unwrap_err().contains("more than"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn validates_inline_write_base64() {
|
||||
validate_inline_write_data("YWJjZA==").unwrap();
|
||||
assert!(validate_inline_write_data("not base64").unwrap_err().contains("invalid base64"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,702 @@
|
||||
use std::collections::{BTreeMap, HashMap, HashSet};
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::models::connection::{ConnectionConfig, ConnectionTestResult, DatabaseType};
|
||||
use serde::de::DeserializeOwned;
|
||||
use serde::Serialize;
|
||||
use tokio::sync::{broadcast, Mutex, RwLock};
|
||||
|
||||
use super::{
|
||||
InstalledPlugin, PluginBinaryMessage, PluginConnectionActionContribution, PluginConnectionCapability,
|
||||
PluginConnectionProviderContribution, PluginEvent, PluginFormFieldBinding, PluginFormFieldDefinition,
|
||||
PluginFormFieldType, PluginRegistry, PluginRuntimeEnv, PluginSessionState, PluginSidecarSession,
|
||||
PLUGIN_CONNECTION_ACTION_METHOD, PLUGIN_CONNECTION_CONNECT_METHOD, PLUGIN_CONNECTION_DISCONNECT_METHOD,
|
||||
PLUGIN_CONNECTION_TEST_METHOD,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ActivePluginSession {
|
||||
pub plugin_id: String,
|
||||
pub process_id: Option<u32>,
|
||||
pub state: PluginSessionState,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct PluginConnectionActionResult {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub message: Option<String>,
|
||||
#[serde(skip_serializing_if = "BTreeMap::is_empty")]
|
||||
pub field_values: BTreeMap<String, serde_json::Value>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct PluginHost {
|
||||
inner: Arc<PluginHostInner>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct PluginConnectionHandle {
|
||||
pub plugin_id: String,
|
||||
pub provider_id: String,
|
||||
pub connection_id: String,
|
||||
session: Option<Arc<PluginSidecarSession>>,
|
||||
disconnect: bool,
|
||||
params: serde_json::Value,
|
||||
}
|
||||
|
||||
impl PluginConnectionHandle {
|
||||
pub fn is_running(&self) -> bool {
|
||||
self.session.as_ref().is_none_or(|session| session.status().state == PluginSessionState::Running)
|
||||
}
|
||||
|
||||
pub async fn disconnect(&self) -> Result<(), String> {
|
||||
let Some(session) = &self.session else {
|
||||
return Ok(());
|
||||
};
|
||||
if !self.disconnect || session.status().state != PluginSessionState::Running {
|
||||
return Ok(());
|
||||
}
|
||||
let result: serde_json::Value = session
|
||||
.invoke_with_timeout(
|
||||
PLUGIN_CONNECTION_DISCONNECT_METHOD,
|
||||
self.params.clone(),
|
||||
None,
|
||||
Some(super::PLUGIN_REQUEST_TIMEOUT),
|
||||
)
|
||||
.await?;
|
||||
ensure_plugin_operation_succeeded(result)
|
||||
}
|
||||
}
|
||||
|
||||
struct PluginHostInner {
|
||||
registry: PluginRegistry,
|
||||
sessions: RwLock<HashMap<String, Arc<PluginSidecarSession>>>,
|
||||
activation_lock: Mutex<()>,
|
||||
events: broadcast::Sender<PluginEvent>,
|
||||
binary_messages: broadcast::Sender<PluginBinaryMessage>,
|
||||
}
|
||||
|
||||
impl PluginHost {
|
||||
pub fn new(registry: PluginRegistry) -> Self {
|
||||
let (events, _) = broadcast::channel(512);
|
||||
let (binary_messages, _) = broadcast::channel(128);
|
||||
Self {
|
||||
inner: Arc::new(PluginHostInner {
|
||||
registry,
|
||||
sessions: RwLock::new(HashMap::new()),
|
||||
activation_lock: Mutex::new(()),
|
||||
events,
|
||||
binary_messages,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn subscribe_events(&self) -> broadcast::Receiver<PluginEvent> {
|
||||
self.inner.events.subscribe()
|
||||
}
|
||||
|
||||
pub fn subscribe_binary(&self) -> broadcast::Receiver<PluginBinaryMessage> {
|
||||
self.inner.binary_messages.subscribe()
|
||||
}
|
||||
|
||||
pub(super) fn registry(&self) -> &PluginRegistry {
|
||||
&self.inner.registry
|
||||
}
|
||||
|
||||
pub async fn activate(&self, plugin_id: &str) -> Result<Arc<PluginSidecarSession>, String> {
|
||||
self.activate_with_env(plugin_id, PluginRuntimeEnv::default()).await
|
||||
}
|
||||
|
||||
pub async fn activate_with_env(
|
||||
&self,
|
||||
plugin_id: &str,
|
||||
env: PluginRuntimeEnv,
|
||||
) -> Result<Arc<PluginSidecarSession>, String> {
|
||||
if let Some(session) = self.running_session(plugin_id).await {
|
||||
return Ok(session);
|
||||
}
|
||||
|
||||
let _activation = self.inner.activation_lock.lock().await;
|
||||
if let Some(session) = self.running_session(plugin_id).await {
|
||||
return Ok(session);
|
||||
}
|
||||
self.inner.sessions.write().await.remove(plugin_id);
|
||||
|
||||
let plugin = self
|
||||
.inner
|
||||
.registry
|
||||
.find_plugin(plugin_id)?
|
||||
.ok_or_else(|| format!("Plugin '{plugin_id}' is not installed"))?;
|
||||
if !plugin.compatibility.compatible {
|
||||
return Err(format!("Plugin '{plugin_id}' is incompatible: {}", plugin.compatibility.errors.join("; ")));
|
||||
}
|
||||
let session = PluginSidecarSession::start(plugin, self.inner.registry.app_version().to_string(), env).await?;
|
||||
self.forward_session_events(&session);
|
||||
self.inner.sessions.write().await.insert(plugin_id.to_string(), session.clone());
|
||||
Ok(session)
|
||||
}
|
||||
|
||||
pub async fn invoke<T>(
|
||||
&self,
|
||||
plugin_id: &str,
|
||||
method: &str,
|
||||
params: serde_json::Value,
|
||||
required_permission: Option<&str>,
|
||||
timeout: Option<Duration>,
|
||||
) -> Result<T, String>
|
||||
where
|
||||
T: DeserializeOwned,
|
||||
{
|
||||
let session = self.activate(plugin_id).await?;
|
||||
ensure_permission(session.plugin(), required_permission)?;
|
||||
session.invoke_with_timeout(method, params, None, timeout).await
|
||||
}
|
||||
|
||||
pub async fn notify(
|
||||
&self,
|
||||
plugin_id: &str,
|
||||
method: &str,
|
||||
params: serde_json::Value,
|
||||
required_permission: Option<&str>,
|
||||
) -> Result<(), String> {
|
||||
let session = self.activate(plugin_id).await?;
|
||||
ensure_permission(session.plugin(), required_permission)?;
|
||||
session.notify(method, params, None).await
|
||||
}
|
||||
|
||||
pub async fn send_binary(
|
||||
&self,
|
||||
plugin_id: &str,
|
||||
channel: &str,
|
||||
data: &[u8],
|
||||
required_permission: Option<&str>,
|
||||
) -> Result<(), String> {
|
||||
let session = self.activate(plugin_id).await?;
|
||||
ensure_permission(session.plugin(), required_permission)?;
|
||||
session.send_binary(channel, data).await
|
||||
}
|
||||
|
||||
pub async fn test_connection(
|
||||
&self,
|
||||
config: &ConnectionConfig,
|
||||
runtime_host: &str,
|
||||
runtime_port: u16,
|
||||
) -> Result<ConnectionTestResult, String> {
|
||||
let (plugin, provider) = self.resolve_connection_provider(config)?;
|
||||
validate_plugin_connection_values(config, &provider)?;
|
||||
let provider_label = provider.label.as_deref().unwrap_or(&plugin.manifest.name);
|
||||
if !provider.has_capability(PluginConnectionCapability::Test) {
|
||||
return Ok(ConnectionTestResult::success(format!("{provider_label} is available")));
|
||||
}
|
||||
let session = self.activate(config.plugin_id.as_deref().unwrap_or_default()).await?;
|
||||
let result: serde_json::Value = session
|
||||
.invoke_with_timeout(
|
||||
PLUGIN_CONNECTION_TEST_METHOD,
|
||||
plugin_connection_params(config, &provider, runtime_host, runtime_port)?,
|
||||
None,
|
||||
Some(Duration::from_secs(config.effective_connect_timeout_secs())),
|
||||
)
|
||||
.await?;
|
||||
plugin_connection_test_result(result, provider_label)
|
||||
}
|
||||
|
||||
pub async fn connect_connection(
|
||||
&self,
|
||||
config: &ConnectionConfig,
|
||||
runtime_host: &str,
|
||||
runtime_port: u16,
|
||||
) -> Result<PluginConnectionHandle, String> {
|
||||
let (_, provider) = self.resolve_connection_provider(config)?;
|
||||
validate_plugin_connection_values(config, &provider)?;
|
||||
let params = plugin_connection_params(config, &provider, runtime_host, runtime_port)?;
|
||||
let needs_session = provider.has_capability(PluginConnectionCapability::Connect)
|
||||
|| provider.has_capability(PluginConnectionCapability::Disconnect);
|
||||
let session = if needs_session {
|
||||
Some(self.activate(config.plugin_id.as_deref().unwrap_or_default()).await?)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
if provider.has_capability(PluginConnectionCapability::Connect) {
|
||||
if let Some(session) = &session {
|
||||
let result: serde_json::Value = session
|
||||
.invoke_with_timeout(
|
||||
PLUGIN_CONNECTION_CONNECT_METHOD,
|
||||
params.clone(),
|
||||
None,
|
||||
Some(Duration::from_secs(config.effective_connect_timeout_secs())),
|
||||
)
|
||||
.await?;
|
||||
ensure_plugin_operation_succeeded(result)?;
|
||||
}
|
||||
}
|
||||
let disconnect = provider.has_capability(PluginConnectionCapability::Disconnect);
|
||||
Ok(PluginConnectionHandle {
|
||||
plugin_id: config.plugin_id.clone().unwrap_or_default(),
|
||||
provider_id: provider.id,
|
||||
connection_id: config.id.clone(),
|
||||
session,
|
||||
disconnect,
|
||||
params,
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn invoke_connection_action(
|
||||
&self,
|
||||
config: &ConnectionConfig,
|
||||
action_id: &str,
|
||||
runtime_host: &str,
|
||||
runtime_port: u16,
|
||||
) -> Result<PluginConnectionActionResult, String> {
|
||||
let (_, provider) = self.resolve_connection_provider(config)?;
|
||||
let action = plugin_invoke_connection_action(&provider, action_id)?;
|
||||
validate_plugin_connection_values_for_action(config, &provider, action.requires_valid_form)?;
|
||||
let session = self.activate(config.plugin_id.as_deref().unwrap_or_default()).await?;
|
||||
let mut params = plugin_connection_params(config, &provider, runtime_host, runtime_port)?;
|
||||
params
|
||||
.as_object_mut()
|
||||
.ok_or("Plugin connection action params must be an object")?
|
||||
.insert("action".to_string(), serde_json::json!({ "id": action.id }));
|
||||
let result: serde_json::Value = session
|
||||
.invoke_with_timeout(
|
||||
PLUGIN_CONNECTION_ACTION_METHOD,
|
||||
params,
|
||||
None,
|
||||
action.timeout_ms.map(Duration::from_millis).or(Some(super::PLUGIN_REQUEST_TIMEOUT)),
|
||||
)
|
||||
.await?;
|
||||
plugin_connection_action_result(result, &provider)
|
||||
}
|
||||
|
||||
pub async fn list_active(&self) -> Vec<ActivePluginSession> {
|
||||
let sessions = self.inner.sessions.read().await.values().cloned().collect::<Vec<_>>();
|
||||
let mut active = Vec::with_capacity(sessions.len());
|
||||
for session in sessions {
|
||||
active.push(ActivePluginSession {
|
||||
plugin_id: session.plugin().manifest.id.clone(),
|
||||
process_id: session.pid().await,
|
||||
state: session.status().state,
|
||||
});
|
||||
}
|
||||
active.sort_by(|left, right| left.plugin_id.cmp(&right.plugin_id));
|
||||
active
|
||||
}
|
||||
|
||||
pub async fn stop(&self, plugin_id: &str) {
|
||||
if let Some(session) = self.inner.sessions.write().await.remove(plugin_id) {
|
||||
session.shutdown().await;
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn stop_all(&self) {
|
||||
let sessions = std::mem::take(&mut *self.inner.sessions.write().await);
|
||||
for (_, session) in sessions {
|
||||
session.shutdown().await;
|
||||
}
|
||||
}
|
||||
|
||||
async fn running_session(&self, plugin_id: &str) -> Option<Arc<PluginSidecarSession>> {
|
||||
let session = self.inner.sessions.read().await.get(plugin_id).cloned()?;
|
||||
(session.status().state == PluginSessionState::Running).then_some(session)
|
||||
}
|
||||
|
||||
fn resolve_connection_provider(
|
||||
&self,
|
||||
config: &ConnectionConfig,
|
||||
) -> Result<(InstalledPlugin, PluginConnectionProviderContribution), String> {
|
||||
if config.db_type != DatabaseType::Plugin {
|
||||
return Err("Connection is not a plugin-owned connection".to_string());
|
||||
}
|
||||
let plugin_id = required_plugin_binding(&config.plugin_id, "plugin_id")?;
|
||||
let provider_id = required_plugin_binding(&config.plugin_connection_provider, "plugin_connection_provider")?;
|
||||
let connection_type = required_plugin_binding(&config.plugin_connection_type, "plugin_connection_type")?;
|
||||
let plugin = self
|
||||
.inner
|
||||
.registry
|
||||
.find_plugin(plugin_id)?
|
||||
.ok_or_else(|| format!("Plugin '{plugin_id}' is not installed"))?;
|
||||
if !plugin.compatibility.compatible {
|
||||
return Err(format!("Plugin '{plugin_id}' is incompatible: {}", plugin.compatibility.errors.join("; ")));
|
||||
}
|
||||
let provider = plugin
|
||||
.manifest
|
||||
.connection_provider(provider_id)?
|
||||
.ok_or_else(|| format!("Plugin '{plugin_id}' does not provide connection provider '{provider_id}'"))?;
|
||||
if provider.database_type != connection_type {
|
||||
return Err(format!(
|
||||
"Connection type '{}' does not match provider '{}' type '{}'",
|
||||
connection_type, provider.id, provider.database_type
|
||||
));
|
||||
}
|
||||
Ok((plugin, provider))
|
||||
}
|
||||
|
||||
fn forward_session_events(&self, session: &Arc<PluginSidecarSession>) {
|
||||
let mut events = session.subscribe_events();
|
||||
let host_events = self.inner.events.clone();
|
||||
tokio::spawn(async move {
|
||||
loop {
|
||||
match events.recv().await {
|
||||
Ok(event) => {
|
||||
let _ = host_events.send(event);
|
||||
}
|
||||
Err(broadcast::error::RecvError::Lagged(skipped)) => {
|
||||
log::warn!("Plugin host event relay skipped {skipped} events");
|
||||
}
|
||||
Err(broadcast::error::RecvError::Closed) => break,
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
let mut binary = session.subscribe_binary();
|
||||
let host_binary = self.inner.binary_messages.clone();
|
||||
tokio::spawn(async move {
|
||||
loop {
|
||||
match binary.recv().await {
|
||||
Ok(message) => {
|
||||
let _ = host_binary.send(message);
|
||||
}
|
||||
Err(broadcast::error::RecvError::Lagged(skipped)) => {
|
||||
log::warn!("Plugin host binary relay skipped {skipped} messages");
|
||||
}
|
||||
Err(broadcast::error::RecvError::Closed) => break,
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
fn required_plugin_binding<'a>(value: &'a Option<String>, field: &str) -> Result<&'a str, String> {
|
||||
value
|
||||
.as_deref()
|
||||
.filter(|value| !value.trim().is_empty())
|
||||
.ok_or_else(|| format!("Plugin connection is missing {field}"))
|
||||
}
|
||||
|
||||
fn plugin_connection_params(
|
||||
config: &ConnectionConfig,
|
||||
provider: &PluginConnectionProviderContribution,
|
||||
runtime_host: &str,
|
||||
runtime_port: u16,
|
||||
) -> Result<serde_json::Value, String> {
|
||||
Ok(serde_json::json!({
|
||||
"provider": {
|
||||
"id": provider.id,
|
||||
"databaseType": provider.database_type,
|
||||
},
|
||||
"connection": serde_json::to_value(config).map_err(|error| error.to_string())?,
|
||||
"runtime": {
|
||||
"host": runtime_host,
|
||||
"port": runtime_port,
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
||||
fn validate_plugin_connection_values(
|
||||
config: &ConnectionConfig,
|
||||
provider: &PluginConnectionProviderContribution,
|
||||
) -> Result<(), String> {
|
||||
validate_plugin_connection_values_for_action(config, provider, true)
|
||||
}
|
||||
|
||||
fn plugin_invoke_connection_action<'a>(
|
||||
provider: &'a PluginConnectionProviderContribution,
|
||||
action_id: &str,
|
||||
) -> Result<&'a PluginConnectionActionContribution, String> {
|
||||
provider
|
||||
.actions
|
||||
.iter()
|
||||
.find(|action| action.id == action_id)
|
||||
.ok_or_else(|| format!("Connection provider '{}' does not declare action '{action_id}'", provider.id))
|
||||
}
|
||||
|
||||
fn validate_plugin_connection_values_for_action(
|
||||
config: &ConnectionConfig,
|
||||
provider: &PluginConnectionProviderContribution,
|
||||
require_required_fields: bool,
|
||||
) -> Result<(), String> {
|
||||
let allowed_secrets = provider
|
||||
.fields
|
||||
.iter()
|
||||
.filter(|field| field.effective_binding() == PluginFormFieldBinding::Secret)
|
||||
.map(|field| field.key.as_str())
|
||||
.collect::<HashSet<_>>();
|
||||
for key in config.connection_secrets.keys() {
|
||||
if !allowed_secrets.contains(key.as_str()) {
|
||||
return Err(format!("Connection secret '{key}' is not declared by provider '{}'", provider.id));
|
||||
}
|
||||
}
|
||||
for field in &provider.fields {
|
||||
let value = plugin_connection_field_value(config, field);
|
||||
if require_required_fields && field.required && plugin_field_value_is_empty(value.as_ref()) {
|
||||
return Err(format!("Plugin connection field '{}' is required", field.label));
|
||||
}
|
||||
if let Some(value) = value {
|
||||
validate_plugin_field_type(field, &value)?;
|
||||
if field.effective_binding() == PluginFormFieldBinding::Port
|
||||
&& value.as_u64().is_none_or(|port| port == 0 || port > u16::MAX as u64)
|
||||
{
|
||||
return Err(format!("Plugin connection field '{}' must be a port between 1 and 65535", field.label));
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn plugin_connection_action_result(
|
||||
result: serde_json::Value,
|
||||
provider: &PluginConnectionProviderContribution,
|
||||
) -> Result<PluginConnectionActionResult, String> {
|
||||
if let Some(message) = result.as_str() {
|
||||
return Ok(PluginConnectionActionResult { message: Some(message.to_string()), field_values: BTreeMap::new() });
|
||||
}
|
||||
if result.is_null() {
|
||||
return Ok(PluginConnectionActionResult::default());
|
||||
}
|
||||
let object = result
|
||||
.as_object()
|
||||
.ok_or_else(|| "Plugin connection action must return null, a message string, or an object".to_string())?;
|
||||
if object.get("success").and_then(serde_json::Value::as_bool) == Some(false) {
|
||||
return Err(object
|
||||
.get("message")
|
||||
.and_then(serde_json::Value::as_str)
|
||||
.unwrap_or("Plugin connection action failed")
|
||||
.to_string());
|
||||
}
|
||||
let message = match object.get("message") {
|
||||
None | Some(serde_json::Value::Null) => None,
|
||||
Some(serde_json::Value::String(message)) => Some(message.clone()),
|
||||
Some(_) => return Err("Plugin connection action message must be a string".to_string()),
|
||||
};
|
||||
let mut field_values = BTreeMap::new();
|
||||
if let Some(values) = object.get("fieldValues") {
|
||||
let values =
|
||||
values.as_object().ok_or_else(|| "Plugin connection action fieldValues must be an object".to_string())?;
|
||||
for (key, value) in values {
|
||||
let field = provider
|
||||
.fields
|
||||
.iter()
|
||||
.find(|field| field.key == *key)
|
||||
.ok_or_else(|| format!("Plugin connection action returned undeclared field '{key}'"))?;
|
||||
if !value.is_null() {
|
||||
validate_plugin_field_type(field, value)?;
|
||||
if field.effective_binding() == PluginFormFieldBinding::Port
|
||||
&& value.as_u64().is_none_or(|port| port == 0 || port > u16::MAX as u64)
|
||||
{
|
||||
return Err(format!(
|
||||
"Plugin connection field '{}' must be a port between 1 and 65535",
|
||||
field.label
|
||||
));
|
||||
}
|
||||
}
|
||||
field_values.insert(key.clone(), value.clone());
|
||||
}
|
||||
}
|
||||
Ok(PluginConnectionActionResult { message, field_values })
|
||||
}
|
||||
|
||||
fn plugin_connection_field_value(
|
||||
config: &ConnectionConfig,
|
||||
field: &PluginFormFieldDefinition,
|
||||
) -> Option<serde_json::Value> {
|
||||
match field.effective_binding() {
|
||||
PluginFormFieldBinding::Name => Some(serde_json::Value::String(config.name.clone())),
|
||||
PluginFormFieldBinding::Host => Some(serde_json::Value::String(config.host.clone())),
|
||||
PluginFormFieldBinding::Port => Some(serde_json::Value::Number(config.port.into())),
|
||||
PluginFormFieldBinding::Username => Some(serde_json::Value::String(config.username.clone())),
|
||||
PluginFormFieldBinding::Password => Some(serde_json::Value::String(config.password.clone())),
|
||||
PluginFormFieldBinding::Database => config.database.clone().map(serde_json::Value::String),
|
||||
PluginFormFieldBinding::Secret => {
|
||||
config.connection_secrets.get(&field.key).cloned().map(serde_json::Value::String)
|
||||
}
|
||||
PluginFormFieldBinding::Config => config.external_config.as_ref()?.get(&field.key).cloned(),
|
||||
}
|
||||
}
|
||||
|
||||
fn plugin_field_value_is_empty(value: Option<&serde_json::Value>) -> bool {
|
||||
match value {
|
||||
None | Some(serde_json::Value::Null) => true,
|
||||
Some(serde_json::Value::String(value)) => value.trim().is_empty(),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn validate_plugin_field_type(field: &PluginFormFieldDefinition, value: &serde_json::Value) -> Result<(), String> {
|
||||
let valid = match field.field_type {
|
||||
PluginFormFieldType::Text
|
||||
| PluginFormFieldType::Password
|
||||
| PluginFormFieldType::Select
|
||||
| PluginFormFieldType::Radio
|
||||
| PluginFormFieldType::Textarea => value.is_string(),
|
||||
PluginFormFieldType::Number => value.is_number(),
|
||||
PluginFormFieldType::Boolean => value.is_boolean(),
|
||||
};
|
||||
if valid {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(format!("Plugin connection field '{}' has an invalid value type", field.label))
|
||||
}
|
||||
}
|
||||
|
||||
fn plugin_connection_test_result(
|
||||
result: serde_json::Value,
|
||||
provider_label: &str,
|
||||
) -> Result<ConnectionTestResult, String> {
|
||||
if let Some(success) = result.get("success").and_then(serde_json::Value::as_bool) {
|
||||
let message = result.get("message").and_then(serde_json::Value::as_str).unwrap_or(if success {
|
||||
"Connection successful"
|
||||
} else {
|
||||
"Connection failed"
|
||||
});
|
||||
if !success {
|
||||
return Err(message.to_string());
|
||||
}
|
||||
return Ok(ConnectionTestResult::success(message));
|
||||
}
|
||||
if let Some(message) = result.as_str() {
|
||||
return Ok(ConnectionTestResult::success(message));
|
||||
}
|
||||
if result.is_null() {
|
||||
return Ok(ConnectionTestResult::success(format!("{provider_label} connection successful")));
|
||||
}
|
||||
serde_json::from_value(result)
|
||||
.map_err(|error| format!("Plugin connection test returned an invalid result: {error}"))
|
||||
}
|
||||
|
||||
fn ensure_plugin_operation_succeeded(result: serde_json::Value) -> Result<(), String> {
|
||||
if result.get("success").and_then(serde_json::Value::as_bool) == Some(false) {
|
||||
return Err(result
|
||||
.get("message")
|
||||
.and_then(serde_json::Value::as_str)
|
||||
.unwrap_or("Plugin connection operation failed")
|
||||
.to_string());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn ensure_permission(plugin: &super::InstalledPlugin, required_permission: Option<&str>) -> Result<(), String> {
|
||||
let Some(permission) = required_permission else {
|
||||
return Ok(());
|
||||
};
|
||||
if plugin.manifest.permissions.iter().any(|declared| declared == permission) {
|
||||
return Ok(());
|
||||
}
|
||||
Err(format!("Plugin '{}' has not declared permission '{permission}'", plugin.manifest.id))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{
|
||||
plugin_connection_action_result, plugin_invoke_connection_action, validate_plugin_connection_values,
|
||||
validate_plugin_connection_values_for_action,
|
||||
};
|
||||
use crate::models::connection::ConnectionConfig;
|
||||
use crate::plugins::PluginConnectionProviderContribution;
|
||||
|
||||
#[test]
|
||||
fn rejects_zero_port_for_port_bound_connection_field() {
|
||||
let config: ConnectionConfig = serde_json::from_value(serde_json::json!({
|
||||
"id": "plugin-connection",
|
||||
"name": "Plugin connection",
|
||||
"db_type": "plugin",
|
||||
"host": "localhost",
|
||||
"port": 0,
|
||||
"username": "",
|
||||
"password": "",
|
||||
"database": null,
|
||||
"plugin_id": "sample",
|
||||
"plugin_connection_provider": "sample.connection",
|
||||
"plugin_connection_type": "sample"
|
||||
}))
|
||||
.unwrap();
|
||||
let provider: PluginConnectionProviderContribution = serde_json::from_value(serde_json::json!({
|
||||
"id": "sample.connection",
|
||||
"label": "Sample",
|
||||
"database_type": "sample",
|
||||
"fields": [{ "key": "port", "label": "Port", "type": "number", "binding": "port", "required": true }]
|
||||
}))
|
||||
.unwrap();
|
||||
|
||||
assert!(validate_plugin_connection_values(&config, &provider)
|
||||
.unwrap_err()
|
||||
.contains("port between 1 and 65535"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn allows_incomplete_fields_only_for_declared_permissive_actions() {
|
||||
let config: ConnectionConfig = serde_json::from_value(serde_json::json!({
|
||||
"id": "plugin-connection",
|
||||
"name": "Plugin connection",
|
||||
"db_type": "plugin",
|
||||
"host": "",
|
||||
"port": 0,
|
||||
"username": "",
|
||||
"password": "",
|
||||
"database": null,
|
||||
"plugin_id": "sample",
|
||||
"plugin_connection_provider": "sample.connection",
|
||||
"plugin_connection_type": "sample"
|
||||
}))
|
||||
.unwrap();
|
||||
let provider: PluginConnectionProviderContribution = serde_json::from_value(serde_json::json!({
|
||||
"id": "sample.connection",
|
||||
"label": "Sample",
|
||||
"database_type": "sample",
|
||||
"fields": [{ "key": "host", "label": "Host", "type": "text", "binding": "host", "required": true }]
|
||||
}))
|
||||
.unwrap();
|
||||
|
||||
assert!(validate_plugin_connection_values_for_action(&config, &provider, false).is_ok());
|
||||
assert!(validate_plugin_connection_values_for_action(&config, &provider, true)
|
||||
.unwrap_err()
|
||||
.contains("is required"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resolves_only_declared_custom_actions() {
|
||||
let provider: PluginConnectionProviderContribution = serde_json::from_value(serde_json::json!({
|
||||
"id": "sample.connection",
|
||||
"label": "Sample",
|
||||
"database_type": "sample",
|
||||
"fields": [],
|
||||
"actions": [{ "id": "discover", "label": "Discover" }]
|
||||
}))
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(plugin_invoke_connection_action(&provider, "discover").unwrap().id, "discover");
|
||||
assert!(plugin_invoke_connection_action(&provider, "missing").unwrap_err().contains("does not declare action"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn validates_connection_action_field_updates() {
|
||||
let provider: PluginConnectionProviderContribution = serde_json::from_value(serde_json::json!({
|
||||
"id": "sample.connection",
|
||||
"label": "Sample",
|
||||
"database_type": "sample",
|
||||
"fields": [
|
||||
{ "key": "host", "label": "Host", "type": "text", "binding": "host" },
|
||||
{ "key": "port", "label": "Port", "type": "number", "binding": "port" }
|
||||
]
|
||||
}))
|
||||
.unwrap();
|
||||
|
||||
let result = plugin_connection_action_result(
|
||||
serde_json::json!({ "message": "Updated", "fieldValues": { "host": "db.internal", "port": 5432 } }),
|
||||
&provider,
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(result.message.as_deref(), Some("Updated"));
|
||||
assert_eq!(result.field_values.get("port").and_then(serde_json::Value::as_u64), Some(5432));
|
||||
assert!(plugin_connection_action_result(
|
||||
serde_json::json!({ "fieldValues": { "unknown": "value" } }),
|
||||
&provider,
|
||||
)
|
||||
.unwrap_err()
|
||||
.contains("undeclared field"));
|
||||
assert!(plugin_connection_action_result(serde_json::json!({ "fieldValues": { "port": "5432" } }), &provider,)
|
||||
.unwrap_err()
|
||||
.contains("invalid value type"));
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,912 @@
|
||||
use std::collections::HashMap;
|
||||
use std::path::Path;
|
||||
use std::process::Stdio;
|
||||
use std::sync::atomic::{AtomicU64, Ordering};
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
use bytes::Bytes;
|
||||
use serde::de::DeserializeOwned;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tokio::io::{AsyncBufRead, AsyncBufReadExt, AsyncReadExt, AsyncWriteExt, BufReader};
|
||||
use tokio::process::{Child, ChildStdin, ChildStdout};
|
||||
use tokio::sync::{broadcast, oneshot, watch, Mutex, RwLock};
|
||||
use tokio::time::timeout;
|
||||
|
||||
use super::{
|
||||
InstalledPlugin, PluginBackendTransport, PluginRuntimeEnv, SUPPORTED_PLUGIN_HOST_API_VERSION,
|
||||
SUPPORTED_PLUGIN_PROTOCOL_VERSION,
|
||||
};
|
||||
|
||||
pub const PLUGIN_REQUEST_TIMEOUT: Duration = Duration::from_secs(30);
|
||||
const MAX_JSON_MESSAGE_BYTES: usize = 8 * 1024 * 1024;
|
||||
const MAX_BINARY_MESSAGE_BYTES: usize = 64 * 1024 * 1024;
|
||||
const FRAME_KIND_JSON: u8 = 0;
|
||||
const FRAME_KIND_BINARY: u8 = 1;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct PluginEvent {
|
||||
pub plugin_id: String,
|
||||
pub method: String,
|
||||
#[serde(default)]
|
||||
pub params: serde_json::Value,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct PluginBinaryMessage {
|
||||
pub plugin_id: String,
|
||||
pub channel: String,
|
||||
pub data: Bytes,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum PluginSessionState {
|
||||
Starting,
|
||||
Running,
|
||||
Stopping,
|
||||
Stopped,
|
||||
Exited,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct PluginSessionStatus {
|
||||
pub state: PluginSessionState,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub message: Option<String>,
|
||||
}
|
||||
|
||||
impl PluginSessionStatus {
|
||||
fn new(state: PluginSessionState, message: Option<String>) -> Self {
|
||||
Self { state, message }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct PluginHandshake {
|
||||
pub protocol_version: u32,
|
||||
#[serde(default)]
|
||||
pub capabilities: Vec<String>,
|
||||
pub plugin: PluginHandshakeIdentity,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub struct PluginHandshakeIdentity {
|
||||
pub id: String,
|
||||
pub version: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct PluginInitializeParams<'a> {
|
||||
host: PluginHostDescription<'a>,
|
||||
plugin: PluginDescription<'a>,
|
||||
permissions: &'a [String],
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct PluginHostDescription<'a> {
|
||||
dbx_version: &'a str,
|
||||
host_api_version: &'static str,
|
||||
protocol_versions: [u32; 1],
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct PluginDescription<'a> {
|
||||
id: &'a str,
|
||||
version: &'a str,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
struct PluginRequest<'a> {
|
||||
jsonrpc: &'static str,
|
||||
id: u64,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
driver: Option<&'a str>,
|
||||
method: &'a str,
|
||||
params: serde_json::Value,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
struct PluginNotification<'a> {
|
||||
jsonrpc: &'static str,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
driver: Option<&'a str>,
|
||||
method: &'a str,
|
||||
params: serde_json::Value,
|
||||
}
|
||||
|
||||
type PendingResponse = oneshot::Sender<Result<serde_json::Value, String>>;
|
||||
|
||||
pub struct PluginSidecarSession {
|
||||
plugin: InstalledPlugin,
|
||||
app_version: String,
|
||||
transport: PluginBackendTransport,
|
||||
child: Arc<Mutex<Child>>,
|
||||
stdin: Mutex<ChildStdin>,
|
||||
pending: Arc<Mutex<HashMap<u64, PendingResponse>>>,
|
||||
next_request_id: AtomicU64,
|
||||
events: broadcast::Sender<PluginEvent>,
|
||||
binary_messages: broadcast::Sender<PluginBinaryMessage>,
|
||||
status: watch::Sender<PluginSessionStatus>,
|
||||
handshake: RwLock<Option<PluginHandshake>>,
|
||||
}
|
||||
|
||||
impl PluginSidecarSession {
|
||||
pub async fn start(
|
||||
plugin: InstalledPlugin,
|
||||
app_version: impl Into<String>,
|
||||
env: PluginRuntimeEnv,
|
||||
) -> Result<Arc<Self>, String> {
|
||||
ensure_plugin_backend(&plugin)?;
|
||||
let transport = plugin.manifest.backend_entrypoint().map(|backend| backend.transport).unwrap_or_default();
|
||||
let app_version = app_version.into();
|
||||
let mut child = spawn_plugin_child(&plugin, &app_version, &env)?;
|
||||
let stdin = child.stdin.take().ok_or("Plugin stdin unavailable")?;
|
||||
let stdout = child.stdout.take().ok_or("Plugin stdout unavailable")?;
|
||||
let stderr = child.stderr.take();
|
||||
let child = Arc::new(Mutex::new(child));
|
||||
let pending = Arc::new(Mutex::new(HashMap::new()));
|
||||
let (events, _) = broadcast::channel(256);
|
||||
let (binary_messages, _) = broadcast::channel(64);
|
||||
let (status, _) = watch::channel(PluginSessionStatus::new(PluginSessionState::Starting, None));
|
||||
let session = Arc::new(Self {
|
||||
plugin,
|
||||
app_version,
|
||||
transport,
|
||||
child,
|
||||
stdin: Mutex::new(stdin),
|
||||
pending,
|
||||
next_request_id: AtomicU64::new(1),
|
||||
events,
|
||||
binary_messages,
|
||||
status,
|
||||
handshake: RwLock::new(None),
|
||||
});
|
||||
|
||||
session.spawn_stdout_reader(stdout);
|
||||
if let Some(stderr) = stderr {
|
||||
session.spawn_stderr_reader(stderr);
|
||||
}
|
||||
|
||||
if !session.plugin.manifest.is_legacy() {
|
||||
let handshake = match session.initialize().await {
|
||||
Ok(handshake) => handshake,
|
||||
Err(error) => {
|
||||
session.shutdown().await;
|
||||
return Err(format!("Plugin '{}' initialization failed: {error}", session.plugin.manifest.id));
|
||||
}
|
||||
};
|
||||
*session.handshake.write().await = Some(handshake);
|
||||
}
|
||||
let transitioned = session.status.send_if_modified(|status| {
|
||||
if status.state != PluginSessionState::Starting {
|
||||
return false;
|
||||
}
|
||||
*status = PluginSessionStatus::new(PluginSessionState::Running, None);
|
||||
true
|
||||
});
|
||||
if !transitioned {
|
||||
let status = session.status();
|
||||
session.shutdown().await;
|
||||
return Err(format!(
|
||||
"Plugin '{}' stopped during initialization{}",
|
||||
session.plugin.manifest.id,
|
||||
status.message.map_or_else(String::new, |message| format!(": {message}"))
|
||||
));
|
||||
}
|
||||
Ok(session)
|
||||
}
|
||||
|
||||
pub fn plugin(&self) -> &InstalledPlugin {
|
||||
&self.plugin
|
||||
}
|
||||
|
||||
pub fn subscribe_events(&self) -> broadcast::Receiver<PluginEvent> {
|
||||
self.events.subscribe()
|
||||
}
|
||||
|
||||
pub fn subscribe_binary(&self) -> broadcast::Receiver<PluginBinaryMessage> {
|
||||
self.binary_messages.subscribe()
|
||||
}
|
||||
|
||||
pub fn subscribe_status(&self) -> watch::Receiver<PluginSessionStatus> {
|
||||
self.status.subscribe()
|
||||
}
|
||||
|
||||
pub fn status(&self) -> PluginSessionStatus {
|
||||
self.status.borrow().clone()
|
||||
}
|
||||
|
||||
pub async fn handshake(&self) -> Option<PluginHandshake> {
|
||||
self.handshake.read().await.clone()
|
||||
}
|
||||
|
||||
pub async fn invoke<T>(&self, method: &str, params: serde_json::Value) -> Result<T, String>
|
||||
where
|
||||
T: DeserializeOwned,
|
||||
{
|
||||
self.invoke_with_timeout(method, params, None, Some(PLUGIN_REQUEST_TIMEOUT)).await
|
||||
}
|
||||
|
||||
pub async fn invoke_with_timeout<T>(
|
||||
&self,
|
||||
method: &str,
|
||||
params: serde_json::Value,
|
||||
driver: Option<&str>,
|
||||
timeout_duration: Option<Duration>,
|
||||
) -> Result<T, String>
|
||||
where
|
||||
T: DeserializeOwned,
|
||||
{
|
||||
let value = self.invoke_value(method, params, driver, timeout_duration).await?;
|
||||
serde_json::from_value(value)
|
||||
.map_err(|error| format!("Failed to decode plugin '{}' result: {error}", self.plugin.manifest.id))
|
||||
}
|
||||
|
||||
pub async fn notify(&self, method: &str, params: serde_json::Value, driver: Option<&str>) -> Result<(), String> {
|
||||
self.ensure_running()?;
|
||||
validate_protocol_name(method)?;
|
||||
let notification = PluginNotification { jsonrpc: "2.0", driver, method, params };
|
||||
let payload = serde_json::to_vec(¬ification).map_err(|error| error.to_string())?;
|
||||
self.write_json(&payload).await
|
||||
}
|
||||
|
||||
pub async fn send_binary(&self, channel: &str, data: &[u8]) -> Result<(), String> {
|
||||
self.ensure_running()?;
|
||||
if self.transport != PluginBackendTransport::StdioFramed {
|
||||
return Err(format!(
|
||||
"Plugin '{}' does not use the framed transport required for binary messages",
|
||||
self.plugin.manifest.id
|
||||
));
|
||||
}
|
||||
validate_binary_channel(channel)?;
|
||||
if data.len() > MAX_BINARY_MESSAGE_BYTES {
|
||||
return Err(format!("Plugin binary message exceeds {MAX_BINARY_MESSAGE_BYTES} bytes"));
|
||||
}
|
||||
let channel_bytes = channel.as_bytes();
|
||||
let payload_len = 2usize
|
||||
.checked_add(channel_bytes.len())
|
||||
.and_then(|length| length.checked_add(data.len()))
|
||||
.ok_or("Plugin binary frame is too large")?;
|
||||
let mut stdin = self.stdin.lock().await;
|
||||
stdin.write_u8(FRAME_KIND_BINARY).await.map_err(|error| self.write_error(error))?;
|
||||
stdin.write_u32(payload_len as u32).await.map_err(|error| self.write_error(error))?;
|
||||
stdin.write_u16(channel_bytes.len() as u16).await.map_err(|error| self.write_error(error))?;
|
||||
stdin.write_all(channel_bytes).await.map_err(|error| self.write_error(error))?;
|
||||
stdin.write_all(data).await.map_err(|error| self.write_error(error))?;
|
||||
stdin.flush().await.map_err(|error| self.write_error(error))
|
||||
}
|
||||
|
||||
pub async fn shutdown(&self) {
|
||||
self.status.send_replace(PluginSessionStatus::new(PluginSessionState::Stopping, None));
|
||||
let kill_result = self.child.lock().await.kill().await;
|
||||
let message = kill_result.err().map(|error| error.to_string());
|
||||
fail_pending(&self.pending, "Plugin session stopped").await;
|
||||
self.status.send_replace(PluginSessionStatus::new(PluginSessionState::Stopped, message));
|
||||
}
|
||||
|
||||
pub async fn pid(&self) -> Option<u32> {
|
||||
self.child.lock().await.id()
|
||||
}
|
||||
|
||||
async fn initialize(&self) -> Result<PluginHandshake, String> {
|
||||
let params = PluginInitializeParams {
|
||||
host: PluginHostDescription {
|
||||
dbx_version: &self.app_version,
|
||||
host_api_version: SUPPORTED_PLUGIN_HOST_API_VERSION,
|
||||
protocol_versions: [SUPPORTED_PLUGIN_PROTOCOL_VERSION],
|
||||
},
|
||||
plugin: PluginDescription { id: &self.plugin.manifest.id, version: &self.plugin.manifest.version },
|
||||
permissions: &self.plugin.manifest.permissions,
|
||||
};
|
||||
let params = serde_json::to_value(params).map_err(|error| error.to_string())?;
|
||||
let handshake: PluginHandshake =
|
||||
self.invoke_with_timeout("plugin/initialize", params, None, Some(PLUGIN_REQUEST_TIMEOUT)).await?;
|
||||
if handshake.protocol_version != SUPPORTED_PLUGIN_PROTOCOL_VERSION {
|
||||
return Err(format!(
|
||||
"Plugin selected protocol version {}, expected {}",
|
||||
handshake.protocol_version, SUPPORTED_PLUGIN_PROTOCOL_VERSION
|
||||
));
|
||||
}
|
||||
if handshake.plugin.id != self.plugin.manifest.id || handshake.plugin.version != self.plugin.manifest.version {
|
||||
return Err(format!(
|
||||
"Plugin backend identity '{}/{}' does not match manifest '{}/{}'",
|
||||
handshake.plugin.id, handshake.plugin.version, self.plugin.manifest.id, self.plugin.manifest.version
|
||||
));
|
||||
}
|
||||
Ok(handshake)
|
||||
}
|
||||
|
||||
async fn invoke_value(
|
||||
&self,
|
||||
method: &str,
|
||||
params: serde_json::Value,
|
||||
driver: Option<&str>,
|
||||
timeout_duration: Option<Duration>,
|
||||
) -> Result<serde_json::Value, String> {
|
||||
self.ensure_running_or_starting()?;
|
||||
validate_protocol_name(method)?;
|
||||
let request_id = self.next_request_id.fetch_add(1, Ordering::Relaxed);
|
||||
let request = PluginRequest { jsonrpc: "2.0", id: request_id, driver, method, params };
|
||||
let payload = serde_json::to_vec(&request).map_err(|error| error.to_string())?;
|
||||
let (sender, receiver) = oneshot::channel();
|
||||
self.pending.lock().await.insert(request_id, sender);
|
||||
if let Err(error) = self.write_json(&payload).await {
|
||||
self.pending.lock().await.remove(&request_id);
|
||||
return Err(error);
|
||||
}
|
||||
|
||||
let receive = async {
|
||||
receiver.await.map_err(|_| format!("Plugin '{}' response channel closed", self.plugin.manifest.id))?
|
||||
};
|
||||
match timeout_duration {
|
||||
Some(duration) => match timeout(duration, receive).await {
|
||||
Ok(result) => result,
|
||||
Err(_) => {
|
||||
self.pending.lock().await.remove(&request_id);
|
||||
Err(format!(
|
||||
"Plugin '{}' request '{}' timed out after {} seconds",
|
||||
self.plugin.manifest.id,
|
||||
method,
|
||||
duration.as_secs()
|
||||
))
|
||||
}
|
||||
},
|
||||
None => receive.await,
|
||||
}
|
||||
}
|
||||
|
||||
async fn write_json(&self, payload: &[u8]) -> Result<(), String> {
|
||||
if payload.len() > MAX_JSON_MESSAGE_BYTES {
|
||||
return Err(format!("Plugin JSON message exceeds {MAX_JSON_MESSAGE_BYTES} bytes"));
|
||||
}
|
||||
let mut stdin = self.stdin.lock().await;
|
||||
match self.transport {
|
||||
PluginBackendTransport::StdioJsonLines => {
|
||||
stdin.write_all(payload).await.map_err(|error| self.write_error(error))?;
|
||||
stdin.write_u8(b'\n').await.map_err(|error| self.write_error(error))?;
|
||||
}
|
||||
PluginBackendTransport::StdioFramed => {
|
||||
stdin.write_u8(FRAME_KIND_JSON).await.map_err(|error| self.write_error(error))?;
|
||||
stdin.write_u32(payload.len() as u32).await.map_err(|error| self.write_error(error))?;
|
||||
stdin.write_all(payload).await.map_err(|error| self.write_error(error))?;
|
||||
}
|
||||
}
|
||||
stdin.flush().await.map_err(|error| self.write_error(error))
|
||||
}
|
||||
|
||||
fn write_error(&self, error: std::io::Error) -> String {
|
||||
format!("Failed to write to plugin '{}': {error}", self.plugin.manifest.id)
|
||||
}
|
||||
|
||||
fn ensure_running(&self) -> Result<(), String> {
|
||||
let status = self.status();
|
||||
if status.state == PluginSessionState::Running {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(format!("Plugin '{}' is not running ({:?})", self.plugin.manifest.id, status.state))
|
||||
}
|
||||
}
|
||||
|
||||
fn ensure_running_or_starting(&self) -> Result<(), String> {
|
||||
let status = self.status();
|
||||
if matches!(status.state, PluginSessionState::Starting | PluginSessionState::Running) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(format!("Plugin '{}' is not available ({:?})", self.plugin.manifest.id, status.state))
|
||||
}
|
||||
}
|
||||
|
||||
fn spawn_stdout_reader(self: &Arc<Self>, stdout: ChildStdout) {
|
||||
let session = self.clone();
|
||||
tokio::spawn(async move {
|
||||
let result = match session.transport {
|
||||
PluginBackendTransport::StdioJsonLines => read_json_lines(&session, BufReader::new(stdout)).await,
|
||||
PluginBackendTransport::StdioFramed => read_framed(&session, stdout).await,
|
||||
};
|
||||
let message = match result {
|
||||
Ok(()) => session.exit_message().await,
|
||||
Err(error) => error,
|
||||
};
|
||||
fail_pending(&session.pending, &message).await;
|
||||
if matches!(session.status().state, PluginSessionState::Stopping | PluginSessionState::Stopped) {
|
||||
return;
|
||||
}
|
||||
let message = session.terminate_after_output_end(message).await;
|
||||
session.status.send_if_modified(|status| {
|
||||
if matches!(status.state, PluginSessionState::Stopping | PluginSessionState::Stopped) {
|
||||
return false;
|
||||
}
|
||||
*status = PluginSessionStatus::new(PluginSessionState::Exited, Some(message.clone()));
|
||||
true
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
fn spawn_stderr_reader(self: &Arc<Self>, stderr: tokio::process::ChildStderr) {
|
||||
let plugin_id = self.plugin.manifest.id.clone();
|
||||
tokio::spawn(async move {
|
||||
let mut reader = BufReader::new(stderr);
|
||||
loop {
|
||||
match read_limited_line(&mut reader, MAX_JSON_MESSAGE_BYTES).await {
|
||||
Ok(Some(line)) => log::warn!("[plugin:{plugin_id}] {}", String::from_utf8_lossy(&line).trim_end()),
|
||||
Ok(None) => break,
|
||||
Err(error) => {
|
||||
log::warn!("[plugin:{plugin_id}] failed to read stderr: {error}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async fn exit_message(&self) -> String {
|
||||
match self.child.lock().await.try_wait() {
|
||||
Ok(Some(status)) => format!("Plugin '{}' exited with status {status}", self.plugin.manifest.id),
|
||||
Ok(None) => format!("Plugin '{}' closed its output stream", self.plugin.manifest.id),
|
||||
Err(error) => format!("Plugin '{}' output closed: {error}", self.plugin.manifest.id),
|
||||
}
|
||||
}
|
||||
|
||||
async fn terminate_after_output_end(&self, message: String) -> String {
|
||||
let mut child = self.child.lock().await;
|
||||
match child.try_wait() {
|
||||
Ok(Some(_)) => message,
|
||||
Ok(None) => match child.kill().await {
|
||||
Ok(()) => format!("{message}; process terminated by host"),
|
||||
Err(error) => format!("{message}; failed to terminate process: {error}"),
|
||||
},
|
||||
Err(error) => format!("{message}; failed to inspect process: {error}"),
|
||||
}
|
||||
}
|
||||
|
||||
async fn dispatch_json(&self, payload: &[u8]) -> Result<(), String> {
|
||||
let value: serde_json::Value = serde_json::from_slice(payload).map_err(|error| {
|
||||
format!("Failed to parse plugin '{}' protocol message: {error}", self.plugin.manifest.id)
|
||||
})?;
|
||||
if !self.plugin.manifest.is_legacy() && value.get("jsonrpc").and_then(serde_json::Value::as_str) != Some("2.0")
|
||||
{
|
||||
return Err(format!("Plugin '{}' sent a message without jsonrpc 2.0", self.plugin.manifest.id));
|
||||
}
|
||||
if let Some(request_id) = value.get("id").and_then(serde_json::Value::as_u64) {
|
||||
let result = decode_response_value(&self.plugin.manifest.id, value);
|
||||
if let Some(sender) = self.pending.lock().await.remove(&request_id) {
|
||||
let _ = sender.send(result);
|
||||
} else {
|
||||
log::warn!("[plugin:{}] ignored response for unknown request {request_id}", self.plugin.manifest.id);
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
if let Some(method) = value.get("method").and_then(serde_json::Value::as_str) {
|
||||
if !self.plugin.manifest.is_legacy() {
|
||||
validate_protocol_name(method)?;
|
||||
}
|
||||
let event = PluginEvent {
|
||||
plugin_id: self.plugin.manifest.id.clone(),
|
||||
method: method.to_string(),
|
||||
params: value.get("params").cloned().unwrap_or(serde_json::Value::Null),
|
||||
};
|
||||
let _ = self.events.send(event);
|
||||
return Ok(());
|
||||
}
|
||||
Err(format!("Plugin '{}' sent a protocol message without id or method", self.plugin.manifest.id))
|
||||
}
|
||||
|
||||
fn dispatch_binary(&self, payload: Bytes) -> Result<(), String> {
|
||||
if payload.len() < 2 {
|
||||
return Err(format!("Plugin '{}' sent an invalid binary frame", self.plugin.manifest.id));
|
||||
}
|
||||
let channel_len = u16::from_be_bytes([payload[0], payload[1]]) as usize;
|
||||
if channel_len == 0 || payload.len() < 2 + channel_len {
|
||||
return Err(format!("Plugin '{}' sent an invalid binary channel", self.plugin.manifest.id));
|
||||
}
|
||||
let channel = std::str::from_utf8(&payload[2..2 + channel_len]).map_err(|error| {
|
||||
format!("Plugin '{}' sent a non-UTF-8 binary channel: {error}", self.plugin.manifest.id)
|
||||
})?;
|
||||
validate_binary_channel(channel)?;
|
||||
let message = PluginBinaryMessage {
|
||||
plugin_id: self.plugin.manifest.id.clone(),
|
||||
channel: channel.to_string(),
|
||||
data: payload.slice(2 + channel_len..),
|
||||
};
|
||||
let _ = self.binary_messages.send(message);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
async fn read_json_lines(session: &PluginSidecarSession, mut reader: BufReader<ChildStdout>) -> Result<(), String> {
|
||||
loop {
|
||||
let Some(line) = read_limited_line(&mut reader, MAX_JSON_MESSAGE_BYTES)
|
||||
.await
|
||||
.map_err(|error| format!("Failed to read plugin '{}' output: {error}", session.plugin.manifest.id))?
|
||||
else {
|
||||
return Ok(());
|
||||
};
|
||||
let trimmed = trim_ascii_whitespace(&line);
|
||||
if trimmed.is_empty() {
|
||||
continue;
|
||||
}
|
||||
if let Err(error) = session.dispatch_json(trimmed).await {
|
||||
if !session.plugin.manifest.is_legacy() {
|
||||
return Err(error);
|
||||
}
|
||||
log::warn!(
|
||||
"[plugin:{}] ignored non-protocol stdout: {} ({error})",
|
||||
session.plugin.manifest.id,
|
||||
String::from_utf8_lossy(trimmed)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn read_framed(session: &PluginSidecarSession, mut stdout: ChildStdout) -> Result<(), String> {
|
||||
loop {
|
||||
let kind = match stdout.read_u8().await {
|
||||
Ok(kind) => kind,
|
||||
Err(error) if error.kind() == std::io::ErrorKind::UnexpectedEof => return Ok(()),
|
||||
Err(error) => {
|
||||
return Err(format!("Failed to read plugin '{}' frame kind: {error}", session.plugin.manifest.id))
|
||||
}
|
||||
};
|
||||
let length =
|
||||
stdout.read_u32().await.map_err(|error| {
|
||||
format!("Failed to read plugin '{}' frame length: {error}", session.plugin.manifest.id)
|
||||
})? as usize;
|
||||
let maximum = if kind == FRAME_KIND_JSON { MAX_JSON_MESSAGE_BYTES } else { MAX_BINARY_MESSAGE_BYTES + 1024 };
|
||||
if length > maximum {
|
||||
return Err(format!("Plugin '{}' frame exceeds {maximum} bytes", session.plugin.manifest.id));
|
||||
}
|
||||
let mut payload = vec![0; length];
|
||||
stdout.read_exact(&mut payload).await.map_err(|error| {
|
||||
format!("Failed to read plugin '{}' frame payload: {error}", session.plugin.manifest.id)
|
||||
})?;
|
||||
match kind {
|
||||
FRAME_KIND_JSON => session.dispatch_json(&payload).await?,
|
||||
FRAME_KIND_BINARY => session.dispatch_binary(Bytes::from(payload))?,
|
||||
_ => return Err(format!("Plugin '{}' sent unknown frame kind {kind}", session.plugin.manifest.id)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn read_limited_line<R>(reader: &mut R, maximum: usize) -> std::io::Result<Option<Vec<u8>>>
|
||||
where
|
||||
R: AsyncBufRead + Unpin,
|
||||
{
|
||||
let mut output = Vec::new();
|
||||
loop {
|
||||
let available = reader.fill_buf().await?;
|
||||
if available.is_empty() {
|
||||
return if output.is_empty() { Ok(None) } else { Ok(Some(output)) };
|
||||
}
|
||||
let take = available.iter().position(|byte| *byte == b'\n').map(|index| index + 1).unwrap_or(available.len());
|
||||
if output.len().saturating_add(take) > maximum {
|
||||
return Err(std::io::Error::new(std::io::ErrorKind::InvalidData, "plugin output line is too large"));
|
||||
}
|
||||
output.extend_from_slice(&available[..take]);
|
||||
reader.consume(take);
|
||||
if output.last() == Some(&b'\n') {
|
||||
return Ok(Some(output));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn trim_ascii_whitespace(mut bytes: &[u8]) -> &[u8] {
|
||||
while bytes.first().is_some_and(u8::is_ascii_whitespace) {
|
||||
bytes = &bytes[1..];
|
||||
}
|
||||
while bytes.last().is_some_and(u8::is_ascii_whitespace) {
|
||||
bytes = &bytes[..bytes.len() - 1];
|
||||
}
|
||||
bytes
|
||||
}
|
||||
|
||||
fn decode_response_value(plugin_id: &str, value: serde_json::Value) -> Result<serde_json::Value, String> {
|
||||
if let Some(error) = value.get("error") {
|
||||
let message = error
|
||||
.get("message")
|
||||
.and_then(serde_json::Value::as_str)
|
||||
.map(str::to_string)
|
||||
.unwrap_or_else(|| error.to_string());
|
||||
return Err(message);
|
||||
}
|
||||
if value.get("result").is_none() && value.get("error").is_none() {
|
||||
return Err(format!("Plugin '{plugin_id}' response has neither result nor error"));
|
||||
}
|
||||
Ok(value.get("result").cloned().unwrap_or(serde_json::Value::Null))
|
||||
}
|
||||
|
||||
async fn fail_pending(pending: &Mutex<HashMap<u64, PendingResponse>>, message: &str) {
|
||||
let responses = std::mem::take(&mut *pending.lock().await);
|
||||
for (_, sender) in responses {
|
||||
let _ = sender.send(Err(message.to_string()));
|
||||
}
|
||||
}
|
||||
|
||||
fn validate_binary_channel(channel: &str) -> Result<(), String> {
|
||||
if channel.is_empty() || channel.len() > u16::MAX as usize {
|
||||
return Err("Plugin binary channel must contain 1-65535 bytes".to_string());
|
||||
}
|
||||
if channel.chars().any(char::is_whitespace) {
|
||||
return Err("Plugin binary channel cannot contain whitespace".to_string());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn validate_protocol_name(value: &str) -> Result<(), String> {
|
||||
if value.is_empty()
|
||||
|| value.len() > 256
|
||||
|| !value
|
||||
.chars()
|
||||
.all(|character| character.is_ascii_alphanumeric() || matches!(character, '.' | '_' | ':' | '/' | '-'))
|
||||
{
|
||||
return Err("Plugin protocol name is invalid".to_string());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn ensure_plugin_backend(plugin: &InstalledPlugin) -> Result<(), String> {
|
||||
if !plugin.compatibility.compatible {
|
||||
return Err(format!(
|
||||
"Plugin '{}' is incompatible: {}",
|
||||
plugin.manifest.id,
|
||||
plugin.compatibility.errors.join("; ")
|
||||
));
|
||||
}
|
||||
if plugin.compatibility.backend_executable.is_none() {
|
||||
return Err(format!("Plugin '{}' does not provide a backend entrypoint", plugin.manifest.id));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn spawn_plugin_child(plugin: &InstalledPlugin, app_version: &str, env: &PluginRuntimeEnv) -> Result<Child, String> {
|
||||
let executable_path =
|
||||
plugin.compatibility.backend_executable.as_ref().ok_or_else(|| {
|
||||
format!("Plugin '{}' does not provide a compatible backend executable", plugin.manifest.id)
|
||||
})?;
|
||||
ensure_executable_permission(executable_path)?;
|
||||
let mut command = crate::process::new_tokio_command(executable_path);
|
||||
command
|
||||
.current_dir(&plugin.path)
|
||||
.stdin(Stdio::piped())
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.kill_on_drop(true)
|
||||
.env("DBX_PLUGIN_ID", &plugin.manifest.id)
|
||||
.env("DBX_PLUGIN_VERSION", &plugin.manifest.version)
|
||||
.env("DBX_APP_VERSION", app_version)
|
||||
.env("DBX_HOST_API_VERSION", SUPPORTED_PLUGIN_HOST_API_VERSION)
|
||||
.env("DBX_PLUGIN_PROTOCOL_VERSION", SUPPORTED_PLUGIN_PROTOCOL_VERSION.to_string());
|
||||
env.apply_to(&mut command);
|
||||
command.spawn().map_err(|error| format!("Failed to start plugin '{}': {error}", plugin.manifest.id))
|
||||
}
|
||||
|
||||
fn ensure_executable_permission(path: &Path) -> Result<(), String> {
|
||||
#[cfg(unix)]
|
||||
{
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
|
||||
let mode = std::fs::metadata(path).map_err(|error| error.to_string())?.permissions().mode();
|
||||
if mode & 0o111 == 0 {
|
||||
return Err(format!("Plugin backend is not executable: {}", path.display()));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::time::Duration;
|
||||
|
||||
use super::{
|
||||
decode_response_value, read_limited_line, trim_ascii_whitespace, PluginSessionState, PluginSidecarSession,
|
||||
};
|
||||
use crate::plugins::{InstalledPlugin, PluginManifest, PluginRuntimeEnv};
|
||||
use tokio::io::BufReader;
|
||||
|
||||
#[tokio::test]
|
||||
async fn rejects_oversized_json_lines_before_unbounded_growth() {
|
||||
let mut reader = BufReader::new(std::io::Cursor::new(b"123456\n"));
|
||||
let error = read_limited_line(&mut reader, 4).await.expect_err("line should be rejected");
|
||||
assert_eq!(error.kind(), std::io::ErrorKind::InvalidData);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn decodes_json_rpc_result_and_error() {
|
||||
assert_eq!(
|
||||
decode_response_value("sample", serde_json::json!({ "id": 1, "result": { "ok": true } })).unwrap(),
|
||||
serde_json::json!({ "ok": true })
|
||||
);
|
||||
assert_eq!(
|
||||
decode_response_value("sample", serde_json::json!({ "id": 1, "error": { "message": "boom" } }))
|
||||
.unwrap_err(),
|
||||
"boom"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn trims_protocol_whitespace() {
|
||||
assert_eq!(trim_ascii_whitespace(b" \n{}\r\n"), b"{}");
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[tokio::test]
|
||||
async fn negotiates_routes_concurrent_responses_and_forwards_events() {
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let executable = dir.path().join("plugin.sh");
|
||||
std::fs::write(
|
||||
&executable,
|
||||
r#"#!/bin/sh
|
||||
IFS= read -r initialize
|
||||
initialize_id=$(printf '%s' "$initialize" | sed -E 's/.*"id":([0-9]+).*/\1/')
|
||||
printf '{"jsonrpc":"2.0","id":%s,"result":{"protocolVersion":1,"capabilities":["events"],"plugin":{"id":"sample.sidecar","version":"1.0.0"}}}\n' "$initialize_id"
|
||||
IFS= read -r first
|
||||
IFS= read -r second
|
||||
first_id=$(printf '%s' "$first" | sed -E 's/.*"id":([0-9]+).*/\1/')
|
||||
second_id=$(printf '%s' "$second" | sed -E 's/.*"id":([0-9]+).*/\1/')
|
||||
first_method=$(printf '%s' "$first" | sed -E 's/.*"method":"([^"]+)".*/\1/')
|
||||
second_method=$(printf '%s' "$second" | sed -E 's/.*"method":"([^"]+)".*/\1/')
|
||||
printf '{"jsonrpc":"2.0","method":"sample/progress","params":{"value":50}}\n'
|
||||
printf '{"jsonrpc":"2.0","id":%s,"result":"%s"}\n' "$second_id" "$second_method"
|
||||
printf '{"jsonrpc":"2.0","id":%s,"result":"%s"}\n' "$first_id" "$first_method"
|
||||
sleep 30
|
||||
"#,
|
||||
)
|
||||
.unwrap();
|
||||
let mut permissions = std::fs::metadata(&executable).unwrap().permissions();
|
||||
permissions.set_mode(0o755);
|
||||
std::fs::set_permissions(&executable, permissions).unwrap();
|
||||
|
||||
let manifest: PluginManifest = serde_json::from_value(serde_json::json!({
|
||||
"manifest_version": 1,
|
||||
"id": "sample.sidecar",
|
||||
"name": "Sample Sidecar",
|
||||
"version": "1.0.0",
|
||||
"publisher": "dbx",
|
||||
"engines": { "dbx": ">=0.1.0", "host_api": "^1.0" },
|
||||
"permissions": ["host.events"],
|
||||
"entrypoints": {
|
||||
"backend": {
|
||||
"protocol_versions": [1],
|
||||
"transport": "stdio-jsonl",
|
||||
"executable": "plugin.sh"
|
||||
}
|
||||
}
|
||||
}))
|
||||
.unwrap();
|
||||
let plugin = InstalledPlugin::new(manifest, dir.path().to_path_buf(), "0.5.67");
|
||||
let session = PluginSidecarSession::start(plugin, "0.5.67", PluginRuntimeEnv::default())
|
||||
.await
|
||||
.expect("v1 sidecar should initialize");
|
||||
assert_eq!(session.status().state, PluginSessionState::Running);
|
||||
assert_eq!(session.handshake().await.unwrap().capabilities, vec!["events"]);
|
||||
let mut events = session.subscribe_events();
|
||||
|
||||
let first = session.invoke::<String>("sample/first", serde_json::Value::Null);
|
||||
let second = session.invoke::<String>("sample/second", serde_json::Value::Null);
|
||||
let (first, second) = tokio::join!(first, second);
|
||||
|
||||
assert_eq!(first.unwrap(), "sample/first");
|
||||
assert_eq!(second.unwrap(), "sample/second");
|
||||
let event = events.recv().await.unwrap();
|
||||
assert_eq!(event.method, "sample/progress");
|
||||
assert_eq!(event.params["value"], 50);
|
||||
session.shutdown().await;
|
||||
assert_eq!(session.status().state, PluginSessionState::Stopped);
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[tokio::test]
|
||||
async fn failed_initialize_terminates_plugin_process() {
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let executable = dir.path().join("plugin.sh");
|
||||
let pid_file = dir.path().join("plugin.pid");
|
||||
std::fs::write(
|
||||
&executable,
|
||||
format!(
|
||||
r#"#!/bin/sh
|
||||
printf '%s' "$$" > '{}'
|
||||
IFS= read -r initialize
|
||||
initialize_id=$(printf '%s' "$initialize" | sed -E 's/.*"id":([0-9]+).*/\1/')
|
||||
printf '{{"jsonrpc":"2.0","id":%s,"result":{{"protocolVersion":1,"capabilities":[],"plugin":{{"id":"wrong.sidecar","version":"1.0.0"}}}}}}\n' "$initialize_id"
|
||||
sleep 30
|
||||
"#,
|
||||
pid_file.display()
|
||||
),
|
||||
)
|
||||
.unwrap();
|
||||
let mut permissions = std::fs::metadata(&executable).unwrap().permissions();
|
||||
permissions.set_mode(0o755);
|
||||
std::fs::set_permissions(&executable, permissions).unwrap();
|
||||
|
||||
let manifest: PluginManifest = serde_json::from_value(serde_json::json!({
|
||||
"manifest_version": 1,
|
||||
"id": "sample.sidecar",
|
||||
"name": "Sample Sidecar",
|
||||
"version": "1.0.0",
|
||||
"publisher": "dbx",
|
||||
"engines": { "dbx": ">=0.1.0", "host_api": "^1.0" },
|
||||
"entrypoints": {
|
||||
"backend": {
|
||||
"protocol_versions": [1],
|
||||
"transport": "stdio-jsonl",
|
||||
"executable": "plugin.sh"
|
||||
}
|
||||
}
|
||||
}))
|
||||
.unwrap();
|
||||
let plugin = InstalledPlugin::new(manifest, dir.path().to_path_buf(), "0.5.67");
|
||||
let error = match PluginSidecarSession::start(plugin, "0.5.67", PluginRuntimeEnv::default()).await {
|
||||
Ok(session) => {
|
||||
session.shutdown().await;
|
||||
panic!("mismatched backend identity should fail initialization")
|
||||
}
|
||||
Err(error) => error,
|
||||
};
|
||||
assert!(error.contains("does not match manifest"));
|
||||
|
||||
let pid = std::fs::read_to_string(&pid_file).unwrap().parse::<u32>().unwrap();
|
||||
for _ in 0..20 {
|
||||
if !process_exists(pid) {
|
||||
return;
|
||||
}
|
||||
tokio::time::sleep(Duration::from_millis(10)).await;
|
||||
}
|
||||
assert!(!process_exists(pid), "plugin process {pid} survived failed initialization");
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[tokio::test]
|
||||
async fn legacy_jsonl_runtime_ignores_banner_output() {
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let executable = dir.path().join("plugin.sh");
|
||||
std::fs::write(
|
||||
&executable,
|
||||
r#"#!/bin/sh
|
||||
IFS= read -r request
|
||||
request_id=$(printf '%s' "$request" | sed -E 's/.*"id":([0-9]+).*/\1/')
|
||||
printf 'legacy banner\n'
|
||||
printf '{"id":%s,"result":{"ok":true}}\n' "$request_id"
|
||||
sleep 30
|
||||
"#,
|
||||
)
|
||||
.unwrap();
|
||||
let mut permissions = std::fs::metadata(&executable).unwrap().permissions();
|
||||
permissions.set_mode(0o755);
|
||||
std::fs::set_permissions(&executable, permissions).unwrap();
|
||||
|
||||
let manifest: PluginManifest = serde_json::from_value(serde_json::json!({
|
||||
"id": "legacy",
|
||||
"name": "Legacy",
|
||||
"executable": "plugin.sh"
|
||||
}))
|
||||
.unwrap();
|
||||
let plugin = InstalledPlugin::new(manifest, dir.path().to_path_buf(), "0.5.67");
|
||||
let session = PluginSidecarSession::start(plugin, "0.5.67", PluginRuntimeEnv::default()).await.unwrap();
|
||||
let result: serde_json::Value = session.invoke("ping", serde_json::Value::Null).await.unwrap();
|
||||
assert_eq!(result["ok"], true);
|
||||
session.shutdown().await;
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
fn process_exists(pid: u32) -> bool {
|
||||
std::process::Command::new("kill")
|
||||
.arg("-0")
|
||||
.arg(pid.to_string())
|
||||
.stderr(std::process::Stdio::null())
|
||||
.status()
|
||||
.map(|status| status.success())
|
||||
.unwrap_or(false)
|
||||
}
|
||||
}
|
||||
@@ -810,6 +810,10 @@ mod tests {
|
||||
gbase_server: String::new(),
|
||||
informix_server: String::new(),
|
||||
external_config: None,
|
||||
plugin_id: None,
|
||||
plugin_connection_provider: None,
|
||||
plugin_connection_type: None,
|
||||
connection_secrets: Default::default(),
|
||||
one_time: false,
|
||||
save_password: true,
|
||||
read_only: false,
|
||||
|
||||
@@ -2318,6 +2318,7 @@ async fn do_execute_typed(
|
||||
.await
|
||||
.map(|result| truncate_result_with_max_rows(result, max_rows))
|
||||
}
|
||||
PoolKind::PluginConnection(_) => Err("SQL execution is not supported for plugin connections".to_string()),
|
||||
PoolKind::HBase(_) => Err("SQL execution is not supported for HBase connections".to_string()),
|
||||
PoolKind::DynamoDb(client) => {
|
||||
let client = client.clone();
|
||||
@@ -4098,7 +4099,8 @@ fn pool_kind_has_transactional_path(pool: &PoolKind) -> bool {
|
||||
| PoolKind::InfluxDb(_)
|
||||
| PoolKind::InfluxDb3(_)
|
||||
| PoolKind::VictoriaMetrics(_)
|
||||
| PoolKind::ExternalDriver { .. } => false,
|
||||
| PoolKind::ExternalDriver { .. }
|
||||
| PoolKind::PluginConnection(_) => false,
|
||||
#[cfg(feature = "mq-admin")]
|
||||
PoolKind::Mqtt(_) => false,
|
||||
}
|
||||
@@ -4468,7 +4470,8 @@ fn batch_transaction_path(pool: &PoolKind) -> BatchTransactionPath {
|
||||
| PoolKind::InfluxDb(_)
|
||||
| PoolKind::InfluxDb3(_)
|
||||
| PoolKind::VictoriaMetrics(_)
|
||||
| PoolKind::ExternalDriver { .. } => BatchTransactionPath::Unsupported,
|
||||
| PoolKind::ExternalDriver { .. }
|
||||
| PoolKind::PluginConnection(_) => BatchTransactionPath::Unsupported,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6553,7 +6556,8 @@ mod tests {
|
||||
use crate::models::connection::{default_redis_key_separator, ConnectionConfig, DatabaseType};
|
||||
#[cfg(unix)]
|
||||
use crate::plugins::{
|
||||
InstalledPlugin, PluginDriverManifest, PluginDriverSession, PluginManifest, PluginRuntimeEnv,
|
||||
InstalledPlugin, PluginCompatibility, PluginDriverManifest, PluginDriverSession, PluginManifest,
|
||||
PluginRuntimeEnv,
|
||||
};
|
||||
use crate::storage::Storage;
|
||||
|
||||
@@ -6880,6 +6884,10 @@ for line in sys.stdin:
|
||||
gbase_server: String::new(),
|
||||
informix_server: String::new(),
|
||||
external_config: None,
|
||||
plugin_id: None,
|
||||
plugin_connection_provider: None,
|
||||
plugin_connection_type: None,
|
||||
connection_secrets: Default::default(),
|
||||
jdbc_driver_class: None,
|
||||
jdbc_driver_paths: Vec::new(),
|
||||
one_time: false,
|
||||
@@ -8671,8 +8679,14 @@ for line in sys.stdin:
|
||||
kind: "external".to_string(),
|
||||
database_type: Some("jdbc".to_string()),
|
||||
}],
|
||||
..Default::default()
|
||||
},
|
||||
path: dir.clone(),
|
||||
compatibility: PluginCompatibility {
|
||||
compatible: true,
|
||||
backend_executable: Some(dir.join("plugin.sh")),
|
||||
..Default::default()
|
||||
},
|
||||
};
|
||||
let session = PluginDriverSession::start_for_test(plugin, "jdbc".to_string(), PluginRuntimeEnv::default())
|
||||
.await
|
||||
@@ -8771,8 +8785,14 @@ for line in sys.stdin:
|
||||
kind: "external".to_string(),
|
||||
database_type: Some("jdbc".to_string()),
|
||||
}],
|
||||
..Default::default()
|
||||
},
|
||||
path: dir.clone(),
|
||||
compatibility: PluginCompatibility {
|
||||
compatible: true,
|
||||
backend_executable: Some(dir.join("plugin.sh")),
|
||||
..Default::default()
|
||||
},
|
||||
};
|
||||
let session = Arc::new(
|
||||
PluginDriverSession::start_for_test(plugin, "jdbc".to_string(), PluginRuntimeEnv::default())
|
||||
@@ -8881,8 +8901,14 @@ for line in sys.stdin:
|
||||
kind: "external".to_string(),
|
||||
database_type: Some("jdbc".to_string()),
|
||||
}],
|
||||
..Default::default()
|
||||
},
|
||||
path: dir.clone(),
|
||||
compatibility: PluginCompatibility {
|
||||
compatible: true,
|
||||
backend_executable: Some(dir.join("plugin.sh")),
|
||||
..Default::default()
|
||||
},
|
||||
};
|
||||
let session = PluginDriverSession::start_for_test(plugin, "jdbc".to_string(), PluginRuntimeEnv::default())
|
||||
.await
|
||||
@@ -8939,8 +8965,14 @@ for line in sys.stdin:
|
||||
kind: "external".to_string(),
|
||||
database_type: Some("jdbc".to_string()),
|
||||
}],
|
||||
..Default::default()
|
||||
},
|
||||
path: dir.clone(),
|
||||
compatibility: PluginCompatibility {
|
||||
compatible: true,
|
||||
backend_executable: Some(dir.join("plugin.sh")),
|
||||
..Default::default()
|
||||
},
|
||||
};
|
||||
let session = PluginDriverSession::start_for_test(plugin, "jdbc".to_string(), PluginRuntimeEnv::default())
|
||||
.await
|
||||
@@ -9400,6 +9432,10 @@ for line in sys.stdin:
|
||||
gbase_server: String::new(),
|
||||
informix_server: String::new(),
|
||||
external_config: None,
|
||||
plugin_id: None,
|
||||
plugin_connection_provider: None,
|
||||
plugin_connection_type: None,
|
||||
connection_secrets: Default::default(),
|
||||
jdbc_driver_class: None,
|
||||
jdbc_driver_paths: Vec::new(),
|
||||
one_time: false,
|
||||
|
||||
@@ -3409,6 +3409,10 @@ mod tests {
|
||||
gbase_server: String::new(),
|
||||
informix_server: String::new(),
|
||||
external_config: None,
|
||||
plugin_id: None,
|
||||
plugin_connection_provider: None,
|
||||
plugin_connection_type: None,
|
||||
connection_secrets: HashMap::new(),
|
||||
jdbc_driver_class: None,
|
||||
jdbc_driver_paths: Vec::new(),
|
||||
one_time: false,
|
||||
@@ -3636,8 +3640,14 @@ done
|
||||
kind: "external".to_string(),
|
||||
database_type: Some("jdbc".to_string()),
|
||||
}],
|
||||
..PluginManifest::default()
|
||||
},
|
||||
path: dir.clone(),
|
||||
compatibility: crate::plugins::PluginCompatibility {
|
||||
compatible: true,
|
||||
backend_executable: Some(dir.join("plugin.sh")),
|
||||
..Default::default()
|
||||
},
|
||||
};
|
||||
let session = std::sync::Arc::new(
|
||||
PluginDriverSession::start_for_test(plugin, "jdbc".to_string(), PluginRuntimeEnv::default()).await.unwrap(),
|
||||
|
||||
@@ -187,7 +187,12 @@ mod tests {
|
||||
redis_key_separator: default_redis_key_separator(),
|
||||
etcd_endpoints: String::new(),
|
||||
gbase_server: String::new(),
|
||||
informix_server: String::new(), external_config: None,
|
||||
informix_server: String::new(),
|
||||
plugin_id: None,
|
||||
plugin_connection_provider: None,
|
||||
plugin_connection_type: None,
|
||||
connection_secrets: Default::default(),
|
||||
external_config: None,
|
||||
jdbc_driver_class: None,
|
||||
jdbc_driver_paths: Vec::new(),
|
||||
one_time: false,
|
||||
@@ -211,7 +216,7 @@ mod tests {
|
||||
numeric_precision: None,
|
||||
numeric_scale: None,
|
||||
character_maximum_length: None,
|
||||
..Default::default()
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -818,6 +818,8 @@ pub fn profile_for(db_type: DatabaseType) -> DdlDialectProfile {
|
||||
|
||||
InfluxDb => influxdb_profile(),
|
||||
|
||||
Plugin => conservative_ansi(db_type),
|
||||
|
||||
// Non-tabular / not applicable for relational CREATE TABLE
|
||||
Redis | MongoDb | DynamoDb | Elasticsearch | Easysearch | Meilisearch | Qdrant | Milvus | Weaviate
|
||||
| ChromaDb | Neo4j | Cassandra | Etcd | ZooKeeper | Nacos | Consul | InfluxDb3 | VictoriaMetrics
|
||||
|
||||
@@ -18,7 +18,7 @@ use crate::connection_secrets::{
|
||||
CASSANDRA_KEYSTORE_PASSWORD_KEY, CASSANDRA_TLS_SECRET_PREFIX, CASSANDRA_TRUSTSTORE_PASSWORD_KEY,
|
||||
MQ_AUTH_API_KEY_VALUE_KEY, MQ_AUTH_CLIENT_SECRET_KEY, MQ_AUTH_PASSWORD_KEY, MQ_AUTH_SECRET_PREFIX,
|
||||
MQ_AUTH_TOKEN_KEY, MQ_TOKEN_SIGNING_KEY, MQ_TOKEN_SIGNING_SECRET_PREFIX, NACOS_AUTH_PASSWORD_KEY,
|
||||
NACOS_AUTH_SECRET_PREFIX, NACOS_RNACOS_CONSOLE_PASSWORD_KEY,
|
||||
NACOS_AUTH_SECRET_PREFIX, NACOS_RNACOS_CONSOLE_PASSWORD_KEY, PLUGIN_CONNECTION_SECRET_PREFIX,
|
||||
};
|
||||
use crate::db::sqlite::{connect_path_create_if_missing, SqliteHandle};
|
||||
use crate::history::{
|
||||
@@ -3203,6 +3203,7 @@ fn sanitized_connection_config(config: &ConnectionConfig) -> ConnectionConfig {
|
||||
scrub_mq_token_signing_secret(&mut sanitized);
|
||||
scrub_nacos_auth_secrets(&mut sanitized);
|
||||
scrub_cassandra_tls_secrets(&mut sanitized);
|
||||
sanitized.connection_secrets.clear();
|
||||
sanitized
|
||||
}
|
||||
|
||||
@@ -3279,7 +3280,40 @@ fn persist_connection_in_tx(tx: &rusqlite::Transaction<'_>, config: &ConnectionC
|
||||
persist_mq_auth_secrets_in_tx(tx, &config)?;
|
||||
persist_mq_token_signing_secret_in_tx(tx, &config)?;
|
||||
persist_nacos_auth_secrets_in_tx(tx, &config)?;
|
||||
persist_cassandra_tls_secrets_in_tx(tx, &config)
|
||||
persist_cassandra_tls_secrets_in_tx(tx, &config)?;
|
||||
delete_secret_prefix_in_tx(tx, &config.id, PLUGIN_CONNECTION_SECRET_PREFIX)?;
|
||||
for (key, secret) in &config.connection_secrets {
|
||||
if !key.is_empty() {
|
||||
persist_secret_in_tx(tx, &config.id, &format!("{PLUGIN_CONNECTION_SECRET_PREFIX}{key}"), secret)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn load_plugin_connection_secrets(
|
||||
storage: &Storage,
|
||||
connection_id: &str,
|
||||
) -> Result<HashMap<String, String>, String> {
|
||||
let connection_id = connection_id.to_string();
|
||||
storage
|
||||
.with_conn(move |conn| {
|
||||
let like = format!("{PLUGIN_CONNECTION_SECRET_PREFIX}%");
|
||||
let mut statement = conn
|
||||
.prepare("SELECT key, secret FROM connection_secrets WHERE connection_id = ?1 AND key LIKE ?2")
|
||||
.map_err(|error| error.to_string())?;
|
||||
let rows = statement
|
||||
.query_map(params![connection_id, like], |row| Ok((row.get::<_, String>(0)?, row.get::<_, String>(1)?)))
|
||||
.map_err(|error| error.to_string())?;
|
||||
let mut secrets = HashMap::new();
|
||||
for row in rows {
|
||||
let (key, secret) = row.map_err(|error| error.to_string())?;
|
||||
if let Some(key) = key.strip_prefix(PLUGIN_CONNECTION_SECRET_PREFIX) {
|
||||
secrets.insert(key.to_string(), secret);
|
||||
}
|
||||
}
|
||||
Ok(secrets)
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
fn insert_connection_copy_next_to_source(entries: &mut Vec<serde_json::Value>, source_id: &str, copy_id: &str) -> bool {
|
||||
@@ -3415,6 +3449,7 @@ impl Storage {
|
||||
scrub_mq_token_signing_secret(&mut sanitized);
|
||||
scrub_nacos_auth_secrets(&mut sanitized);
|
||||
scrub_cassandra_tls_secrets(&mut sanitized);
|
||||
sanitized.connection_secrets.clear();
|
||||
let json = serde_json::to_string(&sanitized).map_err(|e| e.to_string())?;
|
||||
|
||||
tx.execute("INSERT INTO connections (id, config_json) VALUES (?1, ?2)", params![config_id, json])
|
||||
@@ -3733,6 +3768,10 @@ impl Storage {
|
||||
config.redis_sentinel_password = self.get_secret(&id, "redis_sentinel_password").await?.unwrap_or_default();
|
||||
config.connection_string = self.get_secret(&id, "connection_string").await?;
|
||||
config.init_script = self.get_secret(&id, "init_script").await?;
|
||||
let stored_plugin_secrets = load_plugin_connection_secrets(self, &id).await?;
|
||||
if !stored_plugin_secrets.is_empty() {
|
||||
config.connection_secrets = stored_plugin_secrets;
|
||||
}
|
||||
let needs_mq_auth_rewrite = self.hydrate_mq_auth_secrets(&id, &mut config).await?;
|
||||
let needs_mq_token_signing_rewrite = self.hydrate_mq_token_signing_secret(&id, &mut config).await?;
|
||||
let needs_nacos_auth_rewrite = self.hydrate_nacos_auth_secret(&id, &mut config).await?;
|
||||
@@ -4276,6 +4315,21 @@ impl Storage {
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn delete_secret_prefix(&self, connection_id: &str, key_prefix: &str) -> Result<(), String> {
|
||||
let connection_id = connection_id.to_string();
|
||||
let key_prefix = key_prefix.to_string();
|
||||
self.with_conn(move |conn| {
|
||||
let like = format!("{key_prefix}%");
|
||||
conn.execute(
|
||||
"DELETE FROM connection_secrets WHERE connection_id = ?1 AND key LIKE ?2",
|
||||
params![connection_id, like],
|
||||
)
|
||||
.map(|_| ())
|
||||
.map_err(|error| error.to_string())
|
||||
})
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
// MQ token records
|
||||
@@ -5300,7 +5354,7 @@ mod tests {
|
||||
use crate::connection_secrets::NACOS_RNACOS_CONSOLE_PASSWORD_KEY;
|
||||
use crate::connection_secrets::{
|
||||
CASSANDRA_KEYSTORE_PASSWORD_KEY, CASSANDRA_TRUSTSTORE_PASSWORD_KEY, MQ_AUTH_PASSWORD_KEY, MQ_AUTH_TOKEN_KEY,
|
||||
MQ_TOKEN_SIGNING_KEY, NACOS_AUTH_PASSWORD_KEY,
|
||||
MQ_TOKEN_SIGNING_KEY, NACOS_AUTH_PASSWORD_KEY, PLUGIN_CONNECTION_SECRET_PREFIX,
|
||||
};
|
||||
use crate::history::{HistoryConnectionFilter, HistoryDatabaseFilter, HistoryEntry, HistorySearchRequest};
|
||||
use crate::models::connection::{
|
||||
@@ -6029,6 +6083,41 @@ mod tests {
|
||||
let _ = std::fs::remove_file(path);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn save_connections_moves_plugin_secrets_to_secret_table_and_restores_them() {
|
||||
let path = temp_db_path("plugin-secrets");
|
||||
let storage = Storage::open(&path).await.unwrap();
|
||||
let mut config = plain_connection("plugin", "");
|
||||
config.db_type = DatabaseType::Plugin;
|
||||
config.plugin_id = Some("example.plugin".to_string());
|
||||
config.plugin_connection_provider = Some("example.connection".to_string());
|
||||
config.connection_secrets.insert("api_token".to_string(), "plugin-secret".to_string());
|
||||
|
||||
storage.save_connections(std::slice::from_ref(&config)).await.unwrap();
|
||||
|
||||
let raw_json = raw_connection_json(&storage, &config.id).await;
|
||||
assert!(!raw_json.contains("plugin-secret"));
|
||||
assert_eq!(
|
||||
storage
|
||||
.get_secret(&config.id, &format!("{PLUGIN_CONNECTION_SECRET_PREFIX}api_token"))
|
||||
.await
|
||||
.unwrap()
|
||||
.as_deref(),
|
||||
Some("plugin-secret")
|
||||
);
|
||||
assert_eq!(storage.load_connections().await.unwrap()[0].connection_secrets, config.connection_secrets);
|
||||
|
||||
let mut cleared = config;
|
||||
cleared.connection_secrets.clear();
|
||||
storage.save_connections(std::slice::from_ref(&cleared)).await.unwrap();
|
||||
assert_eq!(
|
||||
storage.get_secret(&cleared.id, &format!("{PLUGIN_CONNECTION_SECRET_PREFIX}api_token")).await.unwrap(),
|
||||
None
|
||||
);
|
||||
|
||||
let _ = std::fs::remove_file(path);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn switching_save_password_off_removes_stored_password() {
|
||||
let path = temp_db_path("save-password-switch-off");
|
||||
@@ -6107,6 +6196,10 @@ mod tests {
|
||||
"token": token
|
||||
}
|
||||
})),
|
||||
plugin_id: None,
|
||||
plugin_connection_provider: None,
|
||||
plugin_connection_type: None,
|
||||
connection_secrets: Default::default(),
|
||||
jdbc_driver_class: None,
|
||||
jdbc_driver_paths: Vec::new(),
|
||||
one_time: false,
|
||||
@@ -6178,6 +6271,10 @@ mod tests {
|
||||
"password": password
|
||||
}
|
||||
})),
|
||||
plugin_id: None,
|
||||
plugin_connection_provider: None,
|
||||
plugin_connection_type: None,
|
||||
connection_secrets: Default::default(),
|
||||
jdbc_driver_class: None,
|
||||
jdbc_driver_paths: Vec::new(),
|
||||
one_time: false,
|
||||
|
||||
@@ -2287,8 +2287,8 @@ mod tests {
|
||||
permissions.set_mode(0o755);
|
||||
std::fs::set_permissions(&executable, permissions).unwrap();
|
||||
|
||||
let plugin = InstalledPlugin {
|
||||
manifest: PluginManifest {
|
||||
let plugin = InstalledPlugin::new(
|
||||
PluginManifest {
|
||||
id: "jdbc".to_string(),
|
||||
name: "JDBC".to_string(),
|
||||
version: "test".to_string(),
|
||||
@@ -2301,9 +2301,12 @@ mod tests {
|
||||
kind: "external".to_string(),
|
||||
database_type: Some("jdbc".to_string()),
|
||||
}],
|
||||
contributions: Vec::new(),
|
||||
..PluginManifest::default()
|
||||
},
|
||||
path: dir.clone(),
|
||||
};
|
||||
dir.clone(),
|
||||
env!("CARGO_PKG_VERSION"),
|
||||
);
|
||||
let session = Arc::new(
|
||||
PluginDriverSession::start_for_test(plugin, "jdbc".to_string(), PluginRuntimeEnv::default())
|
||||
.await
|
||||
|
||||
@@ -10063,6 +10063,10 @@ mod tests {
|
||||
gbase_server: String::new(),
|
||||
informix_server: String::new(),
|
||||
external_config: None,
|
||||
plugin_id: None,
|
||||
plugin_connection_provider: None,
|
||||
plugin_connection_type: None,
|
||||
connection_secrets: Default::default(),
|
||||
jdbc_driver_class: if driver_class.is_empty() { None } else { Some(driver_class.to_string()) },
|
||||
jdbc_driver_paths: Vec::new(),
|
||||
one_time: false,
|
||||
@@ -15184,6 +15188,10 @@ SELECT 1 FROM dual"#
|
||||
gbase_server: String::new(),
|
||||
informix_server: String::new(),
|
||||
external_config: None,
|
||||
plugin_id: None,
|
||||
plugin_connection_provider: None,
|
||||
plugin_connection_type: None,
|
||||
connection_secrets: Default::default(),
|
||||
jdbc_driver_class: None,
|
||||
jdbc_driver_paths: Vec::new(),
|
||||
one_time: false,
|
||||
|
||||
@@ -70,6 +70,10 @@ fn live_postgres_config(
|
||||
etcd_endpoints: String::new(),
|
||||
gbase_server: String::new(),
|
||||
informix_server: String::new(),
|
||||
plugin_id: None,
|
||||
plugin_connection_provider: None,
|
||||
plugin_connection_type: None,
|
||||
connection_secrets: Default::default(),
|
||||
external_config: None,
|
||||
jdbc_driver_class: None,
|
||||
jdbc_driver_paths: Vec::new(),
|
||||
|
||||
@@ -66,6 +66,10 @@ fn live_postgres_config(
|
||||
etcd_endpoints: String::new(),
|
||||
gbase_server: String::new(),
|
||||
informix_server: String::new(),
|
||||
plugin_id: None,
|
||||
plugin_connection_provider: None,
|
||||
plugin_connection_type: None,
|
||||
connection_secrets: Default::default(),
|
||||
external_config: None,
|
||||
jdbc_driver_class: None,
|
||||
jdbc_driver_paths: Vec::new(),
|
||||
|
||||
@@ -61,6 +61,10 @@ fn live_postgres_config(
|
||||
etcd_endpoints: String::new(),
|
||||
gbase_server: String::new(),
|
||||
informix_server: String::new(),
|
||||
plugin_id: None,
|
||||
plugin_connection_provider: None,
|
||||
plugin_connection_type: None,
|
||||
connection_secrets: Default::default(),
|
||||
external_config: None,
|
||||
jdbc_driver_class: None,
|
||||
jdbc_driver_paths: Vec::new(),
|
||||
|
||||
@@ -67,6 +67,10 @@ fn live_postgres_config(
|
||||
gbase_server: String::new(),
|
||||
informix_server: String::new(),
|
||||
external_config: None,
|
||||
plugin_id: None,
|
||||
plugin_connection_provider: None,
|
||||
plugin_connection_type: None,
|
||||
connection_secrets: Default::default(),
|
||||
jdbc_driver_class: None,
|
||||
jdbc_driver_paths: Vec::new(),
|
||||
one_time: false,
|
||||
|
||||
@@ -61,6 +61,10 @@ fn postgres_test_config(id: &str, database: &str) -> ConnectionConfig {
|
||||
gbase_server: String::new(),
|
||||
informix_server: String::new(),
|
||||
external_config: None,
|
||||
plugin_id: None,
|
||||
plugin_connection_provider: None,
|
||||
plugin_connection_type: None,
|
||||
connection_secrets: Default::default(),
|
||||
jdbc_driver_class: None,
|
||||
jdbc_driver_paths: Vec::new(),
|
||||
one_time: false,
|
||||
|
||||
@@ -68,6 +68,10 @@ fn live_sqlserver_config(id: &str, database: &str) -> dbx_core::models::connecti
|
||||
gbase_server: String::new(),
|
||||
informix_server: String::new(),
|
||||
external_config: None,
|
||||
plugin_id: None,
|
||||
plugin_connection_provider: None,
|
||||
plugin_connection_type: None,
|
||||
connection_secrets: Default::default(),
|
||||
jdbc_driver_class: None,
|
||||
jdbc_driver_paths: Vec::new(),
|
||||
one_time: false,
|
||||
|
||||
@@ -57,6 +57,10 @@ fn live_sqlserver_config(id: &str, database: &str) -> dbx_core::models::connecti
|
||||
gbase_server: String::new(),
|
||||
informix_server: String::new(),
|
||||
external_config: None,
|
||||
plugin_id: None,
|
||||
plugin_connection_provider: None,
|
||||
plugin_connection_type: None,
|
||||
connection_secrets: Default::default(),
|
||||
jdbc_driver_class: None,
|
||||
jdbc_driver_paths: Vec::new(),
|
||||
one_time: false,
|
||||
|
||||
@@ -60,6 +60,10 @@ fn live_sqlserver_config(id: &str, database: &str) -> ConnectionConfig {
|
||||
gbase_server: String::new(),
|
||||
informix_server: String::new(),
|
||||
external_config: None,
|
||||
plugin_id: None,
|
||||
plugin_connection_provider: None,
|
||||
plugin_connection_type: None,
|
||||
connection_secrets: Default::default(),
|
||||
jdbc_driver_class: None,
|
||||
jdbc_driver_paths: Vec::new(),
|
||||
one_time: false,
|
||||
|
||||
@@ -181,6 +181,10 @@ pub fn postgres_test_config(id: &str, port: u16) -> ConnectionConfig {
|
||||
gbase_server: String::new(),
|
||||
informix_server: String::new(),
|
||||
external_config: None,
|
||||
plugin_id: None,
|
||||
plugin_connection_provider: None,
|
||||
plugin_connection_type: None,
|
||||
connection_secrets: Default::default(),
|
||||
jdbc_driver_class: None,
|
||||
jdbc_driver_paths: Vec::new(),
|
||||
one_time: false,
|
||||
|
||||
Reference in new issue
Block a user