use crate::cli::config::Config;
use malwaredb_server::vt::VtUpdater;
use std::path::PathBuf;
use std::process::ExitCode;
use anyhow::Context;
use clap::Parser;
use malwaredb_virustotal::common::ReportResponseHeader;
use malwaredb_virustotal::filereport::ScanResultAttributes;
#[derive(Parser, Debug)]
pub struct DataLoader {
#[arg(short, long)]
pub report: PathBuf,
#[clap(subcommand)]
cmd: Option<super::VtConfig>,
}
impl DataLoader {
pub async fn execute(self) -> anyhow::Result<ExitCode> {
let report =
std::fs::read_to_string(&self.report).context("failed to read VT report file")?;
let report: ReportResponseHeader<ScanResultAttributes> =
toml::from_str(&report).context("failed to parse VT report")?;
let cfg = match self.cmd {
Some(config) => config.config()?,
None => Config::from_found_files()?,
};
let updater: VtUpdater = cfg.into_state().await?.try_into()?;
updater.loader(&report.attributes).await?;
Ok(ExitCode::SUCCESS)
}
}