Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
ljl committed Nov 2, 2023
2 parents b3870c1 + 2712866 commit 65a5ca9
Show file tree
Hide file tree
Showing 37 changed files with 650 additions and 572 deletions.
9 changes: 7 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,17 @@ run_script = { version = "0.10" }
testcontainers-modules = { version = "0.1"}
strum ={ version = "0.25", features = ["derive"] }
# tardis
tardis = { version = "=0.1.0-rc.2" }
tardis = { version = "=0.1.0-rc.3" }
# tardis = { path = "../tardis/tardis" }
# tardis = { git = "https://github.com/ideal-world/tardis.git", rev = "9424e16" }
#spacegate
spacegate-kernel = { git = "https://github.com/ideal-world/spacegate.git", rev = "ed34d33",features = [
spacegate-kernel = { git = "https://github.com/ideal-world/spacegate.git", rev = "a0430a8",features = [
"ws",
"cache",
"k8s",
] }
#spacegate-kernel = { path = "../spacegate/kernel",features = [
# "ws",
# "cache",
# "k8s",
#] }
2 changes: 1 addition & 1 deletion basic/src/rbum/dto/rbum_safe_dto.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use serde::{Serialize};
use serde::Serialize;
#[cfg(feature = "default")]
use tardis::db::sea_orm;
use tardis::{
Expand Down
3 changes: 1 addition & 2 deletions basic/src/rbum/serv/rbum_kind_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ impl RbumCrudOperation<rbum_kind::ActiveModel, RbumKindAddReq, RbumKindModifyReq
if !R_URL_PART_CODE.is_match(add_req.code.as_str()) {
return Err(funs.err().bad_request(&Self::get_obj_name(), "add", &format!("code {} is invalid", add_req.code), "400-rbum-*-code-illegal"));
}
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
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
{
return Err(funs.err().conflict(&Self::get_obj_name(), "add", &format!("code {} already exists", add_req.code), "409-rbum-*-code-exist"));
}
Expand Down
4 changes: 2 additions & 2 deletions basic/src/test/init_rbum_test_container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use std::env;
use tardis::basic::result::TardisResult;
use tardis::test::test_container::TardisTestContainer;
use tardis::testcontainers::clients::Cli;
use tardis::testcontainers::GenericImage;
use testcontainers_modules::redis::Redis;
use tardis::testcontainers::Container;
use tardis::testcontainers::GenericImage;
use tardis::TardisFuns;
use testcontainers_modules::redis::Redis;

pub struct LifeHold<'a> {
pub reldb: Container<'a, GenericImage>,
Expand Down
6 changes: 5 additions & 1 deletion basic/src/test/test_http_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ pub struct TestHttpClient {
impl TestHttpClient {
pub fn new(base_url: String) -> TestHttpClient {
TestHttpClient {
client: TardisWebClient::init(&WebClientModuleConfig { connect_timeout_sec: 600, ..Default::default() }).unwrap(),
client: TardisWebClient::init(&WebClientModuleConfig {
connect_timeout_sec: 600,
..Default::default()
})
.unwrap(),
context: Default::default(),
base_url,
}
Expand Down
3 changes: 2 additions & 1 deletion gateway/spacegate-lib/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![warn(clippy::unwrap_used)]

use crate::plugin::{anti_replay, anti_xss, audit_log, auth, ip_time};
use crate::plugin::{anti_replay, anti_xss, audit_log, auth, ip_time, rewrite_ns_b_ip};

mod plugin;

Expand All @@ -12,4 +12,5 @@ pub fn register_lib_filter() {
spacegate_kernel::register_filter_def(anti_replay::SgFilterAntiReplayDef);
spacegate_kernel::register_filter_def(anti_xss::SgFilterAntiXSSDef);
spacegate_kernel::register_filter_def(auth::SgFilterAuthDef);
spacegate_kernel::register_filter_def(rewrite_ns_b_ip::SgFilterRewriteNsDef);
}
1 change: 1 addition & 0 deletions gateway/spacegate-lib/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub mod anti_xss;
pub mod audit_log;
pub mod auth;
pub mod ip_time;
pub mod rewrite_ns_b_ip;
mod plugin_constants {
pub const BEFORE_ENCRYPT_BODY: &str = "beforeEncryptBody";
}
20 changes: 4 additions & 16 deletions gateway/spacegate-lib/src/plugin/anti_replay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ use std::time::Duration;
use async_trait::async_trait;

use serde::{Deserialize, Serialize};
use spacegate_kernel::def_filter;
use spacegate_kernel::plugins::filters::SgPluginFilterInitDto;
use spacegate_kernel::plugins::{
context::SgRoutePluginContext,
filters::{BoxSgPluginFilter, SgPluginFilter, SgPluginFilterAccept, SgPluginFilterDef},
filters::{SgPluginFilter, SgPluginFilterAccept},
};
use tardis::cache::cache_client::TardisCacheClient;

Expand All @@ -15,22 +16,9 @@ use tardis::{
basic::{error::TardisError, result::TardisResult},
serde_json::{self},
tokio::{self},
TardisFuns,
};

pub const CODE: &str = "anti_replay";
pub struct SgFilterAntiReplayDef;

impl SgPluginFilterDef for SgFilterAntiReplayDef {
fn get_code(&self) -> &str {
CODE
}

fn inst(&self, spec: serde_json::Value) -> TardisResult<BoxSgPluginFilter> {
let filter = TardisFuns::json.json_to_obj::<SgFilterAntiReplay>(spec)?;
Ok(filter.boxed())
}
}
def_filter!("anti_replay", SgFilterAntiReplayDef, SgFilterAntiReplay);

#[derive(Serialize, Deserialize)]
#[serde(default)]
Expand Down Expand Up @@ -131,6 +119,7 @@ mod tests {

use std::env;

use super::*;
use spacegate_kernel::{
http::Uri,
hyper::{Body, HeaderMap, Method, Version},
Expand All @@ -140,7 +129,6 @@ mod tests {
testcontainers::{self, clients::Cli, Container},
};
use testcontainers_modules::redis::Redis;
use super::*;

#[tokio::test]
async fn test_anti_replay() {
Expand Down
17 changes: 3 additions & 14 deletions gateway/spacegate-lib/src/plugin/anti_xss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@ use std::fmt;
use async_trait::async_trait;

use serde::{Deserialize, Serialize};
use spacegate_kernel::http;
use spacegate_kernel::plugins::filters::SgPluginFilterInitDto;
use spacegate_kernel::plugins::{
context::SgRoutePluginContext,
filters::{BoxSgPluginFilter, SgPluginFilter, SgPluginFilterAccept, SgPluginFilterDef},
filters::{SgPluginFilter, SgPluginFilterAccept},
};
use spacegate_kernel::{def_filter, http};

use tardis::{
async_trait,
basic::result::TardisResult,
serde_json::{self},
TardisFuns,
};

macro_rules! append_value {
Expand All @@ -24,18 +23,8 @@ macro_rules! append_value {
}
};
}
pub const CODE: &str = "anti_xss";
pub struct SgFilterAntiXSSDef;

impl SgPluginFilterDef for SgFilterAntiXSSDef {
fn get_code(&self) -> &str {
CODE
}
fn inst(&self, spec: serde_json::Value) -> TardisResult<BoxSgPluginFilter> {
let filter = TardisFuns::json.json_to_obj::<SgFilterAntiXSS>(spec)?;
Ok(filter.boxed())
}
}
def_filter!("anti_xss", SgFilterAntiXSSDef, SgFilterAntiXSS);

#[derive(Default, Serialize, Deserialize)]
#[serde(default)]
Expand Down
16 changes: 3 additions & 13 deletions gateway/spacegate-lib/src/plugin/audit_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ use bios_sdk_invoke::invoke_initializer;

use jsonpath_rust::JsonPathInst;
use serde::{Deserialize, Serialize};
use spacegate_kernel::def_filter;
use spacegate_kernel::plugins::context::SGRoleInfo;
use spacegate_kernel::plugins::{
context::SgRoutePluginContext,
filters::{BoxSgPluginFilter, SgPluginFilter, SgPluginFilterAccept, SgPluginFilterDef, SgPluginFilterInitDto},
filters::{SgPluginFilter, SgPluginFilterAccept, SgPluginFilterInitDto},
};
use tardis::basic::dto::TardisContext;
use tardis::serde_json::{json, Value};
Expand All @@ -31,18 +32,7 @@ use tardis::{

use super::plugin_constants;

pub const CODE: &str = "audit_log";
pub struct SgFilterAuditLogDef;

impl SgPluginFilterDef for SgFilterAuditLogDef {
fn get_code(&self) -> &str {
CODE
}
fn inst(&self, spec: serde_json::Value) -> TardisResult<BoxSgPluginFilter> {
let filter = TardisFuns::json.json_to_obj::<SgFilterAuditLog>(spec)?;
Ok(filter.boxed())
}
}
def_filter!("audit_log", SgFilterAuditLogDef, SgFilterAuditLog);

#[derive(Serialize, Deserialize)]
#[serde(default)]
Expand Down
Loading

0 comments on commit 65a5ca9

Please sign in to comment.