From 1bad83f7ab180d0526f47a18a7f52351c5095ca6 Mon Sep 17 00:00:00 2001 From: Remi Dettai Date: Thu, 5 Oct 2023 12:56:36 +0000 Subject: [PATCH] Fix the FileSourceParams deserialization to support URIs --- quickwit/quickwit-config/src/source_config/mod.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/quickwit/quickwit-config/src/source_config/mod.rs b/quickwit/quickwit-config/src/source_config/mod.rs index 1d4aedcbed6..895abf6c0b2 100644 --- a/quickwit/quickwit-config/src/source_config/mod.rs +++ b/quickwit/quickwit-config/src/source_config/mod.rs @@ -263,13 +263,16 @@ pub struct FileSourceParams { pub filepath: Option, //< 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, D::Error> where D: Deserializer<'de> { let filepath_opt: Option = 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) } @@ -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()) + ); } }