pub mod builder; pub mod info; pub mod traits; pub mod upstream; use std::sync::Arc; use sea_orm::{DatabaseConnection, DatabaseTransaction}; use crate::{ errors::service_error::ServiceError, services::{ agent_client::AgentService, nginx::{ builder::{NginxConfigBuilder, NginxConfigProvider}, upstream::{UpstreamService, UpstreamServiceImpl}, }, }, }; pub struct NginxService { #[allow(dead_code)] connection: Arc, // upstream_service: Arc, } impl NginxService { pub fn new(connection: Arc) -> Self { Self { connection: connection.clone(), // upstream_service: Arc::new(UpstreamServiceImpl::new(connection.clone())), } } pub fn get_upstream_service(&self) -> Arc { self.upstream_service.clone() } #[allow(dead_code)] pub async fn validate_config( &self, agent: Arc, config: &str, ) -> Result<(), ServiceError> { agent.validate(config).await?; Ok(()) } pub async fn apply_changes( &self, agent: Arc, config: &str, ) -> Result<(), ServiceError> { agent.apply(config).await?; Ok(()) } pub async fn generate_config( &self, tx: Option<&mut DatabaseTransaction>, ) -> Result { let mut builder = NginxConfigBuilder::default(); self.upstream_service .generate_config(&mut builder, tx) .await?; Ok(builder.to_nginx_config(None)) } pub async fn regenerate_and_apply_config( &self, agent: Arc, tx: Option<&mut DatabaseTransaction>, ) -> Result<(), ServiceError> { let config = self.generate_config(tx).await?; self.apply_changes(agent, &config).await?; Ok(()) } }