Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
RWDai committed Dec 5, 2023
1 parent 49548da commit 9ff8c0d
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ util/gh-pages/lints.json
.DS_Store

# dev script
devsh/*
devsh/*
.uuid
5 changes: 2 additions & 3 deletions admin/src/api/backend_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ use crate::model::query_dto::{BackendRefQueryDto, ToInstance};
use crate::model::vo::backend_vo::SgBackendRefVo;
use crate::service::backend_ref_service::BackendRefVoService;
use tardis::web::poem::session::Session;
use tardis::web::poem::web::Query;
use tardis::web::poem_openapi;
use tardis::web::poem_openapi::param::Path;
use tardis::web::poem_openapi::param::{Path, Query};
use tardis::web::poem_openapi::payload::Json;
use tardis::web::web_resp::{TardisApiResult, TardisResp, Void};

Expand Down Expand Up @@ -45,7 +44,7 @@ impl BackendApi {
}

/// delete Backend
#[oai(path = "/:backend_id", method = "put")]
#[oai(path = "/:backend_id", method = "delete")]
async fn delete(&self, backend_id: Path<String>, session: &Session) -> TardisApiResult<Void> {
let client_name = &super::get_instance_name(session).await?;
BackendRefVoService::delete(client_name, &backend_id.0).await?;
Expand Down
6 changes: 3 additions & 3 deletions admin/src/api/gateway_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::service::gateway_service::GatewayVoService;
use tardis::basic::error::TardisError;
use tardis::web::poem::session::Session;
use tardis::web::poem_openapi;
use tardis::web::poem_openapi::param::Query;
use tardis::web::poem_openapi::param::{Path, Query};
use tardis::web::poem_openapi::payload::Json;
use tardis::web::web_resp::{TardisApiResult, TardisResp, Void};

Expand Down Expand Up @@ -54,8 +54,8 @@ impl GatewayApi {
}

/// Delete Gateway
#[oai(path = "/", method = "delete")]
async fn delete(&self, name: Query<String>, session: &Session) -> TardisApiResult<Void> {
#[oai(path = "/:plugin_id", method = "delete")]
async fn delete(&self, name: Path<String>, session: &Session) -> TardisApiResult<Void> {
let client_name = &super::get_instance_name(session).await?;
GatewayVoService::delete(client_name, &name.0).await?;
TardisResp::ok(Void {})
Expand Down
2 changes: 1 addition & 1 deletion admin/src/api/plugin_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl PluginApi {
}

/// Delete Plugin
#[oai(path = "/:plugin_id", method = "put")]
#[oai(path = "/:plugin_id", method = "delete")]
async fn delete(&self, plugin_id: Path<String>, session: &Session) -> TardisApiResult<Void> {
let client_name = &super::get_instance_name(session).await?;
PluginVoService::delete(client_name, &plugin_id.0).await?;
Expand Down
2 changes: 1 addition & 1 deletion admin/src/api/tls_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl TlsApi {
}

/// Delete Tls
#[oai(path = "/:backend_id", method = "put")]
#[oai(path = "/:backend_id", method = "delete")]
async fn delete(&self, tls_config_id: Path<String>, session: &Session) -> TardisApiResult<Void> {
let client_name = &super::get_instance_name(session).await?;
TlsVoService::delete(client_name, &tls_config_id.0).await?;
Expand Down
2 changes: 2 additions & 0 deletions admin/src/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ mod test {
fn test_fuzzy_regex() {
assert!(fuzzy_regex("*").unwrap().is_match("8435"));
assert!(fuzzy_regex("*").unwrap().is_match("8435*erf"));
assert!(!fuzzy_regex("").unwrap().is_match("dsfasd"));

assert!(!fuzzy_regex("a").unwrap().is_match("sdfa435gt"));
assert!(fuzzy_regex("a*").unwrap().is_match("a435gt"));
assert!(!fuzzy_regex("a*").unwrap().is_match("sdfa435gt"));

Expand Down
3 changes: 2 additions & 1 deletion admin/src/initializer.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::api::{auth_api, gateway_api, plugin_api, route_api, spacegate_manage_api, tls_api, BasicAuth, CookieMW};
use crate::api::{auth_api, backend_api, gateway_api, plugin_api, route_api, spacegate_manage_api, tls_api, BasicAuth, CookieMW};
use crate::client::init_client;

use crate::constants::DOMAIN_CODE;
Expand All @@ -16,6 +16,7 @@ pub(crate) async fn init(web_server: &TardisWebServer) -> TardisResult<()> {

async fn init_api(web_server: &TardisWebServer) -> TardisResult<()> {
let module = WebServerModule::from((
backend_api::BackendApi,
gateway_api::GatewayApi,
plugin_api::PluginApi,
route_api::HttprouteApi,
Expand Down
1 change: 1 addition & 0 deletions admin/src/service/backend_ref_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ impl BackendRefVoService {
Self::add_vo(client_name, add).await
}
pub(crate) async fn update(client_name: &str, update: SgBackendRefVo) -> TardisResult<SgBackendRefVo> {
//todo update route
Self::update_vo(client_name, update).await
}

Expand Down
18 changes: 14 additions & 4 deletions admin/src/service/base_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,26 @@ where
where
T: 'async_trait,
{
Self::add_or_update_vo(client_name, config, true).await
Self::add_or_update_vo(client_name, config, true, false).await
}

async fn update_vo(client_name: &str, config: T) -> TardisResult<T>
where
T: 'async_trait,
{
Self::add_or_update_vo(client_name, config, false).await
Self::add_or_update_vo(client_name, config, false, true).await
}

async fn add_or_update_vo(client_name: &str, config: T, add_only: bool) -> TardisResult<T>
/// # add_or_update_vo
/// **warning**: `add_only` and `update_only` cannot be true at the same time
async fn add_or_update_vo(client_name: &str, config: T, add_only: bool, update_only: bool) -> TardisResult<T>
where
T: 'async_trait,
{
if add_only && update_only {
panic!("add_only and update_only cannot be true at the same time");
}

let id = config.get_unique_name();
let mut datas = Self::get_str_type_map(client_name).await?;
if datas.get(&id).is_some() {
Expand All @@ -89,7 +95,11 @@ where
log::debug!("[SG.admin] add_or_update {}:{} exists , will update", T::get_vo_type(), id);
}
} else {
log::debug!("[SG.admin] add_or_update {}:{} not exists , will add", T::get_vo_type(), id);
if update_only {
return Err(TardisError::bad_request(&format!("[SG.admin] {}:{} not exists", T::get_vo_type(), id), ""));
} else {
log::debug!("[SG.admin] add_or_update {}:{} not exists , will add", T::get_vo_type(), id);
}
}
let config_str = serde_json::to_string(&config).map_err(|e| TardisError::bad_request(&format!("Serialization to json failed:{e}"), ""))?;
if SpacegateManageService::client_is_kube(client_name).await? {
Expand Down
1 change: 1 addition & 0 deletions admin/src/service/plugin_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ impl PluginVoService {
}

pub(crate) async fn update(client_name: &str, update: SgFilterVo) -> TardisResult<SgFilterVo> {
//todo update sgfilter or httproute\gateway
Self::update_vo(client_name, update).await
}

Expand Down

0 comments on commit 9ff8c0d

Please sign in to comment.