malwaredb 0.3.2

Service for storing malicious, benign, or unknown files and related metadata and relationships.
// SPDX-License-Identifier: Apache-2.0

use malwaredb_server::State;

use std::process::ExitCode;

use clap::{Args, Subcommand};

/// Show (or toggle) the state of Malware DB submitting samples to Virus Total
#[derive(Clone, Debug, Args, PartialEq)]
pub struct VirusTotal {
    /// Optionally enable or disable Virus Total submission
    #[clap(subcommand)]
    option: Option<Options>,
}

#[derive(Clone, Debug, Subcommand, PartialEq, Eq)]
enum Options {
    /// Specifies that files may be sent to Virus Total.
    Enable,

    /// Clears the VT flag, files will not be sent to Virus Total.
    Disable,
}

impl VirusTotal {
    pub async fn execute(&self, state: State) -> anyhow::Result<ExitCode> {
        match self.option {
            None => {
                let virustotal_state = if state.db_config.send_samples_to_vt {
                    "enabled"
                } else {
                    "disabled"
                };
                println!("VT submission {virustotal_state}");
            }
            Some(Options::Enable) => {
                state.db_type.enable_vt_upload().await?;
                println!("VT submission flag set.");
            }
            Some(Options::Disable) => {
                state.db_type.disable_vt_upload().await?;
                println!("VT submission flag unset.");
            }
        }
        Ok(ExitCode::SUCCESS)
    }
}