Skip to content

Commit

Permalink
spi-search: es support adv_query && improve test (#716)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZzIsGod1019 authored Apr 23, 2024
1 parent fd47e66 commit 5ef8305
Show file tree
Hide file tree
Showing 44 changed files with 507 additions and 261 deletions.
6 changes: 3 additions & 3 deletions backend/basic/src/dto.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Basic DTOs
//!
//!
//! 基础的DTOs
use std::collections::HashMap;

Expand All @@ -11,7 +11,7 @@ use crate::enumeration::BasicQueryOpKind;
use tardis::web::poem_openapi;

/// Basic query condition object
///
///
/// 基础的查询条件对象
#[derive(Serialize, Deserialize, Debug, Clone)]
#[cfg_attr(feature = "default", derive(poem_openapi::Object))]
Expand All @@ -27,7 +27,7 @@ pub struct BasicQueryCondInfo {

impl BasicQueryCondInfo {
/// Check if the ``check_vars`` passed in meet the conditions in ``conds``
///
///
/// 检查传入的 ``check_vars`` 是否满足 ``conds`` 中的条件
///
/// The outer level is the `OR` relationship, the inner level is the `AND` relationship
Expand Down
16 changes: 8 additions & 8 deletions backend/basic/src/enumeration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,45 @@ use tardis::derive_more::Display;
use tardis::web::poem_openapi;

/// API classification
///
///
/// API分类
#[derive(Display, Debug)]
#[cfg_attr(feature = "default", derive(poem_openapi::Tags))]
pub enum ApiTag {
/// Common Console, mostly starting with ``cc``, generally do not require authentication.
///
///
/// 公共类型, 多使用 ``cc`` 开头,一般不需要认证
#[oai(rename = "Common Console")]
Common,
/// Tenant Console, mostly starting with ``ct``
///
///
/// 租户类型, 多使用 ``ct`` 开头
#[oai(rename = "Tenant Console")]
Tenant,
/// App Console, mostly starting with ``ca``
///
///
/// 应用类型, 多使用 ``ca`` 开头
#[oai(rename = "App Console")]
App,
/// System Console, mostly starting with ``cs``
///
///
/// 系统类型, 多使用 ``cs`` 开头
#[oai(rename = "System Console")]
System,
/// Passport Console, mostly starting with ``cp``
///
///
/// 通行证类型, 多使用 ``cp`` 开头
#[oai(rename = "Passport Console")]
Passport,
/// Interface Console, mostly starting with ``ci``, used for system-to-system calls, this type of interface generally uses ak/sk authentication
///
///
/// 接口类型, 多使用 ``ci`` 开头, 用于系统间调用, 此类型接口一般使用ak/sk认证
#[oai(rename = "Interface Console")]
Interface,
}

/// Basic query operator
///
///
/// 基础查询操作符
#[derive(Display, Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
#[cfg_attr(feature = "default", derive(poem_openapi::Enum))]
Expand Down
2 changes: 1 addition & 1 deletion backend/basic/src/helper/db_helper.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Database operations helper
//!
//!
//! 数据库操作辅助操作
use tardis::{
chrono::{DateTime, ParseError, Utc},
Expand Down
4 changes: 2 additions & 2 deletions backend/basic/src/helper/request_helper.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Http request helper
//!
//!
//! Http请求辅助操作
use std::{collections::HashMap, net::IpAddr, str::FromStr};

Expand All @@ -26,7 +26,7 @@ pub async fn try_set_real_ip_from_req_to_ctx(request: &Request, ctx: &TardisCont
}

/// Parse the Forwarded header to get the IP
///
///
/// Forwarded format: `Forwarded: by=<identifier>; for=<identifier><,for=<identifier>>; host=<host>; proto=<http|https>`
///
/// ```
Expand Down
8 changes: 4 additions & 4 deletions backend/basic/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Basic library for BIOS
//!
//!
//! BIOS的基础库
//!
//! This library provides the following functions:
Expand Down Expand Up @@ -30,20 +30,20 @@ pub use enumeration::ApiTag;
use tardis::{TardisFuns, TardisFunsInst};

/// Extractor for ``TardisFunInst``
///
///
/// 提取 ``TardisFunsInst``
pub trait TardisFunInstExtractor {
fn tardis_fun_inst(&self) -> TardisFunsInst;
}

/// Extract ``TardisFunInst`` from request path
///
///
/// 从请求路径中自动提取 ``TardisFunInst``
///
/// Get the first path segment from the request path as the service domain.
/// If there is a configuration parameter ``csm.X`` with the same name as the service domain, use this configuration parameter,
/// otherwise use the default configuration parameter.
///
///
/// 从请求路径中找到第一个路径段作为服务域名,如果存在与该服务域名同名的配置参数 ``csm.X``, 则使用该配置参数,否则使用默认配置参数.
#[cfg(feature = "default")]
impl TardisFunInstExtractor for tardis::web::poem::Request {
Expand Down
4 changes: 2 additions & 2 deletions backend/basic/src/process/ci_processor.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! CI (Interface Console) Processor
//!
//!
//! CI (接口控制台) 处理器
//!
//! The CI type interface is mostly used for calls between systems, and the interface is authenticated by Ak/Sk to ensure the security of the interface.
//!
//!
//! CI类型的接口多用于系统之间的调用,通过Ak/Sk进行签名认证,保证接口的安全性。
use serde::{Deserialize, Serialize};
use tardis::{basic::result::TardisResult, chrono::Utc, TardisFuns};
Expand Down
30 changes: 15 additions & 15 deletions backend/basic/src/process/task_processor.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Async task processor
//!
//!
//! 异步任务处理器
use std::{collections::HashMap, future::Future, sync::Arc};

Expand Down Expand Up @@ -36,7 +36,7 @@ pub struct TaskProcessor;

impl TaskProcessor {
/// Initialize the asynchronous task status
///
///
/// 初始化异步任务状态
pub async fn init_status(cache_key: &str, task_id: Option<u64>, cache_client: &TardisCacheClient) -> TardisResult<u64> {
let task_id = task_id.unwrap_or(Local::now().timestamp_nanos_opt().expect("maybe in 23rd century") as u64);
Expand All @@ -51,7 +51,7 @@ impl TaskProcessor {
}

/// Check the status of the asynchronous task (whether it is completed)
///
///
/// 检查异步任务状态(是否完成)
pub async fn check_status(cache_key: &str, task_id: u64, cache_client: &TardisCacheClient) -> TardisResult<bool> {
let result1 = cache_client.getbit(&format!("{cache_key}:1"), (task_id / u32::MAX as u64) as usize).await?;
Expand All @@ -60,7 +60,7 @@ impl TaskProcessor {
}

/// Set the status of the asynchronous task (whether it is completed)
///
///
/// 设置异步任务状态(是否完成)
pub async fn set_status(cache_key: &str, task_id: u64, status: bool, cache_client: &TardisCacheClient) -> TardisResult<()> {
cache_client.setbit(&format!("{cache_key}:1"), (task_id / u32::MAX as u64) as usize, status).await?;
Expand All @@ -69,7 +69,7 @@ impl TaskProcessor {
}

/// Set the status of the asynchronous task (whether it is completed) and send an event
///
///
/// 设置异步任务状态(是否完成)并发送事件
pub async fn set_status_with_event(
cache_key: &str,
Expand All @@ -96,15 +96,15 @@ impl TaskProcessor {
}

/// Set the processing data of the asynchronous task
///
///
/// 设置异步任务处理数据
pub async fn set_process_data(cache_key: &str, task_id: u64, data: Value, cache_client: &TardisCacheClient) -> TardisResult<()> {
cache_client.set_ex(&format!("{cache_key}:{task_id}"), &TardisFuns::json.json_to_string(data)?, TASK_PROCESSOR_DATA_EX_SEC).await?;
Ok(())
}

/// Set the processing data of the asynchronous task and send an event
///
///
/// 设置异步任务处理数据并发送事件
pub async fn set_process_data_with_event(
cache_key: &str,
Expand Down Expand Up @@ -132,7 +132,7 @@ impl TaskProcessor {
}

/// Fetch the processing data of the asynchronous task
///
///
/// 获取异步任务处理数据
pub async fn get_process_data(cache_key: &str, task_id: u64, cache_client: &TardisCacheClient) -> TardisResult<Value> {
if let Some(result) = cache_client.get(&format!("{cache_key}:{task_id}")).await? {
Expand All @@ -143,7 +143,7 @@ impl TaskProcessor {
}

/// Execute asynchronous task
///
///
/// 执行异步任务
pub async fn execute_task<P, T>(cache_key: &str, process_fun: P, cache_client: &Arc<TardisCacheClient>) -> TardisResult<u64>
where
Expand All @@ -154,7 +154,7 @@ impl TaskProcessor {
}

/// Execute asynchronous task and send event
///
///
/// 执行异步任务并发送事件
pub async fn execute_task_with_ctx<P, T>(
cache_key: &str,
Expand Down Expand Up @@ -227,7 +227,7 @@ impl TaskProcessor {
}

/// Execute asynchronous task (without asynchronous function, only used to mark the start of the task)
///
///
/// 执行异步任务(不带异步函数,仅用于标记任务开始执行)
pub async fn execute_task_without_fun(
cache_key: &str,
Expand All @@ -254,14 +254,14 @@ impl TaskProcessor {
}

/// Stop asynchronous task
///
///
/// 停止异步任务
pub async fn stop_task(cache_key: &str, task_id: u64, cache_client: &TardisCacheClient) -> TardisResult<()> {
Self::stop_task_with_event(cache_key, task_id, cache_client, None, "".to_string(), None).await
}

/// Stop asynchronous task and send event
///
///
/// 停止异步任务并发送事件
pub async fn stop_task_with_event(
cache_key: &str,
Expand Down Expand Up @@ -291,11 +291,11 @@ impl TaskProcessor {
}

/// Fetch the asynchronous task IDs in the context
///
///
/// 获取异步任务IDs
///
/// Use ``,`` to separate multiple tasks
///
///
/// 多个任务使用``,``分隔
pub async fn get_task_id_with_ctx(ctx: &TardisContext) -> TardisResult<Option<String>> {
ctx.get_ext(TASK_IN_CTX_FLAG).await
Expand Down
2 changes: 1 addition & 1 deletion backend/basic/src/rbum/domain/rbum_cert_conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use tardis::TardisCreateIndex;
/// This is a general certificate configuration model that describes various types of certificate configurations.
/// It can handle database connections, web system authentication, host ssh, etc.
///
/// 这是一个通用的凭证配置模型,用于描述各种类型的凭证配置。可处理包含数据库连接、web系统认证、主机ssh谁等
/// 这是一个通用的凭证配置模型,用于描述各种类型的凭证配置。可处理包含数据库连接、web系统认证、主机ssh等
///
/// Certificate configuration is bound to a subject that can be a resource domain [`Self::rel_rbum_domain_id`] or a resource item [`Self::rel_rbum_item_id`].
/// It is required that the same binding subject has the same certificate configuration type [`Self::kind`] and certificate configuration supplier [`Self::supplier`] unique.
Expand Down
26 changes: 13 additions & 13 deletions backend/basic/src/rbum/domain/rbum_domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,53 +8,53 @@ use tardis::db::sea_orm::*;
use tardis::TardisCreateIndex;

/// Resource domain model
///
///
/// 资源域模型
///
/// The resource domain is the unit of ownership of the resource, indicating the owner of the resource.
/// Each resource is required to belong to a resource domain.
///
///
/// 资源域是资源的归属单位,表示资源的所有者。每个资源都要求归属于一个资源域。
///
/// E.g. All menu resources are provided by IAM components, and all IaaS resources are provided by CMDB components.
/// IAM components and CMDB components are resource domains.
///
///
/// 例如:所有菜单资源由IAM组件提供,所有IaaS资源由CMDB组件提供。IAM组件和CMDB组件是资源域。
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, TardisCreateIndex)]
#[sea_orm(table_name = "rbum_domain")]
pub struct Model {
/// Resource domain id
///
///
/// 资源域id
#[sea_orm(primary_key, auto_increment = false)]
pub id: String,
/// Resource domain code
///
///
/// 资源域编码
///
///
/// Global unique
///
///
/// 全局唯一
///
///
/// Which is required to conform to the host specification in the uri, matching the regular: ^[a-z0-9-.]+$.
///
///
/// 需要符合uri中的host规范,匹配正则:^[a-z0-9-.]+$。
#[index(unique)]
pub code: String,
/// Resource domain name
///
///
/// 资源域名称
pub name: String,
/// Resource domain note
///
///
/// 资源域备注
pub note: String,
/// Resource domain icon
///
///
/// 资源域图标
pub icon: String,
/// Resource domain sort
///
///
/// 资源域排序
pub sort: i64,

Expand Down
6 changes: 3 additions & 3 deletions backend/basic/src/rbum/dto/rbum_domain_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ pub struct RbumDomainModifyReq {
/// 资源域排序
pub sort: Option<i64>,
/// Resource domain scope level
///
///
/// 资源域作用域级别
///
///
/// Default is ``private``
///
///
/// 默认为``私有``
pub scope_level: Option<RbumScopeLevelKind>,
}
Expand Down
5 changes: 1 addition & 4 deletions backend/basic/src/rbum/helper/rbum_scope_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,8 @@ where
/// Warning: This operation is unsafe, and it should only be used in scenarios where there is no security risk.
#[cfg(feature = "default")]
pub fn check_without_owner_and_unsafe_fill_ctx(request: &tardis::web::poem::Request, funs: &TardisFunsInst, ctx: &mut TardisContext) -> TardisResult<()> {
use tardis::log::warn;

if !ctx.owner.is_empty() {
warn!("[Auth.Check] ctx.owner is not empty, ctx: {:?}", ctx.owner);
// return Err(TardisError::forbidden("[Basic] Request context owner is not empty", "403-rbum-req-ctx-owner-is-not-empty"));
return Err(TardisError::forbidden("[Basic] Request context owner is not empty", "403-rbum-req-ctx-owner-is-not-empty"));
}
unsafe_fill_ctx(request, funs, ctx)
}
Expand Down
1 change: 0 additions & 1 deletion backend/basic/src/rbum/serv/rbum_crud_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ where
Ok(E::Entity::find().filter(Expr::col(ID_FIELD.clone()).eq(id)))
}


async fn after_delete_rbum(_: &str, _: &Option<DetailResp>, _: &TardisFunsInst, _: &TardisContext) -> TardisResult<()> {
Ok(())
}
Expand Down
Loading

0 comments on commit 5ef8305

Please sign in to comment.