Skip to content

Commit be42306

Browse files
committed
Revert "Temporary: artificially disable v2 config parsing in all binaries (but not within unit tests)"
This reverts commit f95139e.
1 parent 5d22012 commit be42306

4 files changed

Lines changed: 7 additions & 55 deletions

File tree

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use super::error::ConfigFileError;
33
use indexmap::IndexMap;
44
use itertools::Itertools;
55
use kernel::config::common::{
6-
parse_any_schema_yaml, parse_only_v1_yaml, ConfigError, PathConfig, PathPattern, RuleConfig,
7-
RulesetConfig, WithVersion,
6+
parse_any_schema_yaml, ConfigError, PathConfig, PathPattern, RuleConfig, RulesetConfig,
7+
WithVersion,
88
};
99
use kernel::config::file_v1::config_file_to_yaml;
1010
use kernel::config::{file_v1, file_v2};
@@ -47,12 +47,7 @@ impl TryFrom<String> for StaticAnalysisConfigFile {
4747
if content.trim().is_empty() {
4848
return Ok(Self::default());
4949
}
50-
let parsed = if cfg!(test) {
51-
parse_any_schema_yaml(&content)
52-
} else {
53-
parse_only_v1_yaml(&content)
54-
};
55-
let parsed = parsed.map_err(|err| {
50+
let parsed = parse_any_schema_yaml(&content).map_err(|err| {
5651
match err {
5752
// Artificially represent this as a "parse" error for backwards compatibility.
5853
ConfigError::UnsupportedSchema(_) => ConfigFileError::Parser {

crates/cli/src/config_file.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ use crate::datadog_utils::{
55
};
66
use crate::git_utils::get_repository_url;
77
use anyhow::{anyhow, Context};
8-
use kernel::config::common::{
9-
parse_any_schema_yaml, parse_only_v1_yaml, ConfigMethod, WithVersion,
10-
};
8+
use kernel::config::common::{parse_any_schema_yaml, ConfigMethod, WithVersion};
119
use kernel::config::file_v2;
1210
use kernel::utils::{decode_base64_string, encode_base64_string};
1311
use std::path::Path;
@@ -53,13 +51,7 @@ pub fn get_config(
5351
let local_file_contents = read_config_file(path)?;
5452
let local_yaml = local_file_contents
5553
.as_ref()
56-
.map(|c| {
57-
if cfg!(test) {
58-
parse_any_schema_yaml(c)
59-
} else {
60-
parse_only_v1_yaml(c)
61-
}
62-
})
54+
.map(|c| parse_any_schema_yaml(c))
6355
.transpose()?;
6456
let local_config: Option<file_v2::ConfigFile> = local_yaml.map(|v| match v {
6557
WithVersion::V1(v1) => file_v2::YamlConfigFile::from(v1).into(),

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

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -314,19 +314,6 @@ pub fn parse_any_schema_yaml(
314314
}
315315
}
316316

317-
/// Like [`parse_any_schema_yaml`], except only ever returns a [`WithVersion::V1`].
318-
///
319-
/// # Note
320-
/// This is a temporary function used to artificially disable v2 support within the static analyzer.
321-
/// When the Datadog backend implements v2 support, this will be removed.
322-
pub fn parse_only_v1_yaml(
323-
config_contents: &str,
324-
) -> Result<WithVersion<file_v1::YamlConfigFile, file_v2::YamlConfigFile>, ConfigError> {
325-
file_v1::parse_yaml(config_contents)
326-
.map(WithVersion::V1)
327-
.map_err(ConfigError::Parse)
328-
}
329-
330317
#[cfg(test)]
331318
mod tests {
332319
use super::*;
@@ -404,21 +391,4 @@ schema-version: v2
404391
));
405392
}
406393
}
407-
408-
/// See [`parse_only_v1_yaml`] for documentation.
409-
#[test]
410-
fn parse_v1_yaml_v1_only() {
411-
// language=yaml
412-
let v1 = "\
413-
schema-version: v1
414-
rulesets:
415-
- java-security
416-
";
417-
// language=yaml
418-
let v2 = "\
419-
schema-version: v2
420-
";
421-
assert!(matches!(parse_only_v1_yaml(v2), Err(ConfigError::Parse(_))));
422-
assert!(matches!(parse_only_v1_yaml(v1), Ok(WithVersion::V1(_))));
423-
}
424394
}

crates/static-analysis-server/src/request.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::model::violation::ServerViolation;
88
use common::analysis_options::AnalysisOptions;
99
use kernel::analysis::analyze::analyze_with;
1010
use kernel::analysis::ddsa_lib::JsRuntime;
11-
use kernel::config::common::{parse_any_schema_yaml, parse_only_v1_yaml, WithVersion};
11+
use kernel::config::common::{parse_any_schema_yaml, WithVersion};
1212
use kernel::config::file_v2;
1313
use kernel::model::rule::RuleInternal;
1414
use kernel::rule_config::RuleConfigProvider;
@@ -29,12 +29,7 @@ pub fn process_analysis_request<T: Borrow<RuleInternal>>(
2929
let configuration = if let Some(config_b64) = request.configuration_base64 {
3030
let config =
3131
decode_base64_string(config_b64).map_err(|_| ERROR_CONFIGURATION_NOT_BASE64)?;
32-
let parsed = if cfg!(test) {
33-
parse_any_schema_yaml(&config)
34-
} else {
35-
parse_only_v1_yaml(&config)
36-
};
37-
let v2_yaml = parsed
32+
let v2_yaml = parse_any_schema_yaml(&config)
3833
.map(|v| match v {
3934
WithVersion::V1(yaml) => file_v2::YamlConfigFile::from(yaml),
4035
WithVersion::V2(yaml) => yaml,

0 commit comments

Comments
 (0)