-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.rs
More file actions
160 lines (130 loc) · 3.81 KB
/
Copy pathconfig.rs
File metadata and controls
160 lines (130 loc) · 3.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
//! Configuration file parsing
//!
//! Reads pg-migration-lint.toml configuration files.
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum ConfigError {
#[error("IO error reading config file: {0}")]
Io(#[from] std::io::Error),
#[error("TOML parse error: {0}")]
Parse(#[from] toml::de::Error),
#[error("Invalid configuration: {0}")]
Validation(String),
}
/// Main configuration structure
#[derive(Debug, Clone, Default, Deserialize, Serialize)]
pub struct Config {
#[serde(default)]
pub migrations: MigrationsConfig,
#[serde(default)]
pub liquibase: LiquibaseConfig,
#[serde(default)]
pub output: OutputConfig,
#[serde(default)]
pub cli: CliConfig,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct MigrationsConfig {
/// Paths to migration directories or changelog files
#[serde(default)]
pub paths: Vec<PathBuf>,
/// Migration ordering strategy
#[serde(default = "default_strategy")]
pub strategy: String,
/// File patterns to include
#[serde(default = "default_include")]
pub include: Vec<String>,
/// File patterns to exclude
#[serde(default)]
pub exclude: Vec<String>,
}
impl Default for MigrationsConfig {
fn default() -> Self {
Self {
paths: vec![PathBuf::from("db/migrations")],
strategy: default_strategy(),
include: default_include(),
exclude: vec![],
}
}
}
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct LiquibaseConfig {
/// Path to liquibase-bridge.jar
pub bridge_jar_path: Option<PathBuf>,
/// Path to liquibase binary
pub binary_path: Option<PathBuf>,
/// Path to liquibase properties file (passed as --defaults-file to liquibase CLI)
pub properties_file: Option<PathBuf>,
/// Strategy: "auto", "bridge", "update-sql", "xml-fallback"
#[serde(default = "default_liquibase_strategy")]
pub strategy: String,
}
impl Default for LiquibaseConfig {
fn default() -> Self {
Self {
bridge_jar_path: Some(PathBuf::from("tools/liquibase-bridge.jar")),
binary_path: Some(PathBuf::from("liquibase")),
properties_file: None,
strategy: default_liquibase_strategy(),
}
}
}
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct OutputConfig {
/// Output formats: "sarif", "sonarqube", "text"
#[serde(default = "default_formats")]
pub formats: Vec<String>,
/// Output directory for report files
#[serde(default = "default_output_dir")]
pub dir: PathBuf,
}
impl Default for OutputConfig {
fn default() -> Self {
Self {
formats: default_formats(),
dir: default_output_dir(),
}
}
}
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct CliConfig {
/// Exit non-zero if findings meet or exceed this severity
#[serde(default = "default_fail_on")]
pub fail_on: String,
}
impl Default for CliConfig {
fn default() -> Self {
Self {
fail_on: default_fail_on(),
}
}
}
fn default_strategy() -> String {
"filename_lexicographic".to_string()
}
fn default_include() -> Vec<String> {
vec!["*.sql".to_string(), "*.xml".to_string()]
}
fn default_liquibase_strategy() -> String {
"auto".to_string()
}
fn default_formats() -> Vec<String> {
vec!["sarif".to_string()]
}
fn default_output_dir() -> PathBuf {
PathBuf::from("build/reports/migration-lint")
}
fn default_fail_on() -> String {
"critical".to_string()
}
impl Config {
/// Load configuration from a file
pub fn from_file(path: &PathBuf) -> Result<Self, ConfigError> {
let contents = std::fs::read_to_string(path)?;
let config: Config = toml::from_str(&contents)?;
Ok(config)
}
}