mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-05-07 10:14:35 +00:00
feat(gui): GUI add support to connect to config server (#1596)
This commit is contained in:
@@ -28,6 +28,7 @@ use crate::{
|
||||
proxy::TcpProxyRpcService, stats::StatsRpcService, vpn_portal::VpnPortalRpcService,
|
||||
},
|
||||
tunnel::{tcp::TcpTunnelListener, TunnelListener},
|
||||
web_client::DefaultHooks,
|
||||
};
|
||||
|
||||
pub struct ApiRpcServer<T: TunnelListener + 'static> {
|
||||
@@ -142,7 +143,10 @@ fn register_api_rpc_service(
|
||||
);
|
||||
|
||||
registry.register(
|
||||
WebClientServiceServer::new(InstanceManageRpcService::new(instance_manager.clone())),
|
||||
WebClientServiceServer::new(InstanceManageRpcService::new(
|
||||
instance_manager.clone(),
|
||||
Arc::new(DefaultHooks),
|
||||
)),
|
||||
"",
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,16 +7,18 @@ use crate::{
|
||||
api::{config::GetConfigRequest, manage::*},
|
||||
rpc_types::{self, controller::BaseController},
|
||||
},
|
||||
web_client::WebClientHooks,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct InstanceManageRpcService {
|
||||
manager: Arc<NetworkInstanceManager>,
|
||||
hooks: Arc<dyn WebClientHooks>,
|
||||
}
|
||||
|
||||
impl InstanceManageRpcService {
|
||||
pub fn new(manager: Arc<NetworkInstanceManager>) -> Self {
|
||||
Self { manager }
|
||||
pub fn new(manager: Arc<NetworkInstanceManager>, hooks: Arc<dyn WebClientHooks>) -> Self {
|
||||
Self { manager, hooks }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +53,14 @@ impl WebClientService for InstanceManageRpcService {
|
||||
};
|
||||
|
||||
let mut control = if let Some(control) = self.manager.get_instance_config_control(&id) {
|
||||
if !req.overwrite {
|
||||
let error_msg = self
|
||||
.manager
|
||||
.get_network_info(&id)
|
||||
.await
|
||||
.and_then(|i| i.error_msg)
|
||||
.unwrap_or_default();
|
||||
|
||||
if !req.overwrite && error_msg.is_empty() {
|
||||
return Ok(resp);
|
||||
}
|
||||
if control.is_read_only() {
|
||||
@@ -96,8 +105,17 @@ impl WebClientService for InstanceManageRpcService {
|
||||
}
|
||||
}
|
||||
|
||||
if let Err(e) = self.hooks.pre_run_network_instance(&cfg).await {
|
||||
return Err(anyhow::anyhow!("pre-run hook failed: {}", e).into());
|
||||
}
|
||||
|
||||
self.manager.run_network_instance(cfg, true, control)?;
|
||||
println!("instance {} started", id);
|
||||
|
||||
if let Err(e) = self.hooks.post_run_network_instance(&id).await {
|
||||
tracing::warn!("post-run hook failed: {}", e);
|
||||
}
|
||||
|
||||
Ok(resp)
|
||||
}
|
||||
|
||||
@@ -173,6 +191,9 @@ impl WebClientService for InstanceManageRpcService {
|
||||
req: DeleteNetworkInstanceRequest,
|
||||
) -> Result<DeleteNetworkInstanceResponse, rpc_types::error::Error> {
|
||||
let inst_ids: HashSet<uuid::Uuid> = req.inst_ids.into_iter().map(Into::into).collect();
|
||||
|
||||
let hook_ids: Vec<uuid::Uuid> = inst_ids.iter().cloned().collect();
|
||||
|
||||
let inst_ids = self
|
||||
.manager
|
||||
.iter()
|
||||
@@ -190,6 +211,11 @@ impl WebClientService for InstanceManageRpcService {
|
||||
.collect::<Vec<_>>();
|
||||
let remain_inst_ids = self.manager.delete_network_instance(inst_ids)?;
|
||||
println!("instance {:?} retained", remain_inst_ids);
|
||||
|
||||
if let Err(e) = self.hooks.post_remove_network_instances(&hook_ids).await {
|
||||
tracing::warn!("post-remove hook failed: {}", e);
|
||||
}
|
||||
|
||||
for config_file in config_files {
|
||||
if let Err(e) = std::fs::remove_file(&config_file) {
|
||||
tracing::warn!(
|
||||
|
||||
@@ -110,11 +110,12 @@ where
|
||||
// collect networks that are disabled
|
||||
let disabled_inst_ids = self
|
||||
.get_storage()
|
||||
.list_network_configs(identify, ListNetworkProps::DisabledOnly)
|
||||
.list_network_configs(identify, ListNetworkProps::All)
|
||||
.await
|
||||
.map_err(RemoteClientError::PersistentError)?
|
||||
.iter()
|
||||
.map(|x| Into::<crate::proto::common::Uuid>::into(x.get_network_inst_id().to_string()))
|
||||
.filter(|id| !ret.inst_ids.contains(id))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
Ok(ListNetworkInstanceIdsJsonResp {
|
||||
|
||||
Reference in New Issue
Block a user