Skip to content

Commit 4534d24

Browse files
committed
Rust: Rename "file_v2" to "file_v1" (Code Security v1.x)
1 parent b03d0e8 commit 4534d24

13 files changed

Lines changed: 69 additions & 69 deletions

File tree

crates/bins/src/bin/datadog-static-analyzer-git-hook.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use itertools::Itertools;
2626
use kernel::analysis::ddsa_lib::v8_platform::{initialize_v8, Initialized, V8Platform};
2727
use kernel::classifiers::ArtifactClassification;
2828
use kernel::config::common::{ConfigMethod, PathConfig};
29-
use kernel::config::file_v2;
29+
use kernel::config::file_v1;
3030
use kernel::constants::{CARGO_VERSION, VERSION};
3131
use kernel::model::common::OutputFormat::Json;
3232
use kernel::model::rule::{Rule, RuleResult};
@@ -257,7 +257,7 @@ fn main() -> Result<()> {
257257
let configuration_file_and_method = get_config(directory_to_analyze.as_str(), use_debug);
258258

259259
let (configuration_file, configuration_method): (
260-
Option<file_v2::ConfigFile>,
260+
Option<file_v1::ConfigFile>,
261261
Option<ConfigMethod>,
262262
) = match configuration_file_and_method {
263263
Ok(cfg) => match cfg {

crates/bins/src/bin/datadog-static-analyzer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use kernel::analysis::ddsa_lib::v8_platform::{initialize_v8, Initialized, V8Plat
3535
use kernel::analysis::generated_content::DEFAULT_IGNORED_GLOBS;
3636
use kernel::classifiers::ArtifactClassification;
3737
use kernel::config::common::{ConfigMethod, PathConfig};
38-
use kernel::config::file_v2;
38+
use kernel::config::file_v1;
3939
use kernel::constants::{CARGO_VERSION, VERSION};
4040
use kernel::model::common::OutputFormat;
4141
use kernel::model::rule::{Rule, RuleSeverity};
@@ -264,7 +264,7 @@ fn main() -> Result<()> {
264264
let configuration_file_and_method = get_config(directory_to_analyze.as_str(), use_debug);
265265

266266
let (configuration_file, configuration_method): (
267-
Option<file_v2::ConfigFile>,
267+
Option<file_v1::ConfigFile>,
268268
Option<ConfigMethod>,
269269
) = match configuration_file_and_method {
270270
Ok(cfg) => match cfg {

crates/bins/src/bin/datadog_static_analyzer_server/ide/configuration_file/static_analysis_config_file.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use kernel::config::common::{
77
WithVersion,
88
};
99
use kernel::config::file_legacy::config_file_to_yaml;
10-
use kernel::config::{file_legacy, file_v2};
10+
use kernel::config::{file_legacy, file_v1};
1111
use kernel::utils::decode_base64_string;
1212
use std::{borrow::Cow, fmt::Debug};
1313
use tracing::instrument;
@@ -16,7 +16,7 @@ const WILDCARD_IGNORE: &str = "**";
1616

1717
#[derive(Debug, Clone, PartialEq)]
1818
pub struct StaticAnalysisConfigFile {
19-
config_file: WithVersion<file_legacy::ConfigFile, file_v2::YamlConfigFile>,
19+
config_file: WithVersion<file_legacy::ConfigFile, file_v1::YamlConfigFile>,
2020
original_content: Option<String>,
2121
}
2222

@@ -58,7 +58,7 @@ impl TryFrom<String> for StaticAnalysisConfigFile {
5858
})?;
5959
let config_file = match parsed {
6060
WithVersion::Legacy(yaml) => WithVersion::Legacy(file_legacy::ConfigFile::from(yaml)),
61-
WithVersion::V2(yaml) => WithVersion::V2(yaml),
61+
WithVersion::CodeSecurity(yaml) => WithVersion::CodeSecurity(yaml),
6262
};
6363
Ok(Self {
6464
config_file,
@@ -172,7 +172,7 @@ impl StaticAnalysisConfigFile {
172172
);
173173
}
174174
}
175-
WithVersion::V2(config) => {
175+
WithVersion::CodeSecurity(config) => {
176176
// (All logic for this is translated from the Legacy match arm)
177177
let map = config.ruleset_configs.get_or_insert_default();
178178
let ruleset_config = map.0.entry(ruleset_name.to_string()).or_default();
@@ -247,7 +247,7 @@ impl StaticAnalysisConfigFile {
247247
}
248248
}
249249
}
250-
WithVersion::V2(config) => {
250+
WithVersion::CodeSecurity(config) => {
251251
if rulesets.is_empty() {
252252
return;
253253
}
@@ -293,7 +293,7 @@ impl StaticAnalysisConfigFile {
293293
};
294294
match parsed.config_file {
295295
WithVersion::Legacy(config) => config.rulesets.iter().map(|rs| rs.0.clone()).collect(),
296-
WithVersion::V2(config) => config.use_rulesets.clone().unwrap_or_default(),
296+
WithVersion::CodeSecurity(config) => config.use_rulesets.clone().unwrap_or_default(),
297297
}
298298
}
299299

@@ -303,7 +303,7 @@ impl StaticAnalysisConfigFile {
303303
WithVersion::Legacy(config) => {
304304
config.paths.only.is_none() && config.paths.ignore.is_empty()
305305
}
306-
WithVersion::V2(config) => {
306+
WithVersion::CodeSecurity(config) => {
307307
config.global_config.is_none()
308308
|| config.global_config.as_ref().is_some_and(|c| {
309309
c.path_config.ignore_paths.is_none() && c.path_config.only_paths.is_none()
@@ -338,7 +338,7 @@ impl StaticAnalysisConfigFile {
338338
})
339339
.join("\n")
340340
}
341-
WithVersion::V2(config) => serde_yaml::to_string(&config)?,
341+
WithVersion::CodeSecurity(config) => serde_yaml::to_string(&config)?,
342342
};
343343
// reconcile and format
344344
// NOTE: if this fails, we're going to return the content

crates/cli/src/config_file.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::datadog_utils::{
66
use crate::git_utils::get_repository_url;
77
use anyhow::{anyhow, Context};
88
use kernel::config::common::{parse_any_schema_yaml, ConfigMethod, WithVersion};
9-
use kernel::config::file_v2;
9+
use kernel::config::file_v1;
1010
use kernel::utils::{decode_base64_string, encode_base64_string};
1111
use std::path::Path;
1212

@@ -47,15 +47,15 @@ pub fn read_config_file(base_path: &str) -> anyhow::Result<Option<String>> {
4747
pub fn get_config(
4848
path: &str,
4949
debug: bool,
50-
) -> anyhow::Result<Option<(file_v2::ConfigFile, ConfigMethod)>> {
50+
) -> anyhow::Result<Option<(file_v1::ConfigFile, ConfigMethod)>> {
5151
let local_file_contents = read_config_file(path)?;
5252
let local_yaml = local_file_contents
5353
.as_ref()
5454
.map(|c| parse_any_schema_yaml(c))
5555
.transpose()?;
56-
let local_config: Option<file_v2::ConfigFile> = local_yaml.map(|v| match v {
57-
WithVersion::Legacy(legacy) => file_v2::YamlConfigFile::from(legacy).into(),
58-
WithVersion::V2(v2) => v2.into(),
56+
let local_config: Option<file_v1::ConfigFile> = local_yaml.map(|v| match v {
57+
WithVersion::Legacy(legacy) => file_v1::YamlConfigFile::from(legacy).into(),
58+
WithVersion::CodeSecurity(v2) => v2.into(),
5959
});
6060

6161
if !should_use_datadog_backend() {
@@ -104,9 +104,9 @@ pub fn get_config(
104104
let Ok(remote_yaml) = res else {
105105
return Ok(local_config.map(|c| (c, ConfigMethod::File)));
106106
};
107-
let remote_config: file_v2::ConfigFile = match remote_yaml {
108-
WithVersion::Legacy(legacy) => file_v2::YamlConfigFile::from(legacy).into(),
109-
WithVersion::V2(v2) => v2.into(),
107+
let remote_config: file_v1::ConfigFile = match remote_yaml {
108+
WithVersion::Legacy(legacy) => file_v1::YamlConfigFile::from(legacy).into(),
109+
WithVersion::CodeSecurity(v2) => v2.into(),
110110
};
111111

112112
let config_method = if local_config.is_some() {

crates/static-analysis-kernel/src/analysis/analyze.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ mod tests {
397397
use crate::analysis::ddsa_lib::test_utils::cfg_test_v8;
398398
use crate::analysis::tree_sitter::get_query;
399399
use crate::config::common::{parse_any_schema_yaml, WithVersion};
400-
use crate::config::file_v2;
400+
use crate::config::file_v1;
401401
use crate::model::common::Language;
402402
use crate::model::rule::{RuleCategory, RuleSeverity};
403403
use crate::rule_config::RuleConfigProvider;
@@ -1170,7 +1170,7 @@ function visit(node, filename, code) {
11701170
tree_sitter_query: get_query(QUERY_CODE, &Language::Python).unwrap(),
11711171
};
11721172

1173-
let local_config: file_v2::ConfigFile = parse_any_schema_yaml(
1173+
let local_config: file_v1::ConfigFile = parse_any_schema_yaml(
11741174
// language=yaml
11751175
r#"
11761176
rulesets:
@@ -1183,8 +1183,8 @@ rulesets:
11831183
"#,
11841184
)
11851185
.map(|v| match v {
1186-
WithVersion::Legacy(legacy) => file_v2::YamlConfigFile::from(legacy).into(),
1187-
WithVersion::V2(v2) => v2.into(),
1186+
WithVersion::Legacy(legacy) => file_v1::YamlConfigFile::from(legacy).into(),
1187+
WithVersion::CodeSecurity(v2) => v2.into(),
11881188
})
11891189
.unwrap();
11901190

@@ -1298,7 +1298,7 @@ function visit(node, filename, code) {
12981298
timeout: None,
12991299
};
13001300

1301-
let local_config: file_v2::ConfigFile = parse_any_schema_yaml(
1301+
let local_config: file_v1::ConfigFile = parse_any_schema_yaml(
13021302
// language=yaml
13031303
r#"
13041304
rulesets:
@@ -1314,8 +1314,8 @@ rulesets:
13141314
"#,
13151315
)
13161316
.map(|v| match v {
1317-
WithVersion::Legacy(legacy) => file_v2::YamlConfigFile::from(legacy).into(),
1318-
WithVersion::V2(v2) => v2.into(),
1317+
WithVersion::Legacy(legacy) => file_v1::YamlConfigFile::from(legacy).into(),
1318+
WithVersion::CodeSecurity(v2) => v2.into(),
13191319
})
13201320
.unwrap();
13211321

crates/static-analysis-kernel/src/arguments.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::config::common::{BySubtree, SplitPath};
2-
use crate::config::file_v2;
2+
use crate::config::file_v1;
33
use common::model::diff_aware::DiffAware;
44
use std::collections::HashMap;
55

@@ -50,7 +50,7 @@ impl ArgumentProvider {
5050
}
5151
}
5252

53-
pub fn from(config: &file_v2::ConfigFile) -> Self {
53+
pub fn from(config: &file_v1::ConfigFile) -> Self {
5454
let mut provider = ArgumentProvider::new();
5555
if let Some(rulesets) = &config.ruleset_configs {
5656
for (ruleset_name, ruleset_cfg) in rulesets {

crates/static-analysis-kernel/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
pub mod common;
66
mod conversion;
77
pub mod file_legacy;
8-
pub mod file_v2;
8+
pub mod file_v1;

crates/static-analysis-kernel/src/config/common.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// This product includes software developed at Datadog (https://www.datadoghq.com/).
33
// Copyright 2026 Datadog, Inc.
44

5-
use crate::config::{file_legacy, file_v2};
5+
use crate::config::{file_legacy, file_v1};
66
use crate::model::rule::{RuleCategory, RuleSeverity};
77
use common::model::diff_aware::DiffAware;
88
use globset::{GlobBuilder, GlobMatcher};
@@ -282,15 +282,15 @@ pub enum ConfigError {
282282
/// from. (This info is preserved for backwards compatibility so that legacy schemas can be output
283283
/// by the datadog-static-analyzer-server.
284284
#[derive(Debug, Clone, Eq, PartialEq)]
285-
pub enum WithVersion<L, V2> {
285+
pub enum WithVersion<L, CS> {
286286
Legacy(L),
287-
V2(V2),
287+
CodeSecurity(CS),
288288
}
289289

290290
/// Parses a YAML configuration for any schema.
291291
pub fn parse_any_schema_yaml(
292292
config_contents: &str,
293-
) -> Result<WithVersion<file_legacy::YamlConfigFile, file_v2::YamlConfigFile>, ConfigError> {
293+
) -> Result<WithVersion<file_legacy::YamlConfigFile, file_v1::YamlConfigFile>, ConfigError> {
294294
#[derive(Debug, serde::Deserialize)]
295295
#[serde(rename_all = "kebab-case")]
296296
struct Version {
@@ -303,12 +303,12 @@ pub fn parse_any_schema_yaml(
303303
YamlSchemaVersion::Legacy => file_legacy::parse_yaml(config_contents)
304304
.map(WithVersion::Legacy)
305305
.map_err(ConfigError::Parse),
306-
YamlSchemaVersion::V2 => file_v2::parse_yaml(config_contents)
307-
.map(WithVersion::V2)
306+
YamlSchemaVersion::V2 => file_v1::parse_yaml(config_contents)
307+
.map(WithVersion::CodeSecurity)
308308
.map_err(|err| match err {
309-
file_v2::ParseError::Parse(inner) => ConfigError::Parse(inner),
309+
file_v1::ParseError::Parse(inner) => ConfigError::Parse(inner),
310310
// Match arm is `YamlSchemaVersion::V2`, so this is impossible.
311-
file_v2::ParseError::WrongSchema(_) => unreachable!(),
311+
file_v1::ParseError::WrongSchema(_) => unreachable!(),
312312
}),
313313
YamlSchemaVersion::Invalid(content) => Err(ConfigError::UnsupportedSchema(content)),
314314
}
@@ -355,7 +355,7 @@ use-rulesets:
355355
let parsed = parse_any_schema_yaml(config_contents).unwrap();
356356
match expected_variant {
357357
"v1" => assert!(matches!(parsed, WithVersion::Legacy(_))),
358-
"v2" => assert!(matches!(parsed, WithVersion::V2(_))),
358+
"v2" => assert!(matches!(parsed, WithVersion::CodeSecurity(_))),
359359
// (If this triggers, you need to add a match arm from a &str to the new version, e.g "v2.1" to WithVersion::V2_1)
360360
_ => panic!("broken test setup: unknown schema `{expected_variant}`"),
361361
}

0 commit comments

Comments
 (0)