feat(proxy): add render_config method and UpstreamService mock
- Add render_config to ProxyServiceTrait and implement it - Add mockall automock to UpstreamService - Remove unused OverrideRef import
This commit is contained in:
@@ -39,6 +39,9 @@ pub trait ProxyServiceTrait: Send + Sync + 'static {
|
||||
) -> ProxyServiceResult<ProxyConfigSummary>;
|
||||
async fn delete_config(&self, id: uuid::Uuid) -> ProxyServiceResult<bool>;
|
||||
|
||||
// Render
|
||||
async fn render_config(&self, proxy_id: uuid::Uuid) -> ProxyServiceResult<String>;
|
||||
|
||||
// Binding
|
||||
async fn get_active_agent_config(
|
||||
&self,
|
||||
|
||||
@@ -32,6 +32,15 @@ impl ProxyServiceTrait for ProxyServiceImpl {
|
||||
self.repo.get_merged_proxy_config(proxy_id).await
|
||||
}
|
||||
|
||||
async fn render_config(&self, proxy_id: uuid::Uuid) -> ProxyServiceResult<String> {
|
||||
let config = self.repo.get_merged_proxy_config(proxy_id).await?;
|
||||
let renderer = self
|
||||
.renderers
|
||||
.get(&config.r#type)
|
||||
.ok_or(ProxyServiceError::RendererNotFound)?;
|
||||
Ok(renderer.render(&config))
|
||||
}
|
||||
|
||||
async fn list_configs(&self) -> ProxyServiceResult<Vec<ProxyConfigSummary>> {
|
||||
self.repo.list_proxy_configs().await
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ use sea_orm::{ActiveModelTrait, ActiveValue::Set, DatabaseConnection, EntityTrai
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::service::proxy::types::{
|
||||
OverrideRef, ProxyServiceError, ProxyServiceResult, UpstreamConfig,
|
||||
ProxyServiceError, ProxyServiceResult, UpstreamConfig,
|
||||
};
|
||||
|
||||
pub struct CreateUpstreamParams {
|
||||
@@ -34,6 +34,7 @@ fn model_to_config(model: crate::db::entities::upstream::Model) -> UpstreamConfi
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(test, mockall::automock)]
|
||||
#[async_trait::async_trait]
|
||||
pub trait UpstreamService: Send + Sync + 'static {
|
||||
async fn get(&self, id: Uuid) -> ProxyServiceResult<UpstreamConfig>;
|
||||
|
||||
Reference in New Issue
Block a user