Skip to content

Commit

Permalink
Validate the regex pattern field of file system source (#722)
Browse files Browse the repository at this point in the history
  • Loading branch information
haoxins authored Aug 24, 2024
1 parent db6b99d commit b38f60d
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions crates/arroyo-connectors/src/filesystem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ mod source;

use anyhow::{anyhow, bail, Result};
use arroyo_storage::BackendConfig;
use regex::Regex;
use std::collections::HashMap;

use typify::import_types;
Expand Down Expand Up @@ -51,7 +52,7 @@ impl Connector for FileSystemConnector {
enabled: true,
source: true,
sink: true,
testing: false,
testing: true,
hidden: false,
custom_schemas: true,
connection_config: None,
Expand All @@ -63,15 +64,37 @@ impl Connector for FileSystemConnector {
&self,
_: &str,
_: Self::ProfileT,
_: Self::TableT,
table: Self::TableT,
_: Option<&ConnectionSchema>,
tx: tokio::sync::mpsc::Sender<TestSourceMessage>,
) {
let mut failed = false;
let mut message = "Successfully validated connection".to_string();
match table.table_type {
TableType::Source { regex_pattern, .. } => {
let r = regex_pattern
.as_ref()
.map(|pattern| Regex::new(pattern))
.transpose();
if let Err(e) = r {
failed = true;
message = format!(
"Invalid regex pattern: {}, {}",
regex_pattern.as_ref().unwrap(),
e
);
}
}
TableType::Sink { .. } => {
// TODO: implement sink testing
}
}

tokio::task::spawn(async move {
let message = TestSourceMessage {
error: false,
error: failed,
done: true,
message: "Successfully validated connection".to_string(),
message: message,
};
tx.send(message).await.unwrap();
});
Expand Down

0 comments on commit b38f60d

Please sign in to comment.