diff --git a/backend/gateways/spacegate-plugins/src/plugin/audit_log.rs b/backend/gateways/spacegate-plugins/src/plugin/audit_log.rs index 8f3e167b..54478b50 100644 --- a/backend/gateways/spacegate-plugins/src/plugin/audit_log.rs +++ b/backend/gateways/spacegate-plugins/src/plugin/audit_log.rs @@ -3,7 +3,7 @@ use std::collections::HashMap; use std::str::FromStr; use std::time::Instant; -use bios_sdk_invoke::clients::spi_log_client::{self, LogItemAddReq}; +use bios_sdk_invoke::clients::spi_log_client::{self, LogItemAddV2Req}; use bios_sdk_invoke::invoke_config::InvokeConfig; use bios_sdk_invoke::invoke_enumeration::InvokeModuleKind; use bios_sdk_invoke::invoke_initializer; @@ -208,8 +208,8 @@ impl AuditLogPlugin { let tag = self.tag.clone(); if !self.log_url.is_empty() && !self.spi_app_id.is_empty() { tokio::task::spawn(async move { - match spi_log_client::SpiLogClient::add( - LogItemAddReq { + match spi_log_client::SpiLogClient::addv2( + LogItemAddV2Req { tag, content: TardisFuns::json.obj_to_json(&content).unwrap_or_default(), kind: None, diff --git a/backend/middlewares/flow/src/serv/clients/flow_log_client.rs b/backend/middlewares/flow/src/serv/clients/flow_log_client.rs index 89cec43a..2072d966 100644 --- a/backend/middlewares/flow/src/serv/clients/flow_log_client.rs +++ b/backend/middlewares/flow/src/serv/clients/flow_log_client.rs @@ -1,6 +1,6 @@ use bios_sdk_invoke::clients::{ iam_client::IamClient, - spi_log_client::{LogItemAddReq, SpiLogClient}, + spi_log_client::{LogItemAddV2Req, SpiLogClient}, }; use serde::Serialize; @@ -96,7 +96,7 @@ impl FlowLogClient { .await? .owner_name; - let req = LogItemAddReq { + let req = LogItemAddV2Req { tag: tag.to_string(), content: TardisFuns::json.obj_to_json(&content).expect("req_msg not a valid json value"), kind, @@ -112,7 +112,7 @@ impl FlowLogClient { owner_name, push: push, }; - SpiLogClient::add(req, funs, ctx).await?; + SpiLogClient::addv2(req, funs, ctx).await?; Ok(()) } } diff --git a/backend/middlewares/schedule/src/serv/schedule_job_serv_v2/event/spi_log.rs b/backend/middlewares/schedule/src/serv/schedule_job_serv_v2/event/spi_log.rs index e89883a6..06b00493 100644 --- a/backend/middlewares/schedule/src/serv/schedule_job_serv_v2/event/spi_log.rs +++ b/backend/middlewares/schedule/src/serv/schedule_job_serv_v2/event/spi_log.rs @@ -1,6 +1,6 @@ use std::{sync::Arc, task::ready, time::Duration}; -use bios_sdk_invoke::clients::spi_log_client::{LogItemAddReq, LogItemFindReq, SpiLogClient}; +use bios_sdk_invoke::clients::spi_log_client::{LogItemAddReq, LogItemAddV2Req, LogItemFindReq, SpiLogClient}; use tardis::{ basic::dto::TardisContext, chrono::Utc, @@ -109,8 +109,8 @@ impl EventComponent for SpiLog { let ctx = self.ctx.clone(); let code = code.to_string(); let _handle = tokio::spawn(async move { - let result = SpiLogClient::add( - LogItemAddReq { + let result = SpiLogClient::addv2( + LogItemAddV2Req { tag: TASK_TAG.to_string(), content: tardis::serde_json::Value::Null, ext: Some(ext), diff --git a/backend/spi/spi-log/src/api/ci/log_ci_item_api.rs b/backend/spi/spi-log/src/api/ci/log_ci_item_api.rs index d31b9092..cb5cafe3 100644 --- a/backend/spi/spi-log/src/api/ci/log_ci_item_api.rs +++ b/backend/spi/spi-log/src/api/ci/log_ci_item_api.rs @@ -4,13 +4,16 @@ use tardis::web::poem_openapi::param::Path; use tardis::web::poem_openapi::payload::Json; use tardis::web::web_resp::{TardisApiResult, TardisPage, TardisResp, Void}; -use crate::dto::log_item_dto::{LogConfigReq, LogItemAddReq, LogItemFindReq, LogItemFindResp}; +use crate::dto::log_item_dto::{LogConfigReq, LogItemAddReq, LogItemAddV2Req, LogItemFindReq, LogItemFindResp}; use crate::serv::log_item_serv; use tardis::serde_json::Value; #[derive(Clone)] pub struct LogCiItemApi; +#[derive(Clone)] +pub struct LogCiItemApiV2; + /// Interface Console Log API #[poem_openapi::OpenApi(prefix_path = "/ci/item", tag = "bios_basic::ApiTag::Interface")] impl LogCiItemApi { @@ -29,6 +32,26 @@ impl LogCiItemApi { let resp = log_item_serv::find(&mut find_req.0, &funs, &ctx.0).await?; TardisResp::ok(resp) } +} + +/// Interface Console Log API V2 +#[poem_openapi::OpenApi(prefix_path = "/ci/v2/item", tag = "bios_basic::ApiTag::Interface")] +impl LogCiItemApiV2 { + /// Add Item + #[oai(path = "/", method = "post")] + async fn add(&self, mut add_req: Json, ctx: TardisContextExtractor) -> TardisApiResult { + let funs = crate::get_tardis_inst(); + let id = log_item_serv::addv2(&mut add_req.0, &funs, &ctx.0).await?; + TardisResp::ok(id) + } + + /// Find Items + #[oai(path = "/find", method = "put")] + async fn find(&self, mut find_req: Json, ctx: TardisContextExtractor) -> TardisApiResult> { + let funs = crate::get_tardis_inst(); + let resp = log_item_serv::findv2(&mut find_req.0, &funs, &ctx.0).await?; + TardisResp::ok(resp) + } /// Modify Item ext by key #[oai(path = "/modify/:tag/:key/ext", method = "post")] diff --git a/backend/spi/spi-log/src/dto/log_item_dto.rs b/backend/spi/spi-log/src/dto/log_item_dto.rs index 824f377b..f7e2ffe4 100644 --- a/backend/spi/spi-log/src/dto/log_item_dto.rs +++ b/backend/spi/spi-log/src/dto/log_item_dto.rs @@ -7,8 +7,49 @@ use tardis::{ web::poem_openapi, }; -#[derive(poem_openapi::Object, Serialize, Deserialize, Clone, Debug)] +#[derive(poem_openapi::Object, Serialize, Deserialize, Debug)] pub struct LogItemAddReq { + #[oai(validator(pattern = r"^[a-z0-9_]+$"))] + pub tag: String, + // #[oai(validator(min_length = "2"))] + pub content: String, + #[oai(validator(min_length = "2"))] + pub kind: Option, + pub ext: Option, + #[oai(validator(min_length = "2"))] + pub key: Option, + #[oai(validator(min_length = "2"))] + pub op: Option, + #[oai(validator(min_length = "2"))] + pub rel_key: Option, + #[oai(validator(min_length = "2"))] + pub id: Option, + pub ts: Option>, + #[oai(validator(min_length = "2"))] + pub owner: Option, + pub own_paths: Option, +} + +impl From for LogItemAddReq { + fn from(value: bios_sdk_invoke::clients::spi_log_client::LogItemAddReq) -> Self { + Self { + tag: value.tag, + content: value.content, + kind: value.kind.map(Into::into), + ext: value.ext, + key: value.key.map(Into::into), + op: value.op, + rel_key: value.rel_key.map(Into::into), + id: value.id, + ts: value.ts, + owner: value.owner, + own_paths: value.own_paths, + } + } +} + +#[derive(poem_openapi::Object, Serialize, Deserialize, Clone, Debug)] +pub struct LogItemAddV2Req { #[oai(validator(pattern = r"^[a-z0-9_]+$"))] pub tag: String, pub content: Value, @@ -32,8 +73,8 @@ pub struct LogItemAddReq { pub push: bool, pub msg: Option, } -impl From for LogItemAddReq { - fn from(value: bios_sdk_invoke::clients::spi_log_client::LogItemAddReq) -> Self { +impl From for LogItemAddV2Req { + fn from(value: bios_sdk_invoke::clients::spi_log_client::LogItemAddV2Req) -> Self { Self { tag: value.tag, content: value.content, @@ -129,8 +170,8 @@ pub struct StatsItemAddReq { pub own_paths: Option, } -impl From for StatsItemAddReq { - fn from(value: LogItemAddReq) -> Self { +impl From for StatsItemAddReq { + fn from(value: LogItemAddV2Req) -> Self { StatsItemAddReq { idempotent_id: value.idempotent_id, tag: value.tag, diff --git a/backend/spi/spi-log/src/event.rs b/backend/spi/spi-log/src/event.rs index ca93d1e8..81c69914 100644 --- a/backend/spi/spi-log/src/event.rs +++ b/backend/spi/spi-log/src/event.rs @@ -4,7 +4,7 @@ use bios_sdk_invoke::clients::{ asteroid_mq::prelude::{EventAttribute, Subject}, get_topic, mq_error, ContextHandler, SPI_RPC_TOPIC, }, - spi_log_client::LogItemAddReq, + spi_log_client::LogItemAddV2Req, }; use tardis::{ basic::{dto::TardisContext, result::TardisResult}, @@ -12,9 +12,9 @@ use tardis::{ }; #[instrument] -async fn handle_add_event(req: LogItemAddReq, ctx: TardisContext) -> TardisResult<()> { +async fn handle_add_event(req: LogItemAddV2Req, ctx: TardisContext) -> TardisResult<()> { let funs = get_tardis_inst(); - serv::log_item_serv::add(&mut req.into(), &funs, &ctx).await?; + serv::log_item_serv::addv2(&mut req.into(), &funs, &ctx).await?; Ok(()) } diff --git a/backend/spi/spi-log/src/serv.rs b/backend/spi/spi-log/src/serv.rs index cd156a3d..1991c4ef 100644 --- a/backend/spi/spi-log/src/serv.rs +++ b/backend/spi/spi-log/src/serv.rs @@ -1,4 +1,3 @@ pub mod log_item_serv; -#[deprecated] pub mod pg; pub mod pgv2; diff --git a/backend/spi/spi-log/src/serv/log_item_serv.rs b/backend/spi/spi-log/src/serv/log_item_serv.rs index f3783690..0a40d6ae 100644 --- a/backend/spi/spi-log/src/serv/log_item_serv.rs +++ b/backend/spi/spi-log/src/serv/log_item_serv.rs @@ -4,7 +4,7 @@ use bios_basic::spi::spi_constants; use bios_basic::spi::spi_funs::SpiBsInstExtractor; use bios_basic::spi_dispatch_service; -use crate::dto::log_item_dto::{LogConfigReq, LogItemAddReq, LogItemFindReq, LogItemFindResp}; +use crate::dto::log_item_dto::{LogConfigReq, LogItemAddReq, LogItemAddV2Req, LogItemFindReq, LogItemFindResp}; use crate::log_initializer; use tardis::web::web_resp::TardisPage; @@ -24,6 +24,8 @@ spi_dispatch_service! { @method: { add(add_req: &mut LogItemAddReq) -> TardisResult; find(find_req: &mut LogItemFindReq) -> TardisResult>; + addv2(add_req: &mut LogItemAddV2Req) -> TardisResult; + findv2(find_req: &mut LogItemFindReq) -> TardisResult>; modify_ext(tag: &str,key: &str, ext: &mut Value) -> TardisResult<()>; add_config(config: &mut LogConfigReq) -> TardisResult<()>; delete_config(config: &mut LogConfigReq) -> TardisResult<()>; diff --git a/backend/spi/spi-log/src/serv/pg/log_pg_item_serv.rs b/backend/spi/spi-log/src/serv/pg/log_pg_item_serv.rs index 4196b1cb..bc9a5e80 100644 --- a/backend/spi/spi-log/src/serv/pg/log_pg_item_serv.rs +++ b/backend/spi/spi-log/src/serv/pg/log_pg_item_serv.rs @@ -8,18 +8,18 @@ use tardis::{ use bios_basic::{dto::BasicQueryCondInfo, enumeration::BasicQueryOpKind, helper::db_helper, spi::spi_funs::SpiBsInst}; -use crate::dto::log_item_dto::{AdvBasicQueryCondInfo, LogConfigReq, LogItemAddReq, LogItemFindReq, LogItemFindResp}; +use crate::dto::log_item_dto::{AdvBasicQueryCondInfo, LogConfigReq, LogItemAddReq, LogItemAddV2Req, LogItemFindReq, LogItemFindResp}; use super::log_pg_initializer; pub async fn add(add_req: &mut LogItemAddReq, _funs: &TardisFunsInst, ctx: &TardisContext, inst: &SpiBsInst) -> TardisResult { - let id = add_req.idempotent_id.clone().unwrap_or(TardisFuns::field.nanoid()); + let id = add_req.id.clone().unwrap_or(TardisFuns::field.nanoid()); let mut params = vec![ Value::from(id.clone()), Value::from(add_req.kind.as_ref().unwrap_or(&"".into()).to_string()), Value::from(add_req.key.as_ref().unwrap_or(&"".into()).to_string()), Value::from(add_req.op.as_ref().unwrap_or(&"".to_string()).as_str()), - Value::from(TardisFuns::json.json_to_string(add_req.content.clone())?.as_str()), + Value::from(add_req.content.clone()), Value::from(add_req.owner.as_ref().unwrap_or(&"".to_string()).as_str()), Value::from(add_req.own_paths.as_ref().unwrap_or(&"".to_string()).as_str()), Value::from(if let Some(ext) = &add_req.ext { @@ -509,14 +509,22 @@ ORDER BY ts DESC }) } -pub async fn modify_ext(_tag: &str, _key: &str, _ext: &mut JsonValue, _funs: &TardisFunsInst, _ctx: &TardisContext, _inst: &SpiBsInst) -> TardisResult<()> { - Ok(()) +pub async fn addv2(add_req: &mut LogItemAddV2Req, funs: &TardisFunsInst, ctx: &TardisContext, inst: &SpiBsInst) -> TardisResult { + Err(funs.err().bad_request("item", "add", "Add v2 is not supported", "400-spi-log-add-v2-not-supported")) } -pub async fn add_config(_req: &LogConfigReq, _funs: &TardisFunsInst, _ctx: &TardisContext, _inst: &SpiBsInst) -> TardisResult<()> { - Ok(()) +pub async fn findv2(find_req: &mut LogItemFindReq, funs: &TardisFunsInst, ctx: &TardisContext, inst: &SpiBsInst) -> TardisResult> { + Err(funs.err().bad_request("item", "find", "Find v2 is not supported", "400-spi-log-find-v2-not-supported")) } -pub async fn delete_config(_config: &mut LogConfigReq, _funs: &TardisFunsInst, _ctx: &TardisContext, _inst: &SpiBsInst) -> TardisResult<()> { - Ok(()) +pub async fn modify_ext(_tag: &str, _key: &str, _ext: &mut JsonValue, funs: &TardisFunsInst, _ctx: &TardisContext, _inst: &SpiBsInst) -> TardisResult<()> { + Err(funs.err().bad_request("item", "modify_ext", "Modify ext is not supported", "400-spi-log-modify-ext-not-supported")) +} + +pub async fn add_config(_req: &LogConfigReq, funs: &TardisFunsInst, _ctx: &TardisContext, _inst: &SpiBsInst) -> TardisResult<()> { + Err(funs.err().bad_request("item", "add_config", "Add config is not supported", "400-spi-log-add-config-not-supported")) +} + +pub async fn delete_config(_config: &mut LogConfigReq, funs: &TardisFunsInst, _ctx: &TardisContext, _inst: &SpiBsInst) -> TardisResult<()> { + Err(funs.err().bad_request("item", "delete_config", "Delete config is not supported", "400-spi-log-delete-config-not-supported")) } diff --git a/backend/spi/spi-log/src/serv/pgv2/log_pg_item_serv.rs b/backend/spi/spi-log/src/serv/pgv2/log_pg_item_serv.rs index be8904c1..fbc94f1f 100644 --- a/backend/spi/spi-log/src/serv/pgv2/log_pg_item_serv.rs +++ b/backend/spi/spi-log/src/serv/pgv2/log_pg_item_serv.rs @@ -22,13 +22,20 @@ use bios_basic::{ }; use crate::{ - dto::log_item_dto::{AdvBasicQueryCondInfo, LogConfigReq, LogItemAddReq, LogItemFindReq, LogItemFindResp, StatsItemAddReq}, + dto::log_item_dto::{AdvBasicQueryCondInfo, LogConfigReq, LogItemAddReq, LogItemAddV2Req, LogItemFindReq, LogItemFindResp, StatsItemAddReq}, log_constants::{CONFIG_TABLE_NAME, LOG_REF_FLAG, TABLE_LOG_FLAG_V2}, }; use super::log_pg_initializer; pub async fn add(add_req: &mut LogItemAddReq, funs: &TardisFunsInst, ctx: &TardisContext, inst: &SpiBsInst) -> TardisResult { + crate::serv::pg::log_pg_item_serv::add(add_req, funs, ctx, inst).await +} +pub async fn find(find_req: &mut LogItemFindReq, funs: &TardisFunsInst, ctx: &TardisContext, inst: &SpiBsInst) -> TardisResult> { + crate::serv::pg::log_pg_item_serv::find(find_req, funs, ctx, inst).await +} + +pub async fn addv2(add_req: &mut LogItemAddV2Req, funs: &TardisFunsInst, ctx: &TardisContext, inst: &SpiBsInst) -> TardisResult { let id = add_req.idempotent_id.clone().unwrap_or(TardisFuns::field.nanoid()); let bs_inst = inst.inst::(); @@ -144,7 +151,7 @@ fn parse_ref_ts_key(ref_key: &str) -> TardisResult<(DateTime, String)> { )) } -pub async fn find(find_req: &mut LogItemFindReq, funs: &TardisFunsInst, ctx: &TardisContext, inst: &SpiBsInst) -> TardisResult> { +pub async fn findv2(find_req: &mut LogItemFindReq, funs: &TardisFunsInst, ctx: &TardisContext, inst: &SpiBsInst) -> TardisResult> { let mut where_fragments: Vec = Vec::new(); let mut sql_vals: Vec = vec![]; @@ -699,7 +706,7 @@ async fn get_ref_fields_by_table_name(conn: &TardisRelDBlConnection, schema_name Ok(ref_fields) } -async fn push_to_eda(req: &LogItemAddReq, ref_fields: &Vec, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<()> { +async fn push_to_eda(req: &LogItemAddV2Req, ref_fields: &Vec, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<()> { if let Some(topic) = get_topic(&SPI_RPC_TOPIC) { let mut req_clone = req.clone(); for ref_field in ref_fields { diff --git a/backend/spi/spi-stats/src/event.rs b/backend/spi/spi-stats/src/event.rs index 325b75a5..f9a13372 100644 --- a/backend/spi/spi-stats/src/event.rs +++ b/backend/spi/spi-stats/src/event.rs @@ -1,7 +1,7 @@ use crate::{get_tardis_inst, serv}; use bios_sdk_invoke::clients::{ event_client::{get_topic, mq_error, ContextHandler, SPI_RPC_TOPIC}, - spi_log_client::LogItemAddReq, + spi_log_client::LogItemAddV2Req, }; use tardis::{ basic::{dto::TardisContext, result::TardisResult}, @@ -9,7 +9,7 @@ use tardis::{ }; #[instrument] -async fn handle_add_event(req: LogItemAddReq, ctx: TardisContext) -> TardisResult<()> { +async fn handle_add_event(req: LogItemAddV2Req, ctx: TardisContext) -> TardisResult<()> { let funs = get_tardis_inst(); //TODO Ok(()) diff --git a/backend/supports/iam/src/basic/serv/clients/iam_log_client.rs b/backend/supports/iam/src/basic/serv/clients/iam_log_client.rs index 2e18562b..beb029e6 100644 --- a/backend/supports/iam/src/basic/serv/clients/iam_log_client.rs +++ b/backend/supports/iam/src/basic/serv/clients/iam_log_client.rs @@ -5,7 +5,7 @@ use bios_basic::{ serv::{rbum_crud_serv::RbumCrudOperation, rbum_item_serv::RbumItemCrudOperation, rbum_set_serv::RbumSetCateServ}, }, }; -use bios_sdk_invoke::clients::spi_log_client::{LogItemAddReq, SpiLogClient}; +use bios_sdk_invoke::clients::spi_log_client::{LogItemAddV2Req, SpiLogClient}; use serde::Serialize; use tardis::{ @@ -135,7 +135,7 @@ impl IamLogClient { let own_paths = if ctx.own_paths.len() < 2 { None } else { Some(ctx.own_paths.clone()) }; let owner = if ctx.owner.len() < 2 { None } else { Some(ctx.owner.clone()) }; - let add_req = LogItemAddReq { + let add_req = LogItemAddV2Req { tag, content: TardisFuns::json.obj_to_json(&content).expect("req_msg not a valid json value"), kind, @@ -151,7 +151,7 @@ impl IamLogClient { owner_name: None, push: false, }; - SpiLogClient::add(add_req, funs, ctx).await?; + SpiLogClient::addv2(add_req, funs, ctx).await?; Ok(()) } diff --git a/frontend/sdks/invoke/src/clients/spi_log_client.rs b/frontend/sdks/invoke/src/clients/spi_log_client.rs index 83143316..0704176a 100644 --- a/frontend/sdks/invoke/src/clients/spi_log_client.rs +++ b/frontend/sdks/invoke/src/clients/spi_log_client.rs @@ -25,7 +25,7 @@ pub mod event { pub const LOG_AVATAR: &str = "spi-log"; - impl EventAttribute for super::LogItemAddReq { + impl EventAttribute for super::LogItemAddV2Req { const SUBJECT: Subject = Subject::const_new("log/add"); } } @@ -70,6 +70,21 @@ pub struct LogDynamicContentReq { #[derive(Serialize, Deserialize, Debug, Default)] pub struct LogItemAddReq { + pub tag: String, + pub content: String, + pub kind: Option, + pub ext: Option, + pub key: Option, + pub op: Option, + pub rel_key: Option, + pub id: Option, + pub ts: Option>, + pub owner: Option, + pub own_paths: Option, +} + +#[derive(Serialize, Deserialize, Debug, Default)] +pub struct LogItemAddV2Req { pub tag: String, pub content: Value, pub kind: Option, @@ -87,6 +102,7 @@ pub struct LogItemAddReq { } impl SpiLogClient { + #[deprecated] pub async fn add_dynamic_log( content: &LogDynamicContentReq, ext: Option, @@ -97,10 +113,38 @@ impl SpiLogClient { ts: Option, funs: &TardisFunsInst, ctx: &TardisContext, + ) -> TardisResult<()> { + let req = LogItemAddReq { + tag: DYNAMIC_LOG.to_string(), + content: TardisFuns::json.obj_to_string(content)?, + kind, + ext, + key, + op, + rel_key, + id: None, + ts: ts.map(|ts| DateTime::parse_from_rfc3339(&ts).unwrap_or_default().with_timezone(&Utc)), + owner: Some(ctx.owner.clone()), + own_paths: Some(ctx.own_paths.clone()), + }; + Self::add(req, funs, ctx).await?; + Ok(()) + } + + pub async fn add_dynamic_log_v2( + content: &LogDynamicContentReq, + ext: Option, + kind: Option, + key: Option, + op: Option, + rel_key: Option, + ts: Option, + funs: &TardisFunsInst, + ctx: &TardisContext, ) -> TardisResult<()> { let cfg = funs.conf::(); let owner_name = IamClient::new("", funs, ctx, cfg.module_urls.get("iam").expect("missing iam base url")).get_account(&ctx.owner, &ctx.own_paths).await?.owner_name; - let req = LogItemAddReq { + let req = LogItemAddV2Req { tag: DYNAMIC_LOG.to_string(), content: TardisFuns::json.obj_to_json(content)?, kind, @@ -116,11 +160,19 @@ impl SpiLogClient { owner_name, push: false, }; - Self::add(req, funs, ctx).await?; + Self::addv2(req, funs, ctx).await?; Ok(()) } + #[deprecated] pub async fn add(req: LogItemAddReq, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<()> { + let log_url: String = BaseSpiClient::module_url(InvokeModuleKind::Log, funs).await?; + let headers = BaseSpiClient::headers(None, funs, ctx).await?; + funs.web_client().post_obj_to_str(&format!("{log_url}/ci/item"), &req, headers.clone()).await?; + Ok(()) + } + + pub async fn addv2(req: LogItemAddV2Req, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<()> { #[cfg(feature = "event")] if let Some(topic) = get_topic(&SPI_RPC_TOPIC) { topic.send_event(req.inject_context(funs, ctx).json()).map_err(mq_error).await?; @@ -128,14 +180,23 @@ impl SpiLogClient { } let log_url: String = BaseSpiClient::module_url(InvokeModuleKind::Log, funs).await?; let headers = BaseSpiClient::headers(None, funs, ctx).await?; - funs.web_client().post_obj_to_str(&format!("{log_url}/ci/item"), &req, headers.clone()).await?; + funs.web_client().post_obj_to_str(&format!("{log_url}/ci/v2/item"), &req, headers.clone()).await?; Ok(()) } + #[deprecated] pub async fn find(find_req: LogItemFindReq, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult>> { + Self::do_find(find_req, "/ci/item/find", funs, ctx).await + } + + pub async fn findv2(find_req: LogItemFindReq, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult>> { + Self::do_find(find_req, "/ci/v2/item/find", funs, ctx).await + } + + async fn do_find(find_req: LogItemFindReq, path: &str, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult>> { let log_url: String = BaseSpiClient::module_url(InvokeModuleKind::Log, funs).await?; let headers = BaseSpiClient::headers(None, funs, ctx).await?; - let resp = funs.web_client().put::>>(&format!("{log_url}/ci/item/find"), &find_req, headers.clone()).await?; + let resp = funs.web_client().put::>>(&format!("{log_url}{path}"), &find_req, headers.clone()).await?; BaseSpiClient::package_resp(resp) } }