use super::Command;
use crate::{Args, Result, TlsError};
use async_trait::async_trait;
use tracing::info;
pub struct ApiServerCommand {
args: Args,
}
impl ApiServerCommand {
pub fn new(args: Args) -> Self {
Self { args }
}
}
#[async_trait]
impl Command for ApiServerCommand {
async fn execute(&self) -> Result<()> {
use crate::api::{ApiConfig, ApiServer};
info!("Starting CipherRun in API server mode");
let mut config = if let Some(config_path) = &self.args.api_server.config {
let config_str = config_path.to_str().ok_or_else(|| TlsError::InvalidInput {
message: "Invalid config file path".to_string(),
})?;
ApiConfig::from_file(config_str)?
} else {
ApiConfig::default()
};
config.host = self.args.api_server.host.clone();
config.port = self.args.api_server.port;
config.max_concurrent_scans = self.args.api_server.max_concurrent;
config.enable_swagger = self.args.api_server.swagger || config.enable_swagger;
let server = ApiServer::new(config)?;
server.run().await?;
Ok(())
}
fn name(&self) -> &'static str {
"ApiServerCommand"
}
}