use std::collections::HashMap;
use std::path::PathBuf;
use serde::Deserialize;
use serde_json::{Value, json};
use crate::error::RpcError;
use crate::server::SharedConfium;
#[derive(Deserialize)]
#[allow(dead_code)]
struct PluginLoadParams {
path: String,
name: String,
#[serde(default)]
options: HashMap<String, String>,
}
pub async fn plugin_load(
cfm: SharedConfium,
params: Value,
) -> std::result::Result<Value, RpcError> {
let p: PluginLoadParams =
serde_json::from_value(params).map_err(|e| RpcError::InvalidParams {
detail: e.to_string(),
})?;
let mut cfm = cfm.borrow_mut();
cfm.load_plugin(&PathBuf::from(&p.path), &p.options)
.map_err(|e| RpcError::Engine {
message: e.to_string(),
})?;
Ok(json!({ "success": true }))
}
pub async fn plugin_unload(
_cfm: SharedConfium,
_params: Value,
) -> std::result::Result<Value, RpcError> {
Err(RpcError::Engine {
message: "plugin_unload is not yet implemented in confium-core".to_string(),
})
}
pub async fn plugin_list(
_cfm: SharedConfium,
_params: Value,
) -> std::result::Result<Value, RpcError> {
Ok(json!({ "plugins": [] }))
}
#[cfg(test)]
mod tests {
use super::*;
use crate::test_util::test_confium;
#[tokio::test]
async fn plugin_list_returns_array() {
let result = plugin_list(test_confium(), json!({})).await.unwrap();
assert!(result.get("plugins").unwrap().is_array());
}
}