Skip to content

Commit

Permalink
spi-conf: config support place holder (#529)
Browse files Browse the repository at this point in the history
  • Loading branch information
4t145 authored Nov 22, 2023
1 parent edcdafd commit f7960a7
Show file tree
Hide file tree
Showing 36 changed files with 595 additions and 96 deletions.
3 changes: 3 additions & 0 deletions basic/src/rbum/domain/rbum_cert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ pub struct Model {
/// Cert key \
/// E.g. password, token, secret key
pub sk: String,
/// Whether the key is visible \
pub sk_invisible: bool,
/// Extend information \
/// The content and format are set by the upper service itself
pub ext: String,
Expand Down Expand Up @@ -79,6 +81,7 @@ impl TardisActiveModel for ActiveModel {
.col(ColumnDef::new(Column::Supplier).not_null().string())
.col(ColumnDef::new(Column::Ak).not_null().string())
.col(ColumnDef::new(Column::Sk).not_null().string())
.col(ColumnDef::new(Column::SkInvisible).not_null().boolean().default(false))
.col(ColumnDef::new(Column::Ext).not_null().string())
.col(ColumnDef::new(Column::ConnUri).not_null().string())
.col(ColumnDef::new(Column::RelRbumCertConfId).not_null().string())
Expand Down
4 changes: 4 additions & 0 deletions basic/src/rbum/dto/rbum_cert_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub struct RbumCertAddReq {
pub ak: TrimString,
#[cfg_attr(feature = "default", oai(validator(min_length = "2", max_length = "10000")))]
pub sk: Option<TrimString>,
pub sk_invisible: Option<bool>,
pub is_ignore_check_sk: bool,
pub kind: Option<String>,
pub supplier: Option<String>,
Expand Down Expand Up @@ -43,6 +44,7 @@ pub struct RbumCertModifyReq {
pub ak: Option<TrimString>,
#[cfg_attr(feature = "default", oai(validator(min_length = "2", max_length = "10000")))]
pub sk: Option<TrimString>,
pub sk_invisible: Option<bool>,
pub is_ignore_check_sk: bool,
#[cfg_attr(feature = "default", oai(validator(min_length = "2", max_length = "2000")))]
pub ext: Option<String>,
Expand Down Expand Up @@ -83,6 +85,7 @@ pub struct RbumCertSummaryWithSkResp {
pub id: String,
pub ak: String,
pub sk: String,
pub sk_invisible: bool,
pub ext: String,
pub conn_uri: String,
pub start_time: DateTime<Utc>,
Expand All @@ -108,6 +111,7 @@ pub struct RbumCertSummaryWithSkResp {
pub struct RbumCertDetailResp {
pub id: String,
pub ak: String,
pub sk_invisible: bool,
pub ext: String,
pub start_time: DateTime<Utc>,
pub end_time: DateTime<Utc>,
Expand Down
2 changes: 2 additions & 0 deletions basic/src/rbum/serv/rbum_cert_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ impl RbumCrudOperation<rbum_cert::ActiveModel, RbumCertAddReq, RbumCertModifyReq
id: Set(TardisFuns::field.nanoid()),
ak: Set(add_req.ak.to_string()),
sk: Set(add_req.sk.as_ref().unwrap_or(&TrimString("".to_string())).to_string()),
sk_invisible: Set(add_req.sk_invisible.unwrap_or(false)),
kind: Set(add_req.kind.as_ref().unwrap_or(&"".to_string()).to_string()),
supplier: Set(add_req.supplier.as_ref().unwrap_or(&"".to_string()).to_string()),
ext: Set(add_req.ext.as_ref().unwrap_or(&"".to_string()).to_string()),
Expand Down Expand Up @@ -598,6 +599,7 @@ impl RbumCrudOperation<rbum_cert::ActiveModel, RbumCertAddReq, RbumCertModifyReq
(rbum_cert::Entity, rbum_cert::Column::Kind),
(rbum_cert::Entity, rbum_cert::Column::Supplier),
(rbum_cert::Entity, rbum_cert::Column::Ak),
(rbum_cert::Entity, rbum_cert::Column::SkInvisible),
(rbum_cert::Entity, rbum_cert::Column::Ext),
(rbum_cert::Entity, rbum_cert::Column::StartTime),
(rbum_cert::Entity, rbum_cert::Column::EndTime),
Expand Down
3 changes: 3 additions & 0 deletions basic/src/spi/serv/spi_bs_serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ impl RbumItemCrudOperation<spi_bs::ActiveModel, SpiBsAddReq, SpiBsModifyReq, Spi
&mut RbumCertAddReq {
ak: add_req.ak.clone(),
sk: Some(add_req.sk.clone()),
sk_invisible: Some(false),
kind: Some(SPI_CERT_KIND.to_string()),
supplier: Some(id.to_string()),
conn_uri: Some(add_req.conn_uri.clone()),
Expand Down Expand Up @@ -142,6 +143,7 @@ impl RbumItemCrudOperation<spi_bs::ActiveModel, SpiBsAddReq, SpiBsModifyReq, Spi
status: None,
start_time: None,
end_time: None,
sk_invisible: None,
},
funs,
ctx,
Expand All @@ -160,6 +162,7 @@ impl RbumItemCrudOperation<spi_bs::ActiveModel, SpiBsAddReq, SpiBsModifyReq, Spi
.column((rbum_cert::Entity, rbum_cert::Column::ConnUri))
.column((rbum_cert::Entity, rbum_cert::Column::Ak))
.column((rbum_cert::Entity, rbum_cert::Column::Sk))
.column((rbum_cert::Entity, rbum_cert::Column::SkInvisible))
.column((rbum_cert::Entity, rbum_cert::Column::Ext))
.left_join(
rbum_kind::Entity,
Expand Down
21 changes: 19 additions & 2 deletions basic/tests/test_rbum_cert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ async fn test_rbum_cert_conf_is_ak_repeatable(context: &TardisContext) -> Tardis
rel_rbum_id: context.owner.to_string(),
is_outside: false,
is_ignore_check_sk: false,
sk_invisible: None,
},
&funs,
context,
Expand All @@ -336,6 +337,7 @@ async fn test_rbum_cert_conf_is_ak_repeatable(context: &TardisContext) -> Tardis
rel_rbum_id: context.owner.to_string(),
is_outside: false,
is_ignore_check_sk: false,
sk_invisible: None,
},
&funs,
context,
Expand All @@ -347,6 +349,7 @@ async fn test_rbum_cert_conf_is_ak_repeatable(context: &TardisContext) -> Tardis
&mut RbumCertModifyReq {
ak: Some("test".into()),
sk: None,
sk_invisible: None,
ext: None,
start_time: None,
end_time: None,
Expand Down Expand Up @@ -410,6 +413,7 @@ async fn test_rbum_cert_conf_is_ak_repeatable(context: &TardisContext) -> Tardis
kind: None,
supplier: None,
is_ignore_check_sk: false,
sk_invisible: None,
},
&funs,
context,
Expand All @@ -432,7 +436,8 @@ async fn test_rbum_cert_conf_is_ak_repeatable(context: &TardisContext) -> Tardis
is_outside: false,
kind: None,
supplier: None,
is_ignore_check_sk: false
is_ignore_check_sk: false,
sk_invisible: None,
},
&funs,
context,
Expand All @@ -445,6 +450,7 @@ async fn test_rbum_cert_conf_is_ak_repeatable(context: &TardisContext) -> Tardis
&mut RbumCertModifyReq {
ak: Some("test".into()),
sk: None,
sk_invisible: None,
ext: None,
start_time: None,
end_time: None,
Expand Down Expand Up @@ -580,7 +586,8 @@ async fn test_rbum_cert_basic(context: &TardisContext) -> TardisResult<()> {
is_outside: false,
kind: None,
supplier: None,
is_ignore_check_sk: false
is_ignore_check_sk: false,
sk_invisible: None,
},
&funs,
context,
Expand All @@ -593,6 +600,7 @@ async fn test_rbum_cert_basic(context: &TardisContext) -> TardisResult<()> {
&mut RbumCertAddReq {
ak: TrimString("gudaoxuri".to_string()),
sk: None,
sk_invisible: None,
ext: None,
vcode: None,
start_time: None,
Expand All @@ -618,6 +626,7 @@ async fn test_rbum_cert_basic(context: &TardisContext) -> TardisResult<()> {
&mut RbumCertAddReq {
ak: TrimString("gudaoxuri".to_string()),
sk: Some(TrimString("aa".to_string())),
sk_invisible: None,
vcode: None,
ext: None,
start_time: None,
Expand All @@ -643,6 +652,7 @@ async fn test_rbum_cert_basic(context: &TardisContext) -> TardisResult<()> {
&mut RbumCertAddReq {
ak: TrimString("gudaoxuri".to_string()),
sk: Some(TrimString("12345678".to_string())),
sk_invisible: None,
vcode: None,
ext: None,
start_time: None,
Expand All @@ -668,6 +678,7 @@ async fn test_rbum_cert_basic(context: &TardisContext) -> TardisResult<()> {
&mut RbumCertAddReq {
ak: TrimString("gudaoxuri".to_string()),
sk: Some(TrimString("12345678".to_string())),
sk_invisible: None,
vcode: None,
ext: None,
start_time: None,
Expand All @@ -692,6 +703,7 @@ async fn test_rbum_cert_basic(context: &TardisContext) -> TardisResult<()> {
&mut RbumCertAddReq {
ak: TrimString("gudaoxuri".to_string()),
sk: Some(TrimString("12345678".to_string())),
sk_invisible: None,
vcode: None,
ext: None,
start_time: None,
Expand All @@ -716,6 +728,7 @@ async fn test_rbum_cert_basic(context: &TardisContext) -> TardisResult<()> {
&mut RbumCertAddReq {
ak: TrimString("gudaoxuri".to_string()),
sk: Some(TrimString("12345678".to_string())),
sk_invisible: None,
vcode: None,
ext: None,
start_time: None,
Expand All @@ -740,6 +753,7 @@ async fn test_rbum_cert_basic(context: &TardisContext) -> TardisResult<()> {
&mut RbumCertAddReq {
ak: TrimString("root".to_string()),
sk: Some(TrimString("12345678".to_string())),
sk_invisible: None,
vcode: None,
ext: None,
start_time: None,
Expand Down Expand Up @@ -776,6 +790,7 @@ async fn test_rbum_cert_basic(context: &TardisContext) -> TardisResult<()> {
ext: Some("ext".to_string()),
ak: None,
sk: None,
sk_invisible: None,
start_time: None,
end_time: None,
conn_uri: None,
Expand All @@ -794,6 +809,7 @@ async fn test_rbum_cert_basic(context: &TardisContext) -> TardisResult<()> {
ext: Some("ext".to_string()),
ak: None,
sk: None,
sk_invisible: None,
start_time: None,
end_time: None,
conn_uri: None,
Expand Down Expand Up @@ -921,6 +937,7 @@ async fn test_rbum_cert_sk_dynamic(context: &TardisContext) -> TardisResult<()>
&mut RbumCertAddReq {
ak: TrimString("i@sunisle.org".to_string()),
sk: None,
sk_invisible: None,
vcode: Some(TrimString("123456".to_string())),
ext: None,
start_time: None,
Expand Down
4 changes: 4 additions & 0 deletions sdk/invoke/src/clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ macro_rules! tardis_api {
build
*/
($fn_name:ident @build get {$($args_i:ident:$args_t:ty,)*} {$($path:expr,)*} {$($query:expr,)*;$($optional_query:expr,)*} $Resp:ty) => {
#[allow(unused_mut)]
pub async fn $fn_name(&self, $($args_i:$args_t,)*) -> tardis::basic::result::TardisResult<$Resp> {
use $crate::clients::SimpleInvokeClient;
use tardis::web::web_resp::TardisResp;
Expand All @@ -186,6 +187,7 @@ macro_rules! tardis_api {
}
};
($fn_name:ident @build post {$($args_i:ident:$args_t:ty,)*} {$($path:expr,)*} {$($query:expr,)*;$($optional_query:expr,)*} $Body:ty => $Resp:ty) => {
#[allow(unused_mut)]
pub async fn $fn_name(&self, $($args_i:$args_t,)* body: &$Body) -> tardis::basic::result::TardisResult<$Resp> {
use $crate::clients::SimpleInvokeClient;
use tardis::web::web_resp::TardisResp;
Expand All @@ -209,6 +211,7 @@ macro_rules! tardis_api {
}
};
($fn_name:ident @build put {$($args_i:ident:$args_t:ty,)*} {$($path:expr,)*} {$($query:expr,)*;$($optional_query:expr,)*} $Body:ty => $Resp:ty) => {
#[allow(unused_mut)]
pub async fn $fn_name(&self, $($args_i:$args_t,)* body: &$Body) -> tardis::basic::result::TardisResult<$Resp> {
use $crate::clients::SimpleInvokeClient;
use tardis::web::web_resp::TardisResp;
Expand All @@ -232,6 +235,7 @@ macro_rules! tardis_api {
}
};
($fn_name:ident @build delete {$($args_i:ident:$args_t:ty,)*} {$($path:expr,)*} {$($query:expr,)*;$($optional_query:expr,)*} $Resp:ty) => {
#[allow(unused_mut)]
pub async fn $fn_name(&self, $($args_i:$args_t),*) -> tardis::basic::result::TardisResult<$Resp> {
use $crate::clients::SimpleInvokeClient;
use tardis::web::web_resp::TardisResp;
Expand Down
8 changes: 7 additions & 1 deletion sdk/invoke/src/clients/iam_client.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::HashMap;
use std::collections::{HashMap, HashSet};

use serde::{Deserialize, Serialize};
use tardis::{basic::dto::TardisContext, web::poem_openapi, TardisFunsInst};
Expand Down Expand Up @@ -47,7 +47,13 @@ pub struct IamAccountDetailAggResp {
pub orgs: Vec<String>,
}

#[derive(poem_openapi::Object, Serialize, Deserialize, Debug)]
pub struct IamCertDecodeRequest {
pub codes: HashSet<String>,
}

impl_tardis_api_client! {
IamClient<'_>:
{get_account, get ["/ct/account", id] {tenant_id} IamAccountDetailAggResp}
{batch_decode_cert, post ["/ct/cert/manage/decode"] IamCertDecodeRequest => HashMap<String, String>}
}
1 change: 0 additions & 1 deletion services/bios-all/src/initializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ pub async fn init(web_server: &TardisWebServer) -> TardisResult<()> {
.with_arc_channel(tardis::TardisFuns::mail_by_module_or_default(bios_reach::reach_consts::MODULE_CODE)),
)
.await?;

bios_spi_cache::cache_initializer::init(web_server).await?;
bios_spi_graph::graph_initializer::init(web_server).await?;
bios_spi_kv::kv_initializer::init(web_server).await?;
Expand Down
8 changes: 6 additions & 2 deletions spi/spi-conf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,15 @@ poem = "1"
prost-types = "0.11.9"
strum = { version = "0.25.0", features = ["derive"] }
tokio-stream = { version = "0.1.14", features = ["sync"] }

bios-sdk-invoke = { path = "../../sdk/invoke", features = [
"iam",
"macro",
], default-features = false }
ipnet = { version = "2", features = ["serde"] }
[dev-dependencies]
tardis = { workspace = true, features = ["test", "conf-remote", "mq"] }
bios-basic = { path = "../../basic", features = ["default", "test"] }
reqwest = "*"
testcontainers-modules = { workspace = true }
[build-dependencies]
poem-grpc-build = "0.2.21"
poem-grpc-build = "0.2.22"
Loading

0 comments on commit f7960a7

Please sign in to comment.