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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
//! Resolved run configuration (no config file; CLI flags and environment only).
use std::fmt;
use std::path::PathBuf;
use clap::ValueEnum;
use crate::constants::{
COLLECTION, DEFAULT_S3_PATH, NVD_API_URL, PDS_REQUESTS_PER_5MIN, PDS_WRITE_DAILY,
PDS_WRITE_HOURLY, RELEASE_RECHECK_SECONDS,
};
pub const DEFAULT_CACHE: &str = ".state/vuln-notif.db";
pub const DEFAULT_PURLDB: &str = ".state/purl2cpe.db";
pub const DEFAULT_PLC_URL: &str = "https://plc.directory";
pub const EXIT_OK: u8 = 0;
pub const EXIT_FATAL: u8 = 1;
pub const EXIT_USAGE: u8 = 2;
pub const EXIT_INTERRUPTED: u8 = 130;
/// Pending-row publish order (`cache` insert order, NVD lastModified, or reverse).
#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum, Default)]
pub enum Order {
#[default]
Cache,
Newest,
Oldest,
}
impl Order {
pub fn as_sql(self) -> &'static str {
match self {
Self::Cache => "c.updated_at, c.id",
Self::Newest => "c.last_modified DESC, c.id DESC",
Self::Oldest => "c.last_modified ASC, c.id ASC",
}
}
pub fn as_str(self) -> &'static str {
match self {
Self::Cache => "cache",
Self::Newest => "newest",
Self::Oldest => "oldest",
}
}
}
impl fmt::Display for Order {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str(self.as_str())
}
}
/// Release ingestion mode.
#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum, Default)]
pub enum ReleaseMode {
#[default]
Latest,
Affected,
History,
Extras,
All,
}
impl ReleaseMode {
pub fn as_str(self) -> &'static str {
match self {
Self::Latest => "latest",
Self::Affected => "affected",
Self::History => "history",
Self::Extras => "extras",
Self::All => "all",
}
}
}
impl fmt::Display for ReleaseMode {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str(self.as_str())
}
}
#[derive(Clone)]
pub struct S3Config {
pub bucket: String,
pub path: String,
pub endpoint_url: Option<String>,
pub access_key_id: Option<String>,
pub secret_access_key: Option<String>,
pub region: String,
}
impl fmt::Debug for S3Config {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter
.debug_struct("S3Config")
.field("bucket", &self.bucket)
.field("path", &self.path)
.field("endpoint_url", &self.endpoint_url)
.field("access_key_id", &self.access_key_id)
.field(
"secret_access_key",
&self.secret_access_key.as_ref().map(|_| "<redacted>"),
)
.field("region", &self.region)
.finish()
}
}
impl Default for S3Config {
fn default() -> Self {
Self {
bucket: String::new(),
path: DEFAULT_S3_PATH.to_owned(),
endpoint_url: None,
access_key_id: None,
secret_access_key: None,
region: "us-east-1".to_owned(),
}
}
}
/// Fully validated runtime configuration.
#[derive(Clone)]
pub struct RunConfig {
pub once: bool,
pub dry_run: bool,
pub limit: usize,
pub backfill: bool,
pub initial_lookback_days: i64,
pub order: Order,
pub publish_atproto: bool,
pub software_limit: usize,
pub publish_releases: bool,
pub release_mode: ReleaseMode,
pub release_limit: usize,
pub release_recheck_seconds: f64,
pub release_ecosystems: Vec<String>,
pub release_sources: Vec<String>,
pub release_history_limit: usize,
pub release_concurrency: usize,
/// Source base-URL override used by the local history e2e.
pub release_source_url: Option<String>,
/// Artifact byte cap; `0` means no cap.
pub artifact_max_bytes: u64,
/// Artifact mirror bucket; `None` leaves the no-op mirror.
pub artifact_s3: Option<S3Config>,
pub github_token: Option<String>,
pub gitlab_token: Option<String>,
pub gitee_token: Option<String>,
pub osv_online: bool,
pub osv_bulk_dir: Option<PathBuf>,
pub purldb: PathBuf,
pub cache_db: PathBuf,
pub poll_interval: f64,
pub page_size: usize,
pub concurrency: usize,
pub pds_timeout: f64,
pub nvd_api_key: Option<String>,
pub require_nvd_key: bool,
pub pds_hourly_points: f64,
pub pds_daily_points: f64,
pub pds_requests_per_5min: f64,
pub pds_url: Option<String>,
pub handle: Option<String>,
pub app_password: Option<String>,
pub collection: String,
pub s3: Option<S3Config>,
pub debug: bool,
pub nvd_url: String,
pub plc_url: String,
}
impl fmt::Debug for RunConfig {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter
.debug_struct("RunConfig")
.field("once", &self.once)
.field("dry_run", &self.dry_run)
.field("limit", &self.limit)
.field("backfill", &self.backfill)
.field("initial_lookback_days", &self.initial_lookback_days)
.field("order", &self.order)
.field("publish_atproto", &self.publish_atproto)
.field("software_limit", &self.software_limit)
.field("publish_releases", &self.publish_releases)
.field("release_mode", &self.release_mode)
.field("release_limit", &self.release_limit)
.field("release_recheck_seconds", &self.release_recheck_seconds)
.field("release_ecosystems", &self.release_ecosystems)
.field("release_sources", &self.release_sources)
.field("release_history_limit", &self.release_history_limit)
.field("release_concurrency", &self.release_concurrency)
.field("release_source_url", &self.release_source_url)
.field("artifact_max_bytes", &self.artifact_max_bytes)
.field("artifact_s3", &self.artifact_s3)
.field(
"github_token",
&self.github_token.as_ref().map(|_| "<redacted>"),
)
.field(
"gitlab_token",
&self.gitlab_token.as_ref().map(|_| "<redacted>"),
)
.field(
"gitee_token",
&self.gitee_token.as_ref().map(|_| "<redacted>"),
)
.field("osv_online", &self.osv_online)
.field("osv_bulk_dir", &self.osv_bulk_dir)
.field("purldb", &self.purldb)
.field("cache_db", &self.cache_db)
.field("poll_interval", &self.poll_interval)
.field("page_size", &self.page_size)
.field("concurrency", &self.concurrency)
.field("pds_timeout", &self.pds_timeout)
.field(
"nvd_api_key",
&self.nvd_api_key.as_ref().map(|_| "<redacted>"),
)
.field("require_nvd_key", &self.require_nvd_key)
.field("pds_hourly_points", &self.pds_hourly_points)
.field("pds_daily_points", &self.pds_daily_points)
.field("pds_requests_per_5min", &self.pds_requests_per_5min)
.field("pds_url", &self.pds_url)
.field("handle", &self.handle)
.field(
"app_password",
&self.app_password.as_ref().map(|_| "<redacted>"),
)
.field("collection", &self.collection)
.field("s3", &self.s3)
.field("debug", &self.debug)
.field("nvd_url", &self.nvd_url)
.field("plc_url", &self.plc_url)
.finish()
}
}
impl RunConfig {
pub fn nvd_url_default() -> &'static str {
NVD_API_URL
}
pub fn default_collection() -> &'static str {
COLLECTION
}
pub fn default_hourly_points() -> f64 {
PDS_WRITE_HOURLY
}
pub fn default_daily_points() -> f64 {
PDS_WRITE_DAILY
}
pub fn default_requests_per_5min() -> f64 {
PDS_REQUESTS_PER_5MIN
}
pub fn default_release_recheck_seconds() -> f64 {
RELEASE_RECHECK_SECONDS
}
}