Skip to content

Commit

Permalink
fix(connector): raise error if path not fully resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
jmfiaschi committed Feb 27, 2024
1 parent 1fc54de commit 9adeff8
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 21 deletions.
28 changes: 17 additions & 11 deletions src/connector/bucket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,10 @@ impl Connector for Bucket {
let path = self.path();

if path.has_mustache() {
warn!(path = path, "This path is not fully resolved");
return Err(Error::new(
ErrorKind::InvalidInput,
format!("This path '{}' is not fully resolved", path),
));
}

let get_object = self
Expand Down Expand Up @@ -528,14 +531,17 @@ impl Connector for Bucket {
dataset: &DataSet,
) -> std::io::Result<Option<DataStream>> {
let mut content_file = Vec::default();
let path_resolved = self.path();
let path = self.path();
let terminator = document.terminator()?;
let footer = document.footer(dataset)?;
let header = document.header(dataset)?;
let body = document.write(dataset)?;

if path_resolved.has_mustache() {
warn!(path = path_resolved, "This path is not fully resolved");
if path.has_mustache() {
return Err(Error::new(
ErrorKind::InvalidInput,
format!("This path '{}' is not fully resolved", path),
));
}

let position = match document.can_append() {
Expand All @@ -544,10 +550,7 @@ impl Connector for Bucket {
};

if !self.is_empty().await? {
info!(
path = path_resolved.to_string().as_str(),
"Fetch existing data"
);
info!(path = path.to_string().as_str(), "Fetch existing data");
{
let get_object = self
.client()
Expand Down Expand Up @@ -600,7 +603,7 @@ impl Connector for Bucket {
.await?
.put_object()
.bucket(&self.bucket)
.key(&path_resolved)
.key(&path)
.tagging(self.tagging())
.content_type(self.metadata().content_type())
.set_metadata(Some(
Expand All @@ -623,7 +626,7 @@ impl Connector for Bucket {
.await
.map_err(|e| Error::new(ErrorKind::Interrupted, e))?;

info!(path = path_resolved, "Send data with success");
info!(path = path, "Send data with success");
Ok(None)
}
fn set_metadata(&mut self, metadata: Metadata) {
Expand All @@ -639,7 +642,10 @@ impl Connector for Bucket {
let path = self.path();

if path.has_mustache() {
warn!(path = path, "This path is not fully resolved");
return Err(Error::new(
ErrorKind::InvalidInput,
format!("This path '{}' is not fully resolved", path),
));
}

self.client()
Expand Down
5 changes: 4 additions & 1 deletion src/connector/bucket_select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,10 @@ impl BucketSelect {
let path = self.path();

if path.has_mustache() {
warn!(path = path, "This path is not fully resolved");
return Err(Error::new(
ErrorKind::InvalidInput,
format!("This path '{}' is not fully resolved", path),
));
}

let input_serialization = match metadata.mime_subtype.as_deref() {
Expand Down
24 changes: 18 additions & 6 deletions src/connector/curl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,14 @@ use std::collections::hash_map::DefaultHasher;
use std::collections::HashMap;
use std::convert::TryInto;
use std::hash::{Hash, Hasher};
use std::io::Write;
use std::pin::Pin;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::OnceLock;
use std::time;
use std::time::Duration;
use std::{
fmt,
io::{Error, ErrorKind, Result},
io::{Error, ErrorKind, Result, Write},
};
use surf::middleware::{Middleware, Next};
use surf::{
Expand Down Expand Up @@ -451,7 +450,10 @@ impl Connector for Curl {
let path = self.path();

if path.has_mustache() {
warn!(path, "This path is not fully resolved");
return Err(Error::new(
ErrorKind::InvalidInput,
format!("This path '{}' is not fully resolved", path),
));
}

let url = Url::parse(format!("{}{}", self.endpoint, path).as_str())
Expand All @@ -462,8 +464,12 @@ impl Connector for Curl {
match self.method {
Method::Post | Method::Put | Method::Patch => {
let mut buffer = Vec::default();
let mut parameters_without_context = self.parameters_without_context()?;
parameters_without_context.replace_mustache(self.parameters.clone());

let dataset = vec![DataResult::Ok(self.parameters_without_context()?)];
let dataset = vec![DataResult::Ok(parameters_without_context)];
let mut document = document.clone_box();
document.set_entry_path(String::default());
buffer.write_all(&document.header(&dataset)?)?;
buffer.write_all(&document.write(&dataset)?)?;
buffer.write_all(&document.footer(&dataset)?)?;
Expand Down Expand Up @@ -584,7 +590,10 @@ impl Connector for Curl {
let path = self.path();

if path.has_mustache() {
warn!(path, "This path is not fully resolved");
return Err(Error::new(
ErrorKind::InvalidInput,
format!("This path '{}' is not fully resolved", path),
));
}

let url = Url::parse(format!("{}{}", self.endpoint, path).as_str())
Expand Down Expand Up @@ -696,7 +705,10 @@ impl Connector for Curl {
let path = self.path();

if path.has_mustache() {
warn!(path, "This path is not fully resolved");
return Err(Error::new(
ErrorKind::InvalidInput,
format!("This path '{}' is not fully resolved", path),
));
}

let url = Url::parse(format!("{}{}", self.endpoint, path).as_str())
Expand Down
15 changes: 12 additions & 3 deletions src/connector/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,10 @@ impl Connector for Local {
let algo_with_checksum_opt = self.algo_with_checksum.clone();

if path.has_mustache() {
warn!(path = path, "This path is not fully resolved");
return Err(Error::new(
ErrorKind::InvalidInput,
format!("This path '{}' is not fully resolved", path),
));
}

if self.is_cached {
Expand Down Expand Up @@ -445,7 +448,10 @@ impl Connector for Local {
let path = self.path();

if path.has_mustache() {
warn!(path = path, "This path is not fully resolved");
return Err(Error::new(
ErrorKind::InvalidInput,
format!("This path '{}' is not fully resolved", path),
));
}

let position = match document.can_append() {
Expand Down Expand Up @@ -538,7 +544,10 @@ impl Connector for Local {
let path = self.path();

if path.has_mustache() {
warn!(path = path, "This path is not fully resolved");
return Err(Error::new(
ErrorKind::InvalidInput,
format!("This path '{}' is not fully resolved", path),
));
}

let paths = glob(path.as_str()).map_err(|e| Error::new(ErrorKind::NotFound, e))?;
Expand Down

0 comments on commit 9adeff8

Please sign in to comment.