-
Notifications
You must be signed in to change notification settings - Fork 283
Create ListDatabases resource #335
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
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,127 @@ | ||
use crate::headers::from_headers::*; | ||
use crate::prelude::*; | ||
use crate::resources::Database; | ||
use crate::ResourceQuota; | ||
|
||
use azure_core::headers::{continuation_token_from_headers_optional, session_token_from_headers}; | ||
use azure_core::{collect_pinned_stream, prelude::*, Request, Response}; | ||
use chrono::{DateTime, Utc}; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct ListDatabasesOptions { | ||
consistency_level: Option<ConsistencyLevel>, | ||
max_item_count: MaxItemCount, | ||
} | ||
|
||
impl ListDatabasesOptions { | ||
pub fn new() -> Self { | ||
Self { | ||
consistency_level: None, | ||
max_item_count: MaxItemCount::new(-1), | ||
} | ||
} | ||
|
||
setters! { | ||
consistency_level: ConsistencyLevel => Some(consistency_level), | ||
max_item_count: i32 => MaxItemCount::new(max_item_count), | ||
} | ||
|
||
pub async fn decorate_request(&self, request: &mut Request) -> Result<(), crate::Error> { | ||
azure_core::headers::add_optional_header2(&self.consistency_level, request)?; | ||
azure_core::headers::add_mandatory_header2(&self.max_item_count, request)?; | ||
Ok(()) | ||
} | ||
|
||
// pub fn stream(&self) -> impl Stream<Item = Result<ListDatabasesResponse, crate::Error>> + '_ { | ||
// #[derive(Debug, Clone, PartialEq)] | ||
// enum States { | ||
// Init, | ||
// Continuation(String), | ||
// } | ||
|
||
// unfold( | ||
// Some(States::Init), | ||
// move |continuation_token: Option<States>| { | ||
// async move { | ||
// debug!("continuation_token == {:?}", &continuation_token); | ||
// let response = match continuation_token { | ||
// Some(States::Init) => self.decorate_request().await, | ||
// Some(States::Continuation(continuation_token)) => { | ||
// self.clone() | ||
// .continuation(continuation_token.as_str()) | ||
// .decorate_request() | ||
// .await | ||
// } | ||
// None => return None, | ||
// }; | ||
|
||
// // the ? operator does not work in async move (yet?) | ||
// // so we have to resort to this boilerplate | ||
// let response = match response { | ||
// Ok(response) => response, | ||
// Err(err) => return Some((Err(err), None)), | ||
// }; | ||
|
||
// let continuation_token = response | ||
// .continuation_token | ||
// .as_ref() | ||
// .map(|ct| States::Continuation(ct.to_owned())); | ||
|
||
// Some((Ok(response), continuation_token)) | ||
// } | ||
// }, | ||
// ) | ||
// } | ||
} | ||
|
||
#[derive(Clone, PartialEq, PartialOrd, Debug)] | ||
pub struct ListDatabasesResponse { | ||
pub rid: String, | ||
pub databases: Vec<Database>, | ||
pub count: u32, | ||
pub activity_id: uuid::Uuid, | ||
pub charge: f64, | ||
pub session_token: String, | ||
pub last_state_change: DateTime<Utc>, | ||
pub resource_quota: Vec<ResourceQuota>, | ||
pub resource_usage: Vec<ResourceQuota>, | ||
pub schema_version: String, | ||
pub service_version: String, | ||
pub continuation_token: Option<String>, | ||
pub gateway_version: String, | ||
} | ||
|
||
impl ListDatabasesResponse { | ||
pub(crate) async fn try_from(response: Response) -> Result<Self, crate::Error> { | ||
let (_status_code, headers, pinned_stream) = response.deconstruct(); | ||
let body = collect_pinned_stream(pinned_stream).await?; | ||
|
||
#[derive(Deserialize, Debug)] | ||
pub struct Response { | ||
#[serde(rename = "_rid")] | ||
rid: String, | ||
#[serde(rename = "Databases")] | ||
pub databases: Vec<Database>, | ||
#[serde(rename = "_count")] | ||
pub count: u32, | ||
} | ||
|
||
let response: Response = serde_json::from_slice(&body)?; | ||
|
||
Ok(Self { | ||
rid: response.rid, | ||
databases: response.databases, | ||
count: response.count, | ||
charge: request_charge_from_headers(&headers)?, | ||
activity_id: activity_id_from_headers(&headers)?, | ||
session_token: session_token_from_headers(&headers)?, | ||
last_state_change: last_state_change_from_headers(&headers)?, | ||
resource_quota: resource_quota_from_headers(&headers)?, | ||
resource_usage: resource_usage_from_headers(&headers)?, | ||
schema_version: schema_version_from_headers(&headers)?.to_owned(), | ||
service_version: service_version_from_headers(&headers)?.to_owned(), | ||
continuation_token: continuation_token_from_headers_optional(&headers)?, | ||
gateway_version: gateway_version_from_headers(&headers)?.to_owned(), | ||
}) | ||
} | ||
} |
This file contains hidden or 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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
Oops, something went wrong.
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.
We'll have to figure out what our interface for kicking off an async iterator response will be.
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.
💯 yess, will do as a follow-up!