forked from ideal-world/spacegate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
454 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,14 @@ | ||
use tardis::async_trait::async_trait; | ||
use tardis::basic::result::TardisResult; | ||
|
||
pub mod gateway_vo_conv; | ||
pub mod plugin_vo_conv; | ||
|
||
#[async_trait] | ||
pub trait VoConv<M, S> | ||
where | ||
S: VoConv<M, S>, | ||
{ | ||
async fn to_model(self) -> TardisResult<M>; | ||
async fn from_model(model: M) -> TardisResult<S>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
use crate::model::query_dto::PluginQueryDto; | ||
use crate::model::vo::gateway_vo::{SgGatewayVO, SgListenerVO, SgTlsConfigVO}; | ||
use crate::model::vo_converter::VoConv; | ||
use crate::service::base_service::VoBaseService; | ||
use crate::service::plugin_service::PluginServiceVo; | ||
use crate::service::tls_config_service::TlsConfigServiceVo; | ||
use kernel_common::inner_model::gateway::{SgGateway, SgListener, SgTlsConfig}; | ||
use kernel_common::inner_model::plugin_filter::SgRouteFilter; | ||
use tardis::async_trait::async_trait; | ||
use tardis::basic::result::TardisResult; | ||
use tardis::futures_util::future::join_all; | ||
use tardis::TardisFuns; | ||
|
||
#[async_trait] | ||
impl VoConv<SgGateway, SgGatewayVO> for SgGatewayVO { | ||
async fn to_model(self) -> TardisResult<SgGateway> { | ||
let filters = if let Some(filter_strs) = self.filters { | ||
Some( | ||
join_all( | ||
PluginServiceVo::list(PluginQueryDto { | ||
ids: Some(filter_strs), | ||
..Default::default() | ||
}) | ||
.await? | ||
.into_iter() | ||
.map(|f| f.to_model()) | ||
.collect::<Vec<_>>(), | ||
) | ||
.await | ||
.into_iter() | ||
.collect::<TardisResult<Vec<_>>>()?, | ||
) | ||
} else { | ||
None | ||
}; | ||
Ok(SgGateway { | ||
name: self.name, | ||
parameters: self.parameters, | ||
listeners: join_all(self.listeners.into_iter().map(|l| l.to_model()).collect::<Vec<_>>()).await.into_iter().collect::<TardisResult<Vec<_>>>()?, | ||
filters, | ||
}) | ||
} | ||
|
||
async fn from_model(model: SgGateway) -> TardisResult<SgGatewayVO> { | ||
todo!() | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl VoConv<SgListener, SgListenerVO> for SgListenerVO { | ||
async fn to_model(self) -> TardisResult<SgListener> { | ||
let tls = if let Some(tls_id) = self.tls { | ||
Some(TlsConfigServiceVo::get_by_id(&tls_id).await?.to_model().await?) | ||
} else { | ||
None | ||
}; | ||
|
||
Ok(SgListener { | ||
name: self.name, | ||
ip: self.ip, | ||
port: self.port, | ||
protocol: self.protocol, | ||
tls, | ||
hostname: self.hostname, | ||
}) | ||
} | ||
|
||
async fn from_model(model: SgListener) -> TardisResult<SgListenerVO> { | ||
todo!() | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl VoConv<SgTlsConfig, SgTlsConfigVO> for SgTlsConfigVO { | ||
async fn to_model(self) -> TardisResult<SgTlsConfig> { | ||
Ok(SgTlsConfig { | ||
mode: self.mode, | ||
key: self.key, | ||
cert: self.cert, | ||
}) | ||
} | ||
|
||
async fn from_model(model: SgTlsConfig) -> TardisResult<SgTlsConfigVO> { | ||
Ok(SgTlsConfigVO { | ||
id: TardisFuns::crypto.digest.md5(&format!("{}{}{}", model.mode.clone().to_kube_tls_mode_type().to_string(), model.key, model.cert))?, | ||
mode: model.mode, | ||
key: model.key, | ||
cert: model.cert, | ||
ref_ids: None, | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use crate::model::vo::plugin_vo::SgFilterVO; | ||
use crate::model::vo_converter::VoConv; | ||
use kernel_common::inner_model::plugin_filter::SgRouteFilter; | ||
use tardis::async_trait::async_trait; | ||
use tardis::basic::result::TardisResult; | ||
|
||
#[async_trait] | ||
impl VoConv<SgRouteFilter, SgFilterVO> for SgFilterVO { | ||
async fn to_model(self) -> TardisResult<SgRouteFilter> { | ||
Ok(SgRouteFilter { | ||
code: self.code, | ||
name: self.name, | ||
spec: self.spec, | ||
}) | ||
} | ||
|
||
async fn from_model(model: SgRouteFilter) -> TardisResult<SgFilterVO> { | ||
todo!() | ||
} | ||
} |
Oops, something went wrong.