use crate::config::GatewayConfig;
use crate::error::GatewayError;
use crate::policy::PolicyEngine;
pub struct Gateway {
config: GatewayConfig,
policy_engine: PolicyEngine,
}
impl Gateway {
pub fn new(config: GatewayConfig) -> Self {
Self {
config,
policy_engine: PolicyEngine::new(),
}
}
pub fn builder() -> GatewayBuilder {
GatewayBuilder::default()
}
pub async fn init(&mut self) -> Result<(), GatewayError> {
tracing::info!("Initializing QAIL Gateway...");
tracing::info!("Loading schema from: {}", self.config.schema_path);
if let Some(policy_path) = &self.config.policy_path {
tracing::info!("Loading policies from: {}", policy_path);
self.policy_engine.load_from_file(policy_path)?;
}
tracing::info!("Connecting to database...");
tracing::info!("Gateway initialized successfully");
Ok(())
}
pub async fn serve(&self) -> Result<(), GatewayError> {
tracing::info!("Starting QAIL Gateway on {}", self.config.bind_address);
tracing::warn!("HTTP server not yet implemented");
loop {
tokio::time::sleep(std::time::Duration::from_secs(60)).await;
}
}
}
#[derive(Debug, Default)]
pub struct GatewayBuilder {
config: GatewayConfig,
}
impl GatewayBuilder {
pub fn database(mut self, url: impl Into<String>) -> Self {
self.config.database_url = url.into();
self
}
pub fn schema(mut self, path: impl Into<String>) -> Self {
self.config.schema_path = path.into();
self
}
pub fn policy(mut self, path: impl Into<String>) -> Self {
self.config.policy_path = Some(path.into());
self
}
pub fn bind(mut self, addr: impl Into<String>) -> Self {
self.config.bind_address = addr.into();
self
}
pub fn build(self) -> Gateway {
Gateway::new(self.config)
}
pub async fn build_and_init(self) -> Result<Gateway, GatewayError> {
let mut gateway = self.build();
gateway.init().await?;
Ok(gateway)
}
}