Skip to content

Commit

Permalink
Fix the FileSourceParams deserialization to support URIs
Browse files Browse the repository at this point in the history
  • Loading branch information
rdettai committed Oct 5, 2023
1 parent 7ddeb2a commit 1bad83f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions quickwit/quickwit-config/src/source_config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,16 @@ pub struct FileSourceParams {
pub filepath: Option<PathBuf>, //< If None read from stdin.
}

// Deserializing a filepath string into an absolute filepath.
/// Deserializing as an URI first to validate the input.
///
/// TODO: we might want to replace `PathBuf` with `Uri` directly in
/// `FileSourceParams`
fn absolute_filepath_from_str<'de, D>(deserializer: D) -> Result<Option<PathBuf>, D::Error>
where D: Deserializer<'de> {
let filepath_opt: Option<String> = Deserialize::deserialize(deserializer)?;
if let Some(filepath) = filepath_opt {
let uri = Uri::from_str(&filepath).map_err(D::Error::custom)?;
Ok(uri.filepath().map(|path| path.to_path_buf()))
Ok(Some(PathBuf::from(uri.as_str())))
} else {
Ok(None)
}
Expand Down Expand Up @@ -800,8 +803,8 @@ mod tests {
let uri = Uri::from_str("source-path.json").unwrap();
assert_eq!(
file_params.filepath.unwrap().as_path(),
uri.filepath().unwrap()
)
Path::new(uri.as_str())
);
}
}

Expand Down

0 comments on commit 1bad83f

Please sign in to comment.