-
Notifications
You must be signed in to change notification settings - Fork 89
Add option to Azure client to ignore unparsable paths #376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 10 commits
e2e987d
f04e0df
acc8204
c703ef1
1b5b5cf
81ba180
146af11
8fdeda9
5bb9097
429ae6b
fa05a87
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -172,6 +172,7 @@ pub(crate) struct AzureConfig { | |
pub skip_signature: bool, | ||
pub disable_tagging: bool, | ||
pub client_options: ClientOptions, | ||
pub ignore_unparsable_paths: bool, | ||
} | ||
|
||
impl AzureConfig { | ||
|
@@ -1021,7 +1022,7 @@ impl ListClient for Arc<AzureClient> { | |
let token = response.next_marker.take().filter(|x| !x.is_empty()); | ||
|
||
Ok(PaginatedListResult { | ||
result: to_list_result(response, prefix)?, | ||
result: to_list_result(response, prefix, self.config.ignore_unparsable_paths)?, | ||
page_token: token, | ||
}) | ||
} | ||
|
@@ -1038,7 +1039,11 @@ struct ListResultInternal { | |
pub blobs: Blobs, | ||
} | ||
|
||
fn to_list_result(value: ListResultInternal, prefix: Option<&str>) -> Result<ListResult> { | ||
fn to_list_result( | ||
value: ListResultInternal, | ||
prefix: Option<&str>, | ||
ignore_unparsable_paths: bool, | ||
) -> Result<ListResult> { | ||
let prefix = prefix.unwrap_or_default(); | ||
let common_prefixes = value | ||
.blobs | ||
|
@@ -1058,6 +1063,12 @@ fn to_list_result(value: ListResultInternal, prefix: Option<&str>) -> Result<Lis | |
!matches!(blob.properties.resource_type.as_ref(), Some(typ) if typ == "directory") | ||
&& blob.name.len() > prefix.len() | ||
}) | ||
.map(BlobInternal::try_from) | ||
.filter_map(|parsed| match parsed { | ||
Ok(parsed) => Some(parsed), | ||
Err(_) if ignore_unparsable_paths => None, | ||
Err(e) => panic!("cannot parse path: {e}"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I read @kylebarron's 👍 on #376 (comment) as "current behavior is there's an error, NOT a panic". So I think the flag should ignore the error, but even if the flag isn't set, you MUST NOT panic. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh sorry I was just agreeing with you that it's a good question 😅. I don't recall what the current behavior is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In #376 (comment) @ttomasz said returning an error might require a breaking change, though now that we've released 0.12.2 we can now merge breaking changes, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
right 👍 |
||
}) | ||
.map(ObjectMeta::try_from) | ||
.collect::<Result<_>>()?; | ||
|
||
|
@@ -1096,15 +1107,31 @@ struct Blob { | |
pub metadata: Option<HashMap<String, String>>, | ||
} | ||
|
||
impl TryFrom<Blob> for ObjectMeta { | ||
struct BlobInternal { | ||
pub blob: Blob, | ||
pub path: Path, | ||
} | ||
|
||
impl TryFrom<Blob> for BlobInternal { | ||
type Error = crate::path::Error; | ||
|
||
fn try_from(value: Blob) -> Result<Self, crate::path::Error> { | ||
Ok(Self { | ||
path: Path::parse(&value.name)?, | ||
blob: value, | ||
}) | ||
} | ||
} | ||
|
||
impl TryFrom<BlobInternal> for ObjectMeta { | ||
type Error = crate::Error; | ||
|
||
fn try_from(value: Blob) -> Result<Self> { | ||
fn try_from(value: BlobInternal) -> Result<Self> { | ||
Ok(Self { | ||
location: Path::parse(value.name)?, | ||
last_modified: value.properties.last_modified, | ||
size: value.properties.content_length, | ||
e_tag: value.properties.e_tag, | ||
location: value.path, | ||
last_modified: value.blob.properties.last_modified, | ||
size: value.blob.properties.content_length, | ||
e_tag: value.blob.properties.e_tag, | ||
version: None, // For consistency with S3 and GCP which don't include this | ||
}) | ||
} | ||
|
@@ -1403,6 +1430,7 @@ mod tests { | |
skip_signature: false, | ||
disable_tagging: false, | ||
client_options: Default::default(), | ||
ignore_unparsable_paths: Default::default(), | ||
}; | ||
|
||
let client = AzureClient::new(config, HttpClient::new(Client::new())); | ||
|
@@ -1540,4 +1568,135 @@ Time:2018-06-14T16:46:54.6040685Z</Message></Error>\r | |
assert_eq!("404", code); | ||
assert_eq!("The specified blob does not exist.", reason); | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_list_blobs() { | ||
let fake_properties = BlobProperties { | ||
last_modified: Utc::now(), | ||
content_length: 8, | ||
content_type: "text/plain".to_string(), | ||
content_encoding: None, | ||
content_language: None, | ||
e_tag: Some("etag".to_string()), | ||
resource_type: Some("resource".to_string()), | ||
}; | ||
let fake_result = ListResultInternal { | ||
prefix: None, | ||
max_results: None, | ||
delimiter: None, | ||
next_marker: None, | ||
blobs: Blobs { | ||
blob_prefix: vec![], | ||
blobs: vec![ | ||
Blob { | ||
name: "blob0.txt".to_string(), | ||
version_id: None, | ||
is_current_version: None, | ||
deleted: None, | ||
properties: fake_properties.clone(), | ||
metadata: None, | ||
}, | ||
Blob { | ||
name: "blob1.txt".to_string(), | ||
version_id: None, | ||
is_current_version: None, | ||
deleted: None, | ||
properties: fake_properties.clone(), | ||
metadata: None, | ||
}, | ||
], | ||
}, | ||
}; | ||
let result = to_list_result(fake_result, None, false).unwrap(); | ||
assert_eq!(result.common_prefixes.len(), 0); | ||
assert_eq!(result.objects.len(), 2); | ||
assert_eq!(result.objects[0].location, Path::from("blob0.txt")); | ||
assert_eq!(result.objects[1].location, Path::from("blob1.txt")); | ||
} | ||
|
||
#[tokio::test] | ||
#[should_panic(expected = "cannot parse path: Path \"foo//blob1.txt\" contained empty path segment")] | ||
async fn test_list_blobs_invalid_paths() { | ||
let fake_properties = BlobProperties { | ||
last_modified: Utc::now(), | ||
content_length: 8, | ||
content_type: "text/plain".to_string(), | ||
content_encoding: None, | ||
content_language: None, | ||
e_tag: Some("etag".to_string()), | ||
resource_type: Some("resource".to_string()), | ||
}; | ||
let fake_result = ListResultInternal { | ||
prefix: None, | ||
max_results: None, | ||
delimiter: None, | ||
next_marker: None, | ||
blobs: Blobs { | ||
blob_prefix: vec![], | ||
blobs: vec![ | ||
Blob { | ||
name: "foo/blob0.txt".to_string(), | ||
version_id: None, | ||
is_current_version: None, | ||
deleted: None, | ||
properties: fake_properties.clone(), | ||
metadata: None, | ||
}, | ||
Blob { | ||
name: "foo//blob1.txt".to_string(), | ||
version_id: None, | ||
is_current_version: None, | ||
deleted: None, | ||
properties: fake_properties.clone(), | ||
metadata: None, | ||
}, | ||
], | ||
}, | ||
}; | ||
to_list_result(fake_result, None, false).unwrap(); | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_list_blobs_ignore_invalid_paths() { | ||
let fake_properties = BlobProperties { | ||
last_modified: Utc::now(), | ||
content_length: 8, | ||
content_type: "text/plain".to_string(), | ||
content_encoding: None, | ||
content_language: None, | ||
e_tag: Some("etag".to_string()), | ||
resource_type: Some("resource".to_string()), | ||
}; | ||
let fake_result = ListResultInternal { | ||
prefix: None, | ||
max_results: None, | ||
delimiter: None, | ||
next_marker: None, | ||
blobs: Blobs { | ||
blob_prefix: vec![], | ||
blobs: vec![ | ||
Blob { | ||
name: "foo/blob0.txt".to_string(), | ||
version_id: None, | ||
is_current_version: None, | ||
deleted: None, | ||
properties: fake_properties.clone(), | ||
metadata: None, | ||
}, | ||
Blob { | ||
name: "foo//blob1.txt".to_string(), | ||
version_id: None, | ||
is_current_version: None, | ||
deleted: None, | ||
properties: fake_properties.clone(), | ||
metadata: None, | ||
}, | ||
], | ||
}, | ||
}; | ||
let result = to_list_result(fake_result, None, true).unwrap(); | ||
assert_eq!(result.common_prefixes.len(), 0); | ||
assert_eq!(result.objects.len(), 1); | ||
assert_eq!(result.objects[0].location, Path::from("foo/blob0.txt")); | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.