Skip to content

Commit

Permalink
code fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
ZzIsGod1019 committed Jan 17, 2025
1 parent 8e33267 commit f3c8603
Show file tree
Hide file tree
Showing 31 changed files with 658 additions and 523 deletions.
1 change: 0 additions & 1 deletion backend/gateways/spacegate-plugins/src/extension.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

pub mod audit_log_param;
pub mod before_encrypt_body;
pub mod cert_info;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub struct LogParamContent {

impl LogParamContent {
pub fn send_audit_log<P: PluginBiosExt>(self, spi_app_id: &str, log_url: &str, tag: &str) {
send_audit_log(spi_app_id, log_url, tag, self,P::get_funs_inst_by_plugin_code());
send_audit_log(spi_app_id, log_url, tag, self, P::get_funs_inst_by_plugin_code());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,17 @@ impl NotificationContext {
}

// set the dedup key
if let Err(e) = conn.set_ex::<'_, _, _,Option<String>>(&key, "1", cool_down).await {
if let Err(e) = conn.set_ex::<'_, _, _, Option<String>>(&key, "1", cool_down).await {
tracing::error!(error = ?e, "set dedup cache failed");
return;
}

let funs = NotifyPlugin::get_funs_inst_by_plugin_code();
tracing::debug!(?req, "submit notify");
let response = match req {
ReachRequest::ByScene(req) => {
bios_sdk_invoke::clients::reach_client::ReachClient::send_message(&req.into(), &funs, &ctx).await

}
ReachRequest::ByScene(req) => bios_sdk_invoke::clients::reach_client::ReachClient::send_message(&req.into(), &funs, &ctx).await,
ReachRequest::ByTemplate { contact, template_id, replace } => {
bios_sdk_invoke::clients::reach_client::ReachClient::general_send(&contact, &template_id, &replace, &funs, &ctx).await
bios_sdk_invoke::clients::reach_client::ReachClient::general_send(&contact, &template_id, &replace, &funs, &ctx).await
}
};
if let Err(e) = response {
Expand Down
2 changes: 1 addition & 1 deletion backend/gateways/spacegate-plugins/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![warn(clippy::unwrap_used)]

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

mod consts;
mod extension;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ impl Plugin for ContentFilterPlugin {
for f in &self.forbidden_pq_filter {
if f.matches(pq.as_str().as_bytes()) {
let mut response = SgResponse::with_code_empty(StatusCode::BAD_REQUEST);
response.extensions_mut().insert(ContentFilterForbiddenReport { forbidden_reason: format!("forbidden rule matched: {f}") });
response.extensions_mut().insert(ContentFilterForbiddenReport {
forbidden_reason: format!("forbidden rule matched: {f}"),
});
return Ok(response);
}
}
Expand All @@ -125,7 +127,7 @@ impl Plugin for ContentFilterPlugin {
if filter.matches(bytes) {
let mut response = SgResponse::with_code_empty(StatusCode::BAD_REQUEST);
response.extensions_mut().insert(ContentFilterForbiddenReport {
forbidden_reason: format!("forbidden rule matched: {filter}") ,
forbidden_reason: format!("forbidden rule matched: {filter}"),
});
return Ok(response);
}
Expand Down
10 changes: 5 additions & 5 deletions backend/gateways/spacegate-plugins/src/plugin/notify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ use spacegate_shell::{
BoxError, SgRequest, SgRequestExt, SgResponse,
};
use tardis::{
log as tracing,
regex::{self, Regex},
serde_json,
log as tracing,
};

use crate::extension::{
Expand All @@ -32,13 +32,13 @@ pub struct NotifyPluginConfig {
/// - rate_limit: rate limit notification
/// - count: number of requests
/// - time_window: time window
///
///
/// - tamper: tamper notification
///
///
/// - unauthorized_operation: unauthorized operation notification
///
///
/// - cert_lock: cert lock notification
///
///
/// - content_filter_forbidden: content filter forbidden notification
/// - reason: forbidden reason
templates: HashMap<String, NotifyPluginConfigTemplatesItem>,
Expand Down
7 changes: 3 additions & 4 deletions backend/gateways/spacegate-plugins/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn parse_duration(duration: &str) -> Result<Duration, BoxError> {
duration = rest;

// Parse unit
let (unit, rest) = match duration.find(|c: char| !c.is_alphabetic() && c != ' ') {
let (unit, rest) = match duration.find(|c: char| !c.is_alphabetic() && c != ' ') {
Some(index) => duration.split_at(index),
None => (duration, ""),
};
Expand All @@ -29,7 +29,7 @@ pub fn parse_duration(duration: &str) -> Result<Duration, BoxError> {
"ms" | "millisecond" => Duration::from_millis(number),
"s" | "second" => Duration::from_secs(number),
"m" | "min" => Duration::from_secs(number * 60),
"h" | "hour" => Duration::from_secs(number * 60 * 60),
"h" | "hour" => Duration::from_secs(number * 60 * 60),
"d" | "day" => Duration::from_secs(number * 60 * 60 * 24),
_ => return Err(format!("Invalid unit: {}", unit).into()),
};
Expand Down Expand Up @@ -66,6 +66,5 @@ mod test {
"1ns1us1ms1s1m1h1d" => Duration::from_nanos(1) + Duration::from_micros(1) + Duration::from_millis(1) + Duration::from_secs(1) + Duration::from_secs(60) + Duration::from_secs(60 * 60) + Duration::from_secs(60 * 60 * 24),
"1d 1h 1min 1s 1ms 1us 1ns" => Duration::from_secs(60 * 60 * 24) + Duration::from_secs(60 * 60) + Duration::from_secs(60) + Duration::from_secs(1) + Duration::from_millis(1) + Duration::from_micros(1) + Duration::from_nanos(1),
}

}
}
}
10 changes: 10 additions & 0 deletions backend/middlewares/flow/src/api/ci/flow_ci_inst_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,14 @@ impl FlowCiInstApi {
ctx.0.execute_task().await?;
TardisResp::ok(result)
}

/// sync instance status to search
///
/// 同步状态信息
#[oai(path = "/status/sync", method = "get")]
async fn sync_status(&self, _ctx: TardisContextExtractor, _request: &Request) -> TardisApiResult<Void> {
let funs = flow_constants::get_tardis_inst();
FlowInstServ::sync_status(&funs).await?;
TardisResp::ok(Void {})
}
}
5 changes: 2 additions & 3 deletions backend/middlewares/flow/src/api/ci/flow_ci_model_api.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use std::collections::HashMap;

use crate::dto::flow_model_dto::{
FlowModelAggResp, FlowModelAssociativeOperationKind, FlowModelCopyOrReferenceCiReq, FlowModelExistRelByTemplateIdsReq, FlowModelFilterReq, FlowModelFindRelStateResp,
FlowModelKind, FlowModelSyncModifiedFieldReq,
FlowModelAggResp, FlowModelCopyOrReferenceCiReq, FlowModelExistRelByTemplateIdsReq, FlowModelFilterReq, FlowModelFindRelStateResp, FlowModelKind, FlowModelSyncModifiedFieldReq,
};
use crate::flow_constants;
use crate::serv::flow_inst_serv::FlowInstServ;
Expand Down Expand Up @@ -274,7 +273,7 @@ impl FlowCiModelApi {
&ctx.0,
)
.await
.unwrap()
.unwrap_or_default()
.into_iter()
.map(|model| model.tag.clone())
.collect_vec();
Expand Down
4 changes: 2 additions & 2 deletions backend/middlewares/flow/src/dto/flow_inst_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ pub struct FlowInstFindNextTransitionsReq {
}

/// 获取实例下一个动作列表请求
#[derive(Serialize, Deserialize, Debug, poem_openapi::Object, Clone)]
#[derive(Serialize, Deserialize, Debug, Default, poem_openapi::Object, Clone)]
pub struct FlowInstFindNextTransitionResp {
/// Associated [flow_transition](super::flow_transition_dto::FlowTransitionDetailResp) id
///
Expand Down Expand Up @@ -376,7 +376,7 @@ pub struct FlowInstFindNextTransitionResp {
}

/// 获取实例状态及流转信息的请求
#[derive(Serialize, Deserialize, Debug, poem_openapi::Object)]
#[derive(Serialize, Deserialize, Default, Debug, poem_openapi::Object, Clone)]
pub struct FlowInstFindStateAndTransitionsReq {
/// 实例ID
pub flow_inst_id: String,
Expand Down
2 changes: 1 addition & 1 deletion backend/middlewares/flow/src/dto/flow_model_version_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ pub struct FlowModelVersionDetailResp {
impl FlowModelVersionDetailResp {
pub fn states(&self) -> Vec<FlowStateAggResp> {
match &self.states {
Some(states) => TardisFuns::json.json_to_obj(states.clone()).unwrap(),
Some(states) => TardisFuns::json.json_to_obj(states.clone()).unwrap_or_default(),
None => vec![],
}
}
Expand Down
20 changes: 12 additions & 8 deletions backend/middlewares/flow/src/dto/flow_transition_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,31 +197,31 @@ pub struct FlowTransitionDetailResp {

impl FlowTransitionDetailResp {
pub fn guard_by_other_conds(&self) -> Option<Vec<Vec<BasicQueryCondInfo>>> {
if self.guard_by_other_conds.is_array() && !&self.guard_by_other_conds.as_array().unwrap().is_empty() {
if self.guard_by_other_conds.is_array() && !&self.guard_by_other_conds.as_array().filter(|conds| conds.is_empty()).is_some() {
Some(TardisFuns::json.json_to_obj(self.guard_by_other_conds.clone()).unwrap_or_default())
} else {
None
}
}

pub fn vars_collect(&self) -> Option<Vec<FlowVarInfo>> {
if self.vars_collect.is_array() && !&self.vars_collect.as_array().unwrap().is_empty() {
if self.vars_collect.is_array() && !&self.vars_collect.as_array().filter(|conds| conds.is_empty()).is_some() {
Some(TardisFuns::json.json_to_obj(self.vars_collect.clone()).unwrap_or_default())
} else {
None
}
}

pub fn action_by_post_changes(&self) -> Vec<FlowTransitionPostActionInfo> {
if self.action_by_post_changes.is_array() && !&self.action_by_post_changes.as_array().unwrap().is_empty() {
if self.action_by_post_changes.is_array() && !&self.action_by_post_changes.as_array().filter(|conds| conds.is_empty()).is_some() {
TardisFuns::json.json_to_obj(self.action_by_post_changes.clone()).unwrap_or_default()
} else {
vec![]
}
}

pub fn action_by_front_changes(&self) -> Vec<FlowTransitionFrontActionInfo> {
if self.action_by_front_changes.is_array() && !&self.action_by_front_changes.as_array().unwrap().is_empty() {
if self.action_by_front_changes.is_array() && !&self.action_by_front_changes.as_array().filter(|conds| conds.is_empty()).is_some() {
TardisFuns::json.json_to_obj(self.action_by_front_changes.clone()).unwrap_or_default()
} else {
vec![]
Expand Down Expand Up @@ -329,7 +329,7 @@ impl From<FlowTransitionPostActionInfo> for FlowTransitionActionChangeAgg {
kind: value.kind,
var_change_info: None,
state_change_info: Some(FlowTransitionActionByStateChangeInfo {
obj_tag: value.obj_tag.unwrap(),
obj_tag: value.obj_tag.unwrap_or_default(),
obj_tag_rel_kind: value.obj_tag_rel_kind,
describe: value.describe,
obj_current_state_id: value.obj_current_state_id,
Expand Down Expand Up @@ -454,7 +454,7 @@ pub struct StateChangeCondition {
}

/// 筛选条件的配置项
#[derive(Serialize, Deserialize, Clone, PartialEq, Debug, poem_openapi::Object, sea_orm::FromJsonQueryResult)]
#[derive(Serialize, Deserialize, Clone, PartialEq, Debug, Default, poem_openapi::Object, sea_orm::FromJsonQueryResult)]
pub struct StateChangeConditionItem {
/// 对象Tag。为空时,代表触发的业务对象为当前操作的业务对象。有值时,代表触发的业务对象为当前操作的业务对象的关联对象。
/// 例:值为req,则代表触发的业务对象为当前操作对象所关联的需求对象。
Expand All @@ -470,8 +470,9 @@ pub struct StateChangeConditionItem {
}

/// 实际规则的条件类型
#[derive(Serialize, Deserialize, Clone, PartialEq, Debug, poem_openapi::Enum)]
#[derive(Serialize, Deserialize, Clone, PartialEq, Debug, Default, poem_openapi::Enum)]
pub enum StateChangeConditionOp {
#[default]
And,
Or,
}
Expand Down Expand Up @@ -669,7 +670,10 @@ impl FlowTransitionFrontActionInfoRelevanceRelation {
}
left_value >= interval[0] && left_value <= interval[1]
}
FlowTransitionFrontActionInfoRelevanceRelation::IsNullOrEmpty => {let s = left_value.as_str().to_string(); s.is_empty() || s == "[]" || s == "{}"},
FlowTransitionFrontActionInfoRelevanceRelation::IsNullOrEmpty => {
let s = left_value.as_str().to_string();
s.is_empty() || s == "[]" || s == "{}"
}
FlowTransitionFrontActionInfoRelevanceRelation::IsNotNull => !left_value.as_str().to_string().is_empty(),
}
}
Expand Down
2 changes: 1 addition & 1 deletion backend/middlewares/flow/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ pub mod flow_config;
pub mod flow_constants;
pub mod flow_initializer;
mod helper;
mod serv;
mod serv;
33 changes: 16 additions & 17 deletions backend/middlewares/flow/src/serv/clients/kv_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,22 @@ impl FlowKvClient {
pub async fn get_role_id(original_id: &str, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<String> {
let mut role_id = "".to_string();
if let Some(role_id_prefix) = original_id.split(':').collect_vec().first() {
role_id = SpiKvClient::match_items_by_key_prefix(format!("__k_n__:iam_role:{}", role_id_prefix), None, 1, 999, None, funs, ctx).await?
.map(|resp| {
resp.records.into_iter().filter(|record| ctx.own_paths.contains(&record.own_paths)).collect_vec()
})
.map(|records| {
if let Some(item) = records.iter().find(|r| r.own_paths == ctx.own_paths) {
return item.key.split("__k_n__:iam_role:").collect_vec().pop().map(|s| s.to_string()).unwrap_or_default();
}
if let Some(item) = records.iter().find(|r| r.own_paths == rbum_scope_helper::get_path_item(1, &ctx.own_paths).unwrap_or_default()) {
return item.key.split("__k_n__:iam_role:").collect_vec().pop().map(|s| s.to_string()).unwrap_or_default();
}
if let Some(item) = records.iter().find(|r| r.own_paths.is_empty()) {
return item.key.split("__k_n__:iam_role:").collect_vec().pop().map(|s| s.to_string()).unwrap_or_default();
}
"".to_string()
})
.unwrap_or_default();
role_id = SpiKvClient::match_items_by_key_prefix(format!("__k_n__:iam_role:{}", role_id_prefix), None, 1, 999, None, funs, ctx)
.await?
.map(|resp| resp.records.into_iter().filter(|record| ctx.own_paths.contains(&record.own_paths)).collect_vec())
.map(|records| {
if let Some(item) = records.iter().find(|r| r.own_paths == ctx.own_paths) {
return item.key.split("__k_n__:iam_role:").collect_vec().pop().map(|s| s.to_string()).unwrap_or_default();
}
if let Some(item) = records.iter().find(|r| r.own_paths == rbum_scope_helper::get_path_item(1, &ctx.own_paths).unwrap_or_default()) {
return item.key.split("__k_n__:iam_role:").collect_vec().pop().map(|s| s.to_string()).unwrap_or_default();
}
if let Some(item) = records.iter().find(|r| r.own_paths.is_empty()) {
return item.key.split("__k_n__:iam_role:").collect_vec().pop().map(|s| s.to_string()).unwrap_or_default();
}
"".to_string()
})
.unwrap_or_default();
}

Ok(role_id)
Expand Down
Loading

0 comments on commit f3c8603

Please sign in to comment.