Enum malwaredb_server::db::DatabaseType
source · pub enum DatabaseType {
Postgres(Postgres),
SQLite(Sqlite),
}
Expand description
Database handle for SQLite or Postgres
Variants§
Implementations§
source§impl DatabaseType
impl DatabaseType
sourcepub async fn from_string(arg: &str) -> Result<Self>
pub async fn from_string(arg: &str) -> Result<Self>
Get a database connection from a configuration string
sourcepub async fn enable_compression(&self) -> Result<()>
pub async fn enable_compression(&self) -> Result<()>
Set the compression flag
sourcepub async fn disable_compression(&self) -> Result<()>
pub async fn disable_compression(&self) -> Result<()>
Unset the compression flag, does not go and decompress files already compressed!
sourcepub async fn enable_vt_upload(&self) -> Result<()>
pub async fn enable_vt_upload(&self) -> Result<()>
Set the flag allowing uploads to VirusTotal.
sourcepub async fn disable_vt_upload(&self) -> Result<()>
pub async fn disable_vt_upload(&self) -> Result<()>
Set the flag preventing uploads to VirusTotal.
sourcepub async fn files_without_vt_records(&self, limit: i32) -> Result<Vec<String>>
pub async fn files_without_vt_records(&self, limit: i32) -> Result<Vec<String>>
Get the SHA-256 hashes of the files which don’t have VT records
sourcepub async fn store_vt_record(
&self,
results: &ScanResultAttributes,
) -> Result<()>
pub async fn store_vt_record( &self, results: &ScanResultAttributes, ) -> Result<()>
Store the VT results: AV hits and detailed report, or lack of any AV hits
sourcepub async fn get_vt_stats(&self) -> Result<VtStats>
pub async fn get_vt_stats(&self) -> Result<VtStats>
Quick statistics regarding the data contained for VT information for our samples
sourcepub async fn get_config(&self) -> Result<MDBConfig>
pub async fn get_config(&self) -> Result<MDBConfig>
Get the configuration which is stored in the database
sourcepub async fn authenticate(&self, uname: &str, password: &str) -> Result<String>
pub async fn authenticate(&self, uname: &str, password: &str) -> Result<String>
Check user credentials, return API key. Generate if it doesn’t exist.
sourcepub async fn db_info(&self) -> Result<DatabaseInformation>
pub async fn db_info(&self) -> Result<DatabaseInformation>
Retrieve information about the database
sourcepub async fn get_user_info(&self, uid: i32) -> Result<GetUserInfoResponse>
pub async fn get_user_info(&self, uid: i32) -> Result<GetUserInfoResponse>
Retrieve the names of the groups and sources the user is part of and has access to
sourcepub async fn get_user_sources(&self, uid: i32) -> Result<Sources>
pub async fn get_user_sources(&self, uid: i32) -> Result<Sources>
Retrieve the source information available to the specified user
sourcepub async fn reset_own_api_key(&self, uid: i32) -> Result<()>
pub async fn reset_own_api_key(&self, uid: i32) -> Result<()>
Let the user clear their own API key to log out from all systems
sourcepub async fn get_known_data_types(&self) -> Result<Vec<FileType>>
pub async fn get_known_data_types(&self) -> Result<Vec<FileType>>
Retrieve the supported data type information
sourcepub async fn get_labels(&self) -> Result<Labels>
pub async fn get_labels(&self) -> Result<Labels>
Get all labels from MalwareDB
sourcepub async fn get_type_id_for_bytes(&self, data: &[u8]) -> Result<i32>
pub async fn get_type_id_for_bytes(&self, data: &[u8]) -> Result<i32>
Get the corresponding type ID for a buffer representing a file
sourcepub async fn allowed_user_source(&self, uid: i32, sid: i32) -> Result<bool>
pub async fn allowed_user_source(&self, uid: i32, sid: i32) -> Result<bool>
Check that a user has been granted access data for the specific source
sourcepub async fn user_is_admin(&self, uid: i32) -> Result<bool>
pub async fn user_is_admin(&self, uid: i32) -> Result<bool>
Check to see if the user is an administrator. The user must be a member of the the admin group (group ID 0), or a one group below (a group with the parent group id of 0).
sourcepub async fn add_file(
&self,
meta: &FileMetadata,
known_type: KnownType<'_>,
uid: i32,
sid: i32,
ftype: i32,
parent: Option<i64>,
) -> Result<bool>
pub async fn add_file( &self, meta: &FileMetadata, known_type: KnownType<'_>, uid: i32, sid: i32, ftype: i32, parent: Option<i64>, ) -> Result<bool>
Add a file’s metadata to the database, returning true if this is a new entry
sourcepub async fn retrieve_sample(&self, uid: i32, hash: &HashType) -> Result<String>
pub async fn retrieve_sample(&self, uid: i32, hash: &HashType) -> Result<String>
Retrieve the SHA-256 hash of the sample while checking that the user is permitted to access to it
sourcepub async fn get_sample_report(
&self,
uid: i32,
hash: &HashType,
) -> Result<Report>
pub async fn get_sample_report( &self, uid: i32, hash: &HashType, ) -> Result<Report>
Retrieve a report for a given sample, if allowed.
sourcepub async fn find_similar_samples(
&self,
uid: i32,
sim: &[(SimilarityHashType, String)],
) -> Result<Vec<SimilarSample>>
pub async fn find_similar_samples( &self, uid: i32, sim: &[(SimilarityHashType, String)], ) -> Result<Vec<SimilarSample>>
Given a collection of similarity hashes, find samples which are similar.
sourcepub async fn add_file_encryption_key(&self, key: &FileEncryption) -> Result<u32>
pub async fn add_file_encryption_key(&self, key: &FileEncryption) -> Result<u32>
Add an encryption key to the database, set it as the default, and return the key ID
sourcepub async fn get_encryption_key_names_ids(
&self,
) -> Result<Vec<(u32, EncryptionOption)>>
pub async fn get_encryption_key_names_ids( &self, ) -> Result<Vec<(u32, EncryptionOption)>>
Get the key ID and algorithm names
sourcepub async fn create_user(
&self,
uname: &str,
fname: &str,
lname: &str,
email: &str,
password: Option<String>,
organisation: Option<String>,
) -> Result<u64>
pub async fn create_user( &self, uname: &str, fname: &str, lname: &str, email: &str, password: Option<String>, organisation: Option<String>, ) -> Result<u64>
Create a user account, return the user ID.
sourcepub async fn reset_api_keys(&self) -> Result<u64>
pub async fn reset_api_keys(&self) -> Result<u64>
Clear all API keys, either in case of suspected activity, or part of policy
sourcepub async fn set_password(&self, uname: &str, password: &str) -> Result<()>
pub async fn set_password(&self, uname: &str, password: &str) -> Result<()>
Set a user’s password
sourcepub async fn list_users(&self) -> Result<Vec<User>>
pub async fn list_users(&self) -> Result<Vec<User>>
Get the complete list of users
sourcepub async fn group_id_from_name(&self, name: &str) -> Result<i32>
pub async fn group_id_from_name(&self, name: &str) -> Result<i32>
Get the ID of a group from name
sourcepub async fn edit_group(
&self,
gid: i32,
name: &str,
desc: &str,
parent: Option<i32>,
) -> Result<()>
pub async fn edit_group( &self, gid: i32, name: &str, desc: &str, parent: Option<i32>, ) -> Result<()>
Update the record for a group
sourcepub async fn list_groups(&self) -> Result<Vec<Group>>
pub async fn list_groups(&self) -> Result<Vec<Group>>
Get the complete list of groups
sourcepub async fn add_user_to_group(&self, uid: i32, gid: i32) -> Result<()>
pub async fn add_user_to_group(&self, uid: i32, gid: i32) -> Result<()>
Grant a user membership to a group, both by id.
sourcepub async fn add_group_to_source(&self, gid: i32, sid: i32) -> Result<()>
pub async fn add_group_to_source(&self, gid: i32, sid: i32) -> Result<()>
Grand a group access to a source, both by id.
sourcepub async fn create_group(
&self,
name: &str,
description: &str,
parent: Option<i32>,
) -> Result<i32>
pub async fn create_group( &self, name: &str, description: &str, parent: Option<i32>, ) -> Result<i32>
Create a new group, returning the group ID
sourcepub async fn list_sources(&self) -> Result<Vec<Source>>
pub async fn list_sources(&self) -> Result<Vec<Source>>
Get the complete list of sources
sourcepub async fn create_source(
&self,
name: &str,
description: Option<&str>,
url: Option<&str>,
date: DateTime<Local>,
releasable: bool,
malicious: Option<bool>,
) -> Result<i32>
pub async fn create_source( &self, name: &str, description: Option<&str>, url: Option<&str>, date: DateTime<Local>, releasable: bool, malicious: Option<bool>, ) -> Result<i32>
Create a source, returning the source ID
sourcepub async fn edit_user(
&self,
uid: i32,
uname: &str,
fname: &str,
lname: &str,
email: &str,
) -> Result<()>
pub async fn edit_user( &self, uid: i32, uname: &str, fname: &str, lname: &str, email: &str, ) -> Result<()>
Edit a user account setting the specified field values
sourcepub async fn deactivate_user(&self, uid: i32) -> Result<()>
pub async fn deactivate_user(&self, uid: i32) -> Result<()>
Deactivate, but don’t delete, a user’s account
sourcepub async fn file_types_counts(&self) -> Result<HashMap<String, u32>>
pub async fn file_types_counts(&self) -> Result<HashMap<String, u32>>
File types and number of files per type
sourcepub async fn create_label(&self, name: &str, parent: Option<i64>) -> Result<u64>
pub async fn create_label(&self, name: &str, parent: Option<i64>) -> Result<u64>
Create a new label
sourcepub async fn edit_label(
&self,
id: u64,
name: &str,
parent: Option<u64>,
) -> Result<()>
pub async fn edit_label( &self, id: u64, name: &str, parent: Option<u64>, ) -> Result<()>
Edit a label name or parent
sourcepub async fn label_id_from_name(&self, name: &str) -> Result<u64>
pub async fn label_id_from_name(&self, name: &str) -> Result<u64>
Return the ID for a given label name