feat(proxy): implement log setting, proxy setting, rewrite rule, server block, and SSL certificate services

- Added LogSettingService with CRUD operations for log settings.
- Introduced ProxySettingService for managing proxy settings with CRUD functionality.
- Created RewriteRuleService to handle rewrite rules with full CRUD capabilities.
- Implemented ServerBlockService for managing server blocks, including relationships with access rules and location blocks.
- Added SslCertificateService for managing SSL certificates with create, read, update, and delete operations.
- Updated types.rs to include new service configurations and ensure proper merging of overrides.
- Enhanced existing tests to cover new functionalities and ensure correctness.
This commit is contained in:
GW_MC
2026-06-21 12:14:26 +00:00
parent 2e758c67fc
commit 7c233b5f77
15 changed files with 1833 additions and 35 deletions

View File

@@ -0,0 +1,115 @@
use sea_orm::{ActiveModelTrait, ActiveValue::Set, DatabaseConnection, EntityTrait, prelude::*};
use uuid::Uuid;
use crate::service::proxy::types::{LimitZoneConfig, ProxyServiceError, ProxyServiceResult};
pub struct CreateLimitZoneParams {
pub name: String,
pub key: String,
pub rate: String,
pub override_of_id: Option<Uuid>,
}
pub struct UpdateLimitZoneParams {
pub name: Option<String>,
pub key: Option<String>,
pub rate: Option<String>,
pub override_of_id: Option<Option<Uuid>>,
}
#[async_trait::async_trait]
pub trait LimitZoneService: Send + Sync + 'static {
async fn get(&self, id: Uuid) -> ProxyServiceResult<LimitZoneConfig>;
async fn list(&self) -> ProxyServiceResult<Vec<LimitZoneConfig>>;
async fn create(&self, params: CreateLimitZoneParams) -> ProxyServiceResult<LimitZoneConfig>;
async fn update(
&self,
id: Uuid,
params: UpdateLimitZoneParams,
) -> ProxyServiceResult<LimitZoneConfig>;
async fn delete(&self, id: Uuid) -> ProxyServiceResult<bool>;
}
pub(crate) struct LimitZoneServiceImpl {
db: DatabaseConnection,
}
impl LimitZoneServiceImpl {
pub fn new(db: DatabaseConnection) -> Self {
Self { db }
}
}
#[async_trait::async_trait]
impl LimitZoneService for LimitZoneServiceImpl {
async fn get(&self, id: Uuid) -> ProxyServiceResult<LimitZoneConfig> {
use crate::db::entities::limit_zone;
let model = limit_zone::Entity::find_by_id(id)
.one(&self.db)
.await?
.ok_or(ProxyServiceError::ConfigNotFound)?;
Ok(model.into())
}
async fn list(&self) -> ProxyServiceResult<Vec<LimitZoneConfig>> {
use crate::db::entities::limit_zone;
let models = limit_zone::Entity::find().all(&self.db).await?;
Ok(models.into_iter().map(Into::into).collect())
}
async fn create(&self, params: CreateLimitZoneParams) -> ProxyServiceResult<LimitZoneConfig> {
use crate::db::entities::limit_zone::ActiveModel;
let model = ActiveModel {
id: Set(Uuid::new_v4()),
name: Set(params.name),
key: Set(params.key),
rate: Set(params.rate),
override_of_id: Set(params.override_of_id),
};
let result = model.insert(&self.db).await?;
Ok(result.into())
}
async fn update(
&self,
id: Uuid,
params: UpdateLimitZoneParams,
) -> ProxyServiceResult<LimitZoneConfig> {
use crate::db::entities::limit_zone::{ActiveModel, Entity as LimitZoneEntity};
let existing = LimitZoneEntity::find_by_id(id)
.one(&self.db)
.await?
.ok_or(ProxyServiceError::ConfigNotFound)?;
let mut model: ActiveModel = existing.into();
if let Some(name) = params.name {
model.name = Set(name);
}
if let Some(key) = params.key {
model.key = Set(key);
}
if let Some(rate) = params.rate {
model.rate = Set(rate);
}
if let Some(override_of_id) = params.override_of_id {
model.override_of_id = Set(override_of_id);
}
let result = model.update(&self.db).await?;
Ok(result.into())
}
async fn delete(&self, id: Uuid) -> ProxyServiceResult<bool> {
let result = crate::db::entities::limit_zone::Entity::delete_by_id(id)
.exec(&self.db)
.await?;
Ok(result.rows_affected > 0)
}
}