use serde::{Deserialize, Serialize};
use super::{AccessorDetectionConfig, ConstructorDetectionConfig, DataFlowClassificationConfig};
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub struct CallerCalleeConfig {
#[serde(default = "default_max_callers")]
pub max_callers: usize,
#[serde(default = "default_max_callees")]
pub max_callees: usize,
#[serde(default = "default_show_external")]
pub show_external: bool,
#[serde(default = "default_show_std_lib")]
pub show_std_lib: bool,
}
impl Default for CallerCalleeConfig {
fn default() -> Self {
Self {
max_callers: default_max_callers(),
max_callees: default_max_callees(),
show_external: default_show_external(),
show_std_lib: default_show_std_lib(),
}
}
}
fn default_max_callers() -> usize {
5
}
fn default_max_callees() -> usize {
5
}
fn default_show_external() -> bool {
false
}
fn default_show_std_lib() -> bool {
false
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ContextConfig {
#[serde(default = "default_context_enabled")]
pub enabled: bool,
#[serde(default)]
pub rules: Vec<ContextRuleConfig>,
#[serde(default)]
pub function_patterns: Option<FunctionPatternConfig>,
}
impl Default for ContextConfig {
fn default() -> Self {
Self {
enabled: default_context_enabled(),
rules: Vec::new(),
function_patterns: None,
}
}
}
fn default_context_enabled() -> bool {
false }
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ContextRuleConfig {
pub name: String,
pub pattern: String,
pub context: ContextMatcherConfig,
pub action: String,
#[serde(default = "default_rule_priority")]
pub priority: i32,
pub reason: Option<String>,
}
fn default_rule_priority() -> i32 {
50
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ContextMatcherConfig {
pub role: Option<String>,
pub file_type: Option<String>,
pub is_async: Option<bool>,
pub framework_pattern: Option<String>,
pub name_pattern: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FunctionPatternConfig {
#[serde(default)]
pub test_patterns: Vec<String>,
#[serde(default)]
pub config_patterns: Vec<String>,
#[serde(default)]
pub handler_patterns: Vec<String>,
#[serde(default)]
pub init_patterns: Vec<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct ClassificationConfig {
#[serde(default)]
pub constructors: Option<ConstructorDetectionConfig>,
#[serde(default)]
pub accessors: Option<AccessorDetectionConfig>,
#[serde(default)]
pub data_flow: Option<DataFlowClassificationConfig>,
}