Skip to content

Commit

Permalink
iam-kv: add key-name func (#787)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZzIsGod1019 authored Jun 26, 2024
1 parent f260c85 commit a70660d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
29 changes: 29 additions & 0 deletions backend/supports/iam/src/basic/serv/clients/iam_kv_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,26 @@ impl IamKvClient {
.await
}

pub async fn async_add_or_modify_key_name(
key: String,
name: 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::add_or_modify_key_name(&key, &name, &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(|| {
Expand All @@ -60,6 +80,15 @@ impl IamKvClient {
SpiKvClient::add_or_modify_item(key, value, info, scope_level.map(|kind| kind.to_int()), funs, ctx).await
}

pub async fn add_or_modify_key_name(
key: &str,
name: &str,
funs: &TardisFunsInst,
ctx: &TardisContext,
) -> TardisResult<()> {
SpiKvClient::add_or_modify_key_name(key, name, funs, ctx).await
}

pub async fn delete_item(key: &str, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<()> {
SpiKvClient::delete_item(key, funs, ctx).await
}
Expand Down
5 changes: 2 additions & 3 deletions backend/supports/iam/src/basic/serv/iam_role_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ 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};

Expand Down Expand Up @@ -118,7 +117,7 @@ impl RbumItemCrudOperation<iam_role::ActiveModel, IamRoleAddReq, IamRoleModifyRe
ctx,
)
.await;
IamKvClient::async_add_or_modify_item(id.to_string(), json!(role.name.clone()), None, Some(role.scope_level.clone()), funs, ctx).await?;
IamKvClient::async_add_or_modify_key_name(id.to_string(), role.name.clone(), funs, ctx).await?;

Ok(())
}
Expand Down Expand Up @@ -221,7 +220,7 @@ impl RbumItemCrudOperation<iam_role::ActiveModel, IamRoleAddReq, IamRoleModifyRe
if !op_describe.is_empty() {
let _ = IamLogClient::add_ctx_task(LogParamTag::IamRole, Some(id.to_string()), op_describe, Some(op_kind), ctx).await;
}
IamKvClient::async_add_or_modify_item(id.to_string(), json!(role.name.clone()), None, Some(role.scope_level.clone()), funs, ctx).await?;
IamKvClient::async_add_or_modify_key_name(id.to_string(), role.name.clone(), funs, ctx).await?;

Ok(())
}
Expand Down

0 comments on commit a70660d

Please sign in to comment.