diff --git a/backend/supports/iam/src/basic/serv/clients.rs b/backend/supports/iam/src/basic/serv/clients.rs index abd30078a..189f6b80c 100644 --- a/backend/supports/iam/src/basic/serv/clients.rs +++ b/backend/supports/iam/src/basic/serv/clients.rs @@ -1,3 +1,4 @@ +pub mod iam_kv_client; pub mod iam_log_client; pub mod iam_search_client; pub mod mail_client; diff --git a/backend/supports/iam/src/basic/serv/clients/iam_kv_client.rs b/backend/supports/iam/src/basic/serv/clients/iam_kv_client.rs new file mode 100644 index 000000000..f9309d448 --- /dev/null +++ b/backend/supports/iam/src/basic/serv/clients/iam_kv_client.rs @@ -0,0 +1,66 @@ +use bios_basic::rbum::rbum_enumeration::RbumScopeLevelKind; +use bios_sdk_invoke::clients::spi_kv_client::SpiKvClient; +use tardis::tokio; +use tardis::{ + basic::{dto::TardisContext, result::TardisResult}, + serde_json::Value, + TardisFunsInst, +}; + +use crate::iam_constants; + +pub struct IamKvClient; + +impl IamKvClient { + pub async fn async_add_or_modify_item( + key: String, + value: Value, + info: Option, + scope_level: Option, + _funs: &TardisFunsInst, + ctx: &TardisContext, + ) -> TardisResult<()> { + let ctx_clone = ctx.clone(); + ctx.add_async_task(Box::new(|| { + Box::pin(async move { + let task_handle = tokio::spawn(async move { + let funs = iam_constants::get_tardis_inst(); + let _ = Self::add_or_modify_item(&key, &value, info, scope_level, &funs, &ctx_clone).await; + }); + task_handle.await.unwrap(); + Ok(()) + }) + })) + .await + } + + pub async fn async_delete_item(key: String, _funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<()> { + let ctx_clone = ctx.clone(); + ctx.add_async_task(Box::new(|| { + Box::pin(async move { + let task_handle = tokio::spawn(async move { + let funs = iam_constants::get_tardis_inst(); + let _ = Self::delete_item(&key, &funs, &ctx_clone).await; + }); + task_handle.await.unwrap(); + Ok(()) + }) + })) + .await + } + + pub async fn add_or_modify_item( + key: &str, + value: &Value, + info: Option, + scope_level: Option, + funs: &TardisFunsInst, + ctx: &TardisContext, + ) -> TardisResult<()> { + SpiKvClient::add_or_modify_item(key, value, info, scope_level.map(|kind| kind.to_int()), funs, ctx).await + } + + pub async fn delete_item(key: &str, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<()> { + SpiKvClient::delete_item(key, funs, ctx).await + } +} diff --git a/backend/supports/iam/src/basic/serv/iam_role_serv.rs b/backend/supports/iam/src/basic/serv/iam_role_serv.rs index 92690b6f3..4110f06b1 100644 --- a/backend/supports/iam/src/basic/serv/iam_role_serv.rs +++ b/backend/supports/iam/src/basic/serv/iam_role_serv.rs @@ -9,6 +9,7 @@ use tardis::db::sea_orm::prelude::Expr; use tardis::db::sea_orm::sea_query::SelectStatement; use tardis::db::sea_orm::*; use tardis::log::info; +use tardis::serde_json::json; use tardis::web::web_resp::TardisPage; use tardis::{tokio, TardisFuns, TardisFunsInst}; @@ -35,6 +36,7 @@ use crate::iam_constants::{RBUM_SCOPE_LEVEL_APP, RBUM_SCOPE_LEVEL_TENANT}; use crate::iam_enumeration::{IamRelKind, IamRoleKind}; use crate::iam_initializer::{default_iam_send_avatar, ws_iam_send_client}; +use super::clients::iam_kv_client::IamKvClient; use super::clients::iam_log_client::{IamLogClient, LogParamTag}; use super::clients::iam_search_client::IamSearchClient; use super::iam_cert_serv::IamCertServ; @@ -116,6 +118,7 @@ impl RbumItemCrudOperation