Skip to content

Commit 2712866

Browse files
authored
Gateway add rewrite ns plugin in (#520)
* add * update * update * update * update * cargo fmt * update
1 parent 53ebbea commit 2712866

37 files changed

+650
-572
lines changed

Cargo.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,17 @@ run_script = { version = "0.10" }
5050
testcontainers-modules = { version = "0.1"}
5151
strum ={ version = "0.25", features = ["derive"] }
5252
# tardis
53-
tardis = { version = "=0.1.0-rc.2" }
53+
tardis = { version = "=0.1.0-rc.3" }
5454
# tardis = { path = "../tardis/tardis" }
5555
# tardis = { git = "https://github.com/ideal-world/tardis.git", rev = "9424e16" }
5656
#spacegate
57-
spacegate-kernel = { git = "https://github.com/ideal-world/spacegate.git", rev = "ed34d33",features = [
57+
spacegate-kernel = { git = "https://github.com/ideal-world/spacegate.git", rev = "a0430a8",features = [
5858
"ws",
5959
"cache",
6060
"k8s",
6161
] }
62+
#spacegate-kernel = { path = "../spacegate/kernel",features = [
63+
# "ws",
64+
# "cache",
65+
# "k8s",
66+
#] }

basic/src/rbum/dto/rbum_safe_dto.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use serde::{Serialize};
1+
use serde::Serialize;
22
#[cfg(feature = "default")]
33
use tardis::db::sea_orm;
44
use tardis::{

basic/src/rbum/serv/rbum_kind_serv.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ impl RbumCrudOperation<rbum_kind::ActiveModel, RbumKindAddReq, RbumKindModifyReq
5656
if !R_URL_PART_CODE.is_match(add_req.code.as_str()) {
5757
return Err(funs.err().bad_request(&Self::get_obj_name(), "add", &format!("code {} is invalid", add_req.code), "400-rbum-*-code-illegal"));
5858
}
59-
if funs.db().count(Query::select().column(rbum_kind::Column::Id).from(rbum_kind::Entity).and_where(Expr::col(rbum_kind::Column::Code).eq(add_req.code.as_str()))).await?
60-
> 0
59+
if funs.db().count(Query::select().column(rbum_kind::Column::Id).from(rbum_kind::Entity).and_where(Expr::col(rbum_kind::Column::Code).eq(add_req.code.as_str()))).await? > 0
6160
{
6261
return Err(funs.err().conflict(&Self::get_obj_name(), "add", &format!("code {} already exists", add_req.code), "409-rbum-*-code-exist"));
6362
}

basic/src/test/init_rbum_test_container.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ use std::env;
33
use tardis::basic::result::TardisResult;
44
use tardis::test::test_container::TardisTestContainer;
55
use tardis::testcontainers::clients::Cli;
6-
use tardis::testcontainers::GenericImage;
7-
use testcontainers_modules::redis::Redis;
86
use tardis::testcontainers::Container;
7+
use tardis::testcontainers::GenericImage;
98
use tardis::TardisFuns;
9+
use testcontainers_modules::redis::Redis;
1010

1111
pub struct LifeHold<'a> {
1212
pub reldb: Container<'a, GenericImage>,

basic/src/test/test_http_client.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ pub struct TestHttpClient {
2020
impl TestHttpClient {
2121
pub fn new(base_url: String) -> TestHttpClient {
2222
TestHttpClient {
23-
client: TardisWebClient::init(&WebClientModuleConfig { connect_timeout_sec: 600, ..Default::default() }).unwrap(),
23+
client: TardisWebClient::init(&WebClientModuleConfig {
24+
connect_timeout_sec: 600,
25+
..Default::default()
26+
})
27+
.unwrap(),
2428
context: Default::default(),
2529
base_url,
2630
}

gateway/spacegate-lib/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![warn(clippy::unwrap_used)]
22

3-
use crate::plugin::{anti_replay, anti_xss, audit_log, auth, ip_time};
3+
use crate::plugin::{anti_replay, anti_xss, audit_log, auth, ip_time, rewrite_ns_b_ip};
44

55
mod plugin;
66

@@ -12,4 +12,5 @@ pub fn register_lib_filter() {
1212
spacegate_kernel::register_filter_def(anti_replay::SgFilterAntiReplayDef);
1313
spacegate_kernel::register_filter_def(anti_xss::SgFilterAntiXSSDef);
1414
spacegate_kernel::register_filter_def(auth::SgFilterAuthDef);
15+
spacegate_kernel::register_filter_def(rewrite_ns_b_ip::SgFilterRewriteNsDef);
1516
}

gateway/spacegate-lib/src/plugin.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pub mod anti_xss;
33
pub mod audit_log;
44
pub mod auth;
55
pub mod ip_time;
6+
pub mod rewrite_ns_b_ip;
67
mod plugin_constants {
78
pub const BEFORE_ENCRYPT_BODY: &str = "beforeEncryptBody";
89
}

gateway/spacegate-lib/src/plugin/anti_replay.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ use std::time::Duration;
33
use async_trait::async_trait;
44

55
use serde::{Deserialize, Serialize};
6+
use spacegate_kernel::def_filter;
67
use spacegate_kernel::plugins::filters::SgPluginFilterInitDto;
78
use spacegate_kernel::plugins::{
89
context::SgRoutePluginContext,
9-
filters::{BoxSgPluginFilter, SgPluginFilter, SgPluginFilterAccept, SgPluginFilterDef},
10+
filters::{SgPluginFilter, SgPluginFilterAccept},
1011
};
1112
use tardis::cache::cache_client::TardisCacheClient;
1213

@@ -15,22 +16,9 @@ use tardis::{
1516
basic::{error::TardisError, result::TardisResult},
1617
serde_json::{self},
1718
tokio::{self},
18-
TardisFuns,
1919
};
2020

21-
pub const CODE: &str = "anti_replay";
22-
pub struct SgFilterAntiReplayDef;
23-
24-
impl SgPluginFilterDef for SgFilterAntiReplayDef {
25-
fn get_code(&self) -> &str {
26-
CODE
27-
}
28-
29-
fn inst(&self, spec: serde_json::Value) -> TardisResult<BoxSgPluginFilter> {
30-
let filter = TardisFuns::json.json_to_obj::<SgFilterAntiReplay>(spec)?;
31-
Ok(filter.boxed())
32-
}
33-
}
21+
def_filter!("anti_replay", SgFilterAntiReplayDef, SgFilterAntiReplay);
3422

3523
#[derive(Serialize, Deserialize)]
3624
#[serde(default)]
@@ -131,6 +119,7 @@ mod tests {
131119

132120
use std::env;
133121

122+
use super::*;
134123
use spacegate_kernel::{
135124
http::Uri,
136125
hyper::{Body, HeaderMap, Method, Version},
@@ -140,7 +129,6 @@ mod tests {
140129
testcontainers::{self, clients::Cli, Container},
141130
};
142131
use testcontainers_modules::redis::Redis;
143-
use super::*;
144132

145133
#[tokio::test]
146134
async fn test_anti_replay() {

gateway/spacegate-lib/src/plugin/anti_xss.rs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,17 @@ use std::fmt;
33
use async_trait::async_trait;
44

55
use serde::{Deserialize, Serialize};
6-
use spacegate_kernel::http;
76
use spacegate_kernel::plugins::filters::SgPluginFilterInitDto;
87
use spacegate_kernel::plugins::{
98
context::SgRoutePluginContext,
10-
filters::{BoxSgPluginFilter, SgPluginFilter, SgPluginFilterAccept, SgPluginFilterDef},
9+
filters::{SgPluginFilter, SgPluginFilterAccept},
1110
};
11+
use spacegate_kernel::{def_filter, http};
1212

1313
use tardis::{
1414
async_trait,
1515
basic::result::TardisResult,
1616
serde_json::{self},
17-
TardisFuns,
1817
};
1918

2019
macro_rules! append_value {
@@ -24,18 +23,8 @@ macro_rules! append_value {
2423
}
2524
};
2625
}
27-
pub const CODE: &str = "anti_xss";
28-
pub struct SgFilterAntiXSSDef;
2926

30-
impl SgPluginFilterDef for SgFilterAntiXSSDef {
31-
fn get_code(&self) -> &str {
32-
CODE
33-
}
34-
fn inst(&self, spec: serde_json::Value) -> TardisResult<BoxSgPluginFilter> {
35-
let filter = TardisFuns::json.json_to_obj::<SgFilterAntiXSS>(spec)?;
36-
Ok(filter.boxed())
37-
}
38-
}
27+
def_filter!("anti_xss", SgFilterAntiXSSDef, SgFilterAntiXSS);
3928

4029
#[derive(Default, Serialize, Deserialize)]
4130
#[serde(default)]

gateway/spacegate-lib/src/plugin/audit_log.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ use bios_sdk_invoke::invoke_initializer;
1111

1212
use jsonpath_rust::JsonPathInst;
1313
use serde::{Deserialize, Serialize};
14+
use spacegate_kernel::def_filter;
1415
use spacegate_kernel::plugins::context::SGRoleInfo;
1516
use spacegate_kernel::plugins::{
1617
context::SgRoutePluginContext,
17-
filters::{BoxSgPluginFilter, SgPluginFilter, SgPluginFilterAccept, SgPluginFilterDef, SgPluginFilterInitDto},
18+
filters::{SgPluginFilter, SgPluginFilterAccept, SgPluginFilterInitDto},
1819
};
1920
use tardis::basic::dto::TardisContext;
2021
use tardis::serde_json::{json, Value};
@@ -31,18 +32,7 @@ use tardis::{
3132

3233
use super::plugin_constants;
3334

34-
pub const CODE: &str = "audit_log";
35-
pub struct SgFilterAuditLogDef;
36-
37-
impl SgPluginFilterDef for SgFilterAuditLogDef {
38-
fn get_code(&self) -> &str {
39-
CODE
40-
}
41-
fn inst(&self, spec: serde_json::Value) -> TardisResult<BoxSgPluginFilter> {
42-
let filter = TardisFuns::json.json_to_obj::<SgFilterAuditLog>(spec)?;
43-
Ok(filter.boxed())
44-
}
45-
}
35+
def_filter!("audit_log", SgFilterAuditLogDef, SgFilterAuditLog);
4636

4737
#[derive(Serialize, Deserialize)]
4838
#[serde(default)]

0 commit comments

Comments
 (0)