diff --git a/backend/supports/iam/src/basic/serv/iam_open_serv.rs b/backend/supports/iam/src/basic/serv/iam_open_serv.rs index 45c8a7ba0..20cee3e93 100644 --- a/backend/supports/iam/src/basic/serv/iam_open_serv.rs +++ b/backend/supports/iam/src/basic/serv/iam_open_serv.rs @@ -400,18 +400,40 @@ impl IamOpenServ { Ok(()) } - pub async fn get_rule_info(cert_id: String, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult { - let ak = RbumCertServ::find_one_detail_rbum( - &RbumCertFilterReq { - id: Some(cert_id.to_string()), - ..Default::default() - }, - funs, - ctx, - ) - .await? - .ok_or_else(|| funs.err().internal_error("iam_open", "get_rule_info", "cert not found", "404-iam-res-not-exist"))? - .ak; + pub async fn get_rule_info(cert_id_req: Option, ak_req: Option, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult { + if cert_id_req.is_none() && ak_req.is_none() { + return Err(funs.err().internal_error("iam_open", "get_rule_info", "illegal response", "404-iam-res-not-exist")); + } + let cert_id = if let Some(cert_id) = cert_id_req.clone() { + cert_id + } else { + RbumCertServ::find_one_detail_rbum( + &RbumCertFilterReq { + ak: ak_req.clone(), + ..Default::default() + }, + funs, + ctx, + ) + .await? + .ok_or_else(|| funs.err().internal_error("iam_open", "get_rule_info", "cert not found", "404-iam-res-not-exist"))? + .id + }; + let ak = if let Some(ak) = ak_req.clone() { + ak + } else { + RbumCertServ::find_one_detail_rbum( + &RbumCertFilterReq { + id: cert_id_req.clone(), + ..Default::default() + }, + funs, + ctx, + ) + .await? + .ok_or_else(|| funs.err().internal_error("iam_open", "get_rule_info", "cert not found", "404-iam-res-not-exist"))? + .ak + }; // let spec_id = IamRelServ::find_from_id_rels(&IamRelKind::IamCertSpec, false, &cert_id, None, None, funs, ctx).await?.pop().unwrap_or_default(); let spec_id = RbumRelServ::find_detail_rbums( &RbumRelFilterReq { diff --git a/backend/supports/iam/src/console_interface/api/iam_ci_open_api.rs b/backend/supports/iam/src/console_interface/api/iam_ci_open_api.rs index 4922343b2..829c6491f 100644 --- a/backend/supports/iam/src/console_interface/api/iam_ci_open_api.rs +++ b/backend/supports/iam/src/console_interface/api/iam_ci_open_api.rs @@ -68,14 +68,16 @@ impl IamCiOpenApi { /// Get account rule info / 获取账号规则信息 #[oai(path = "/", method = "get")] - async fn get_rule_info(&self, cert_id: Query, mut ctx: TardisContextExtractor, request: &Request) -> TardisApiResult { + async fn get_rule_info(&self, cert_id: Query>, ak: Query>, request: &Request) -> TardisApiResult { let mut funs = iam_constants::get_tardis_inst(); - unsafe_fill_ctx(request, &funs, &mut ctx.0)?; - add_remote_ip(request, &ctx.0).await?; + let global_ctx = TardisContext { + own_paths: "".to_string(), + ..Default::default() + }; funs.begin().await?; - let result = IamOpenServ::get_rule_info(cert_id.0, &funs, &ctx.0).await?; + let result = IamOpenServ::get_rule_info(cert_id.0, ak.0, &funs, &global_ctx).await?; funs.commit().await?; - ctx.0.execute_task().await?; + global_ctx.execute_task().await?; TardisResp::ok(result) } diff --git a/backend/supports/iam/tests/test_ci_open.rs b/backend/supports/iam/tests/test_ci_open.rs index dd2450173..8c9e65e15 100644 --- a/backend/supports/iam/tests/test_ci_open.rs +++ b/backend/supports/iam/tests/test_ci_open.rs @@ -110,7 +110,7 @@ pub async fn test(context1: &TardisContext) -> TardisResult<()> { ) .await?; info!("【test_ci_open】 : Get account info"); - let info = IamOpenServ::get_rule_info(cert_id.clone(), &funs, context1).await?; + let info = IamOpenServ::get_rule_info(Some(cert_id.clone()), None, &funs, context1).await?; assert_eq!(info.cert_id, cert_id.clone()); assert_eq!(info.spec_code, spec1_code.clone()); assert_eq!(info.api_call_frequency, Some(500)); diff --git a/backend/supports/iam/tests/test_iam_cert_sync.rs b/backend/supports/iam/tests/test_iam_cert_sync.rs index 4683434b0..51f04411d 100644 --- a/backend/supports/iam/tests/test_iam_cert_sync.rs +++ b/backend/supports/iam/tests/test_iam_cert_sync.rs @@ -130,7 +130,7 @@ pub async fn test(ldap_account_num: u64, conf_ldap_add_or_modify_req: IamCertCon let mut is_finish = false; while is_finish { sleep(Duration::from_millis(100)).await; - is_finish = TaskProcessor::check_status(&funs.conf::().cache_key_async_task_status, task_id.parse::().unwrap(), &funs.cache()).await.unwrap(); + is_finish = TaskProcessor::check_status(&funs.conf::().cache_key_async_task_status, task_id.parse::().unwrap(), &funs.cache()).await.unwrap(); } } let account_page = IamAccountServ::paginate_account_summary_aggs(