-
Notifications
You must be signed in to change notification settings - Fork 253
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
Move find_blobs_by_tags
to pipeline
#826
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
161 changes: 161 additions & 0 deletions
161
sdk/storage/src/account/operations/find_blobs_by_tags.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
use crate::core::prelude::*; | ||
use crate::xml::read_xml; | ||
use azure_core::headers::{date_from_headers, request_id_from_headers}; | ||
use azure_core::prelude::*; | ||
use azure_core::{collect_pinned_stream, RequestId, Response as HttpResponse}; | ||
use chrono::{DateTime, Utc}; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct FindBlobsByTagsBuilder { | ||
client: StorageClient, | ||
expression: String, | ||
#[allow(unused)] | ||
next_marker: Option<NextMarker>, | ||
#[allow(unused)] | ||
max_results: Option<MaxResults>, | ||
timeout: Option<Timeout>, | ||
context: Context, | ||
} | ||
|
||
impl FindBlobsByTagsBuilder { | ||
pub(crate) fn new(client: StorageClient) -> Self { | ||
Self { | ||
client, | ||
expression: String::new(), | ||
next_marker: None, | ||
max_results: None, | ||
timeout: None, | ||
context: Context::new(), | ||
} | ||
} | ||
|
||
setters! { | ||
expression: String => expression, | ||
next_marker: NextMarker => Some(next_marker), | ||
max_results: MaxResults => Some(max_results), | ||
timeout: Timeout => Some(timeout), | ||
} | ||
|
||
// TODO: Make this a stream instead of a `Future` | ||
pub fn into_future(mut self) -> FindBlobsByTags { | ||
Box::pin(async move { | ||
let mut request = self | ||
.client | ||
.storage_account_client() | ||
.blob_storage_request(http::Method::GET); | ||
|
||
self.timeout.append_to_url_query(request.url_mut()); | ||
request | ||
.url_mut() | ||
.query_pairs_mut() | ||
.append_pair("comp", "blobs"); | ||
request | ||
.url_mut() | ||
.query_pairs_mut() | ||
.append_pair("where", &self.expression); | ||
|
||
let response = self | ||
.client | ||
.storage_account_client() | ||
.pipeline() | ||
.send(&mut self.context, &mut request) | ||
.await?; | ||
|
||
ListBlobsByTagsResponse::try_from(response).await | ||
}) | ||
} | ||
} | ||
|
||
/// The future returned by calling `into_future` on the builder. | ||
pub type FindBlobsByTags = | ||
futures::future::BoxFuture<'static, azure_core::error::Result<ListBlobsByTagsResponse>>; | ||
|
||
#[cfg(feature = "into_future")] | ||
impl std::future::IntoFuture for FindBlobsByTagsBuilder { | ||
type IntoFuture = FindBlobsByTags; | ||
type Output = <FindBlobsByTags as std::future::Future>::Output; | ||
fn into_future(self) -> Self::IntoFuture { | ||
Self::into_future(self) | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq)] | ||
pub struct ListBlobsByTagsResponse { | ||
pub max_results: Option<u32>, | ||
pub delimiter: Option<String>, | ||
pub next_marker: Option<NextMarker>, | ||
pub r#where: Option<String>, | ||
pub blobs: Blobs, | ||
pub request_id: RequestId, | ||
pub date: DateTime<Utc>, | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq, Deserialize)] | ||
#[serde(rename_all = "PascalCase")] | ||
struct ListBlobsByTagsResponseInternal { | ||
pub max_results: Option<u32>, | ||
pub delimiter: Option<String>, | ||
pub next_marker: Option<String>, | ||
pub r#where: Option<String>, | ||
pub blobs: Blobs, | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq, Deserialize)] | ||
#[serde(rename_all = "PascalCase")] | ||
pub struct Blobs { | ||
#[serde(rename = "Blob", default = "Vec::new")] | ||
pub blobs: Vec<Blob>, | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq, Deserialize)] | ||
#[serde(rename_all = "PascalCase")] | ||
pub struct Blob { | ||
pub name: String, | ||
pub container_name: String, | ||
pub tag_value: String, | ||
} | ||
|
||
impl ListBlobsByTagsResponse { | ||
async fn try_from(response: HttpResponse) -> azure_core::error::Result<Self> { | ||
let (_status_code, headers, pinned_stream) = response.deconstruct(); | ||
let body = collect_pinned_stream(pinned_stream).await?; | ||
let list_blobs_response_internal: ListBlobsByTagsResponseInternal = read_xml(&body)?; | ||
|
||
Ok(Self { | ||
request_id: request_id_from_headers(&headers)?, | ||
date: date_from_headers(&headers)?, | ||
max_results: list_blobs_response_internal.max_results, | ||
delimiter: list_blobs_response_internal.delimiter, | ||
r#where: list_blobs_response_internal.r#where, | ||
blobs: list_blobs_response_internal.blobs, | ||
next_marker: NextMarker::from_possibly_empty_string( | ||
list_blobs_response_internal.next_marker, | ||
), | ||
}) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn deserde_azure() { | ||
const S: &str = "<?xml version=\"1.0\" encoding=\"utf-8\"?> | ||
<EnumerationResults ServiceEndpoint=\"https://hsdgeventstoredev.blob.core.windows.net/\"> | ||
<Where>tag1='value1'</Where> | ||
<Blobs> | ||
<Blob> | ||
<Name>test1</Name> | ||
<ContainerName>container1</ContainerName> | ||
<TagValue>value1</TagValue> | ||
</Blob> | ||
</Blobs> | ||
<NextMarker/> | ||
</EnumerationResults>"; | ||
|
||
let bytes = bytes::Bytes::from(S); | ||
let _list_blobs_response_internal: ListBlobsByTagsResponseInternal = | ||
read_xml(&bytes).unwrap(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
mod find_blobs_by_tags; | ||
mod get_account_information; | ||
|
||
pub use find_blobs_by_tags::*; | ||
pub use get_account_information::*; |
This file was deleted.
Oops, something went wrong.
Empty file.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a handful of places we're not paging. It's probably worth opening work items for these.