bios_iam/console_interface/api/
iam_ci_open_api.rs1use bios_basic::helper::request_helper::try_set_real_ip_from_req_to_ctx;
2use bios_basic::rbum::helper::rbum_scope_helper::check_without_owner_and_unsafe_fill_ctx;
3use tardis::basic::dto::TardisContext;
4use tardis::web::context_extractor::TardisContextExtractor;
5use tardis::web::poem::Request;
6use tardis::web::poem_openapi;
7use tardis::web::poem_openapi::param::{Path, Query};
8use tardis::web::poem_openapi::payload::Json;
9use tardis::web::web_resp::{TardisApiResult, TardisResp, Void};
10
11use crate::basic::dto::iam_open_dto::{IamOpenAddOrModifyProductReq, IamOpenAkSkAddReq, IamOpenAkSkResp, IamOpenBindAkProductReq, IamOpenRuleResp};
12use crate::basic::serv::iam_cert_serv::IamCertServ;
13use crate::basic::serv::iam_open_serv::IamOpenServ;
14use crate::iam_constants;
15
16#[derive(Clone, Default)]
17pub struct IamCiOpenApi;
18
19#[poem_openapi::OpenApi(prefix_path = "/ci/open", tag = "bios_basic::ApiTag::Interface")]
22impl IamCiOpenApi {
23 #[oai(path = "/add_or_modify_product", method = "post")]
26 async fn add_or_modify_product(&self, req: Json<IamOpenAddOrModifyProductReq>, mut ctx: TardisContextExtractor, request: &Request) -> TardisApiResult<Void> {
27 let mut funs = iam_constants::get_tardis_inst();
28 check_without_owner_and_unsafe_fill_ctx(request, &funs, &mut ctx.0)?;
29 try_set_real_ip_from_req_to_ctx(request, &ctx.0).await?;
30 funs.begin().await?;
31 IamOpenServ::add_or_modify_product(&req.0, &funs, &ctx.0).await?;
32 funs.commit().await?;
33 ctx.0.execute_task().await?;
34 TardisResp::ok(Void {})
35 }
36
37 #[oai(path = "/:id/bind_cert_product_and_spec", method = "post")]
40 async fn bind_cert_product_and_spec(
41 &self,
42 id: Path<String>,
43 bind_req: Json<IamOpenBindAkProductReq>,
44 mut ctx: TardisContextExtractor,
45 request: &Request,
46 ) -> TardisApiResult<Void> {
47 let mut funs = iam_constants::get_tardis_inst();
48 check_without_owner_and_unsafe_fill_ctx(request, &funs, &mut ctx.0)?;
49 try_set_real_ip_from_req_to_ctx(request, &ctx.0).await?;
50 funs.begin().await?;
51 IamOpenServ::bind_cert_product_and_spec(&id.0, &bind_req.0, &funs, &ctx.0).await?;
52 funs.commit().await?;
53 ctx.0.execute_task().await?;
54 TardisResp::ok(Void {})
55 }
56
57 #[oai(path = "/aksk", method = "post")]
60 async fn add_aksk(&self, add_req: Json<IamOpenAkSkAddReq>, mut ctx: TardisContextExtractor, request: &Request) -> TardisApiResult<IamOpenAkSkResp> {
61 let mut funs = iam_constants::get_tardis_inst();
62 check_without_owner_and_unsafe_fill_ctx(request, &funs, &mut ctx.0)?;
63 let ctx = IamCertServ::try_use_tenant_ctx(ctx.0, Some(add_req.tenant_id.clone()))?;
64 try_set_real_ip_from_req_to_ctx(request, &ctx).await?;
65 funs.begin().await?;
66 let result = IamOpenServ::general_cert(add_req.0, &funs, &ctx).await?;
67 funs.commit().await?;
68 ctx.execute_task().await?;
69 TardisResp::ok(result)
70 }
71
72 #[oai(path = "/", method = "get")]
75 async fn get_rule_info(&self, cert_id: Query<Option<String>>, ak: Query<Option<String>>, _request: &Request) -> TardisApiResult<IamOpenRuleResp> {
76 let mut funs = iam_constants::get_tardis_inst();
77 let global_ctx = TardisContext {
78 own_paths: "".to_string(),
79 ..Default::default()
80 };
81 funs.begin().await?;
82 let result = IamOpenServ::get_rule_info(cert_id.0, ak.0, &funs, &global_ctx).await?;
83 funs.commit().await?;
84 global_ctx.execute_task().await?;
85 TardisResp::ok(result)
86 }
87
88 #[oai(path = "/refresh_cert_cumulative_count", method = "post")]
91 async fn refresh_cert_cumulative_count(&self, _request: &Request) -> TardisApiResult<Void> {
92 let mut funs = iam_constants::get_tardis_inst();
93 let ctx = TardisContext::default();
94 funs.begin().await?;
95 IamOpenServ::refresh_cert_cumulative_count(&funs, &ctx).await?;
96 funs.commit().await?;
97 ctx.execute_task().await?;
98 TardisResp::ok(Void {})
99 }
100}