Skip to content

Commit

Permalink
fix test error and api update (#700)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZzIsGod1019 authored Apr 8, 2024
1 parent 65c162b commit 7109713
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 19 deletions.
46 changes: 34 additions & 12 deletions backend/supports/iam/src/basic/serv/iam_open_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,18 +400,40 @@ impl IamOpenServ {
Ok(())
}

pub async fn get_rule_info(cert_id: String, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<IamOpenRuleResp> {
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<String>, ak_req: Option<String>, funs: &TardisFunsInst, ctx: &TardisContext) -> TardisResult<IamOpenRuleResp> {
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,16 @@ impl IamCiOpenApi {

/// Get account rule info / 获取账号规则信息
#[oai(path = "/", method = "get")]
async fn get_rule_info(&self, cert_id: Query<String>, mut ctx: TardisContextExtractor, request: &Request) -> TardisApiResult<IamOpenRuleResp> {
async fn get_rule_info(&self, cert_id: Query<Option<String>>, ak: Query<Option<String>>, request: &Request) -> TardisApiResult<IamOpenRuleResp> {
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)
}

Expand Down
2 changes: 1 addition & 1 deletion backend/supports/iam/tests/test_ci_open.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion backend/supports/iam/tests/test_iam_cert_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<IamConfig>().cache_key_async_task_status, task_id.parse::<i64>().unwrap(), &funs.cache()).await.unwrap();
is_finish = TaskProcessor::check_status(&funs.conf::<IamConfig>().cache_key_async_task_status, task_id.parse::<u64>().unwrap(), &funs.cache()).await.unwrap();
}
}
let account_page = IamAccountServ::paginate_account_summary_aggs(
Expand Down

0 comments on commit 7109713

Please sign in to comment.