Skip to content

Commit bd79c4c

Browse files
fix(ide): capture multiple segments on base64 query path arguments (#754)
The endpoints `can-onboard` and `rulesets` rely on having a path parameter which is a base64 string. The problem is that this string may have `/` chars, thus making rocket unable to map the route. The fix is matching against [multiple segments](https://rocket.rs/guide/v0.4/requests/#multiple-segments) IDE-4956
1 parent 5bebbb8 commit bd79c4c

File tree

1 file changed

+12
-8
lines changed
  • crates/bins/src/bin/datadog_static_analyzer_server/ide/configuration_file

1 file changed

+12
-8
lines changed

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::path::PathBuf;
2+
13
use super::error::ConfigFileError;
24
use super::models::{AddRuleSetsRequest, IgnoreRuleRequest};
35
use super::static_analysis_config_file::StaticAnalysisConfigFile;
@@ -43,17 +45,19 @@ pub fn post_rulesets(request: Json<AddRuleSetsRequest>) -> Result<String, Custom
4345
}
4446

4547
#[instrument()]
46-
#[rocket::get("/v1/config/rulesets/<content>")]
47-
pub fn get_rulesets(content: &str) -> Json<Vec<String>> {
48-
tracing::debug!(%content);
49-
Json(StaticAnalysisConfigFile::to_rulesets(content.to_string()))
48+
#[rocket::get("/v1/config/rulesets/<content..>")]
49+
pub fn get_rulesets(content: PathBuf) -> Json<Vec<String>> {
50+
let content_str = content.to_string_lossy().into_owned();
51+
tracing::debug!(%content_str);
52+
Json(StaticAnalysisConfigFile::to_rulesets(content_str))
5053
}
5154

5255
#[instrument()]
53-
#[rocket::get("/v1/config/can-onboard/<content>")]
54-
pub fn can_onboard(content: &str) -> Result<Json<bool>, Custom<ConfigFileError>> {
55-
tracing::debug!(%content);
56-
let config = StaticAnalysisConfigFile::try_from(content.to_string())
56+
#[rocket::get("/v1/config/can-onboard/<content..>")]
57+
pub fn can_onboard(content: PathBuf) -> Result<Json<bool>, Custom<ConfigFileError>> {
58+
let content_str = content.to_string_lossy().into_owned();
59+
tracing::debug!(%content_str);
60+
let config = StaticAnalysisConfigFile::try_from(content_str)
5761
.map_err(|e| Custom(Status::InternalServerError, e))?;
5862
let can_onboard = config.is_onboarding_allowed();
5963
Ok(Json(can_onboard))

0 commit comments

Comments
 (0)