From ec50e53383a3d782d4fed07907d8e6636e446ac9 Mon Sep 17 00:00:00 2001 From: Cameron Taggart Date: Tue, 16 Nov 2021 00:10:44 -0600 Subject: [PATCH 01/10] plan using into_future for services --- services/mgmt/vmware/Cargo.toml | 3 +- .../vmware/examples/private_cloud_list.rs | 24 ++-- services/mgmt/vmware/src/lib.rs | 2 +- .../src/package_2021_12_01/operations.rs | 132 +++++++++++++----- 4 files changed, 114 insertions(+), 47 deletions(-) diff --git a/services/mgmt/vmware/Cargo.toml b/services/mgmt/vmware/Cargo.toml index 0aa3058f44..68a1cf302f 100644 --- a/services/mgmt/vmware/Cargo.toml +++ b/services/mgmt/vmware/Cargo.toml @@ -8,11 +8,12 @@ edition = "2018" azure_core = { path = "../../../sdk/core", version = "0.1.0" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" -reqwest = { version = "0.11", features = ["json"] } +# reqwest = { version = "0.11", features = ["json"] } bytes = "1.0" thiserror = "1.0" http = "0.2" url = "2.2" +futures = "0.3" [dev-dependencies] azure_identity = { path = "../../../sdk/identity", version = "0.1.0" } diff --git a/services/mgmt/vmware/examples/private_cloud_list.rs b/services/mgmt/vmware/examples/private_cloud_list.rs index ec4f28381a..d0ea8f04dc 100644 --- a/services/mgmt/vmware/examples/private_cloud_list.rs +++ b/services/mgmt/vmware/examples/private_cloud_list.rs @@ -11,19 +11,23 @@ cargo run --package azure_mgmt_vmware --example private_cloud_list */ use azure_identity::token_credentials::AzureCliCredential; -use azure_mgmt_vmware::operations::private_clouds; +use std::sync::Arc; #[tokio::main] async fn main() -> Result<(), Box> { - let http_client = azure_core::new_http_client(); - let token_credential = AzureCliCredential {}; - let subscription_id = &AzureCliCredential::get_subscription()?; - let config = &azure_mgmt_vmware::config(http_client, Box::new(token_credential)).build(); + let endpoint = "https://management.azure.com".to_owned(); + let credential = AzureCliCredential {}; + let client = azure_mgmt_vmware::Client::new(endpoint, Arc::new(credential)); + let ops = client.operations().list().into_future().await?; + println!("# of operations{}", ops.value.len()); - let clouds = private_clouds::list_in_subscription(config, subscription_id).await?; - println!("# of private clouds {}", clouds.value.len()); - for cloud in &clouds.value { - println!("{:?}", cloud.tracked_resource.resource.id); - } + // let subscription_id = &AzureCliCredential::get_subscription()?; + // let config = &azure_mgmt_vmware::config(http_client, Box::new(credential)).build(); + + // let clouds = private_clouds::list_in_subscription(config, subscription_id).await?; + // println!("# of private clouds {}", clouds.value.len()); + // for cloud in &clouds.value { + // println!("{:?}", cloud.tracked_resource.resource.id); + // } Ok(()) } diff --git a/services/mgmt/vmware/src/lib.rs b/services/mgmt/vmware/src/lib.rs index 24085630e9..1b2d67788e 100644 --- a/services/mgmt/vmware/src/lib.rs +++ b/services/mgmt/vmware/src/lib.rs @@ -6,7 +6,7 @@ #[cfg(feature = "package-2021-12-01")] pub mod package_2021_12_01; #[cfg(all(feature = "package-2021-12-01", not(feature = "no-default-version")))] -pub use package_2021_12_01::{models, operations, operations::Error}; +pub use package_2021_12_01::{models, operations, operations::Client, operations::Error}; #[cfg(feature = "package-2021-06-01")] pub mod package_2021_06_01; #[cfg(all(feature = "package-2021-06-01", not(feature = "no-default-version")))] diff --git a/services/mgmt/vmware/src/package_2021_12_01/operations.rs b/services/mgmt/vmware/src/package_2021_12_01/operations.rs index 793b93d303..a1ec8cd9ce 100644 --- a/services/mgmt/vmware/src/package_2021_12_01/operations.rs +++ b/services/mgmt/vmware/src/package_2021_12_01/operations.rs @@ -200,46 +200,108 @@ pub enum Error { #[error(transparent)] ScriptExecutions_GetExecutionLogs(#[from] script_executions::get_execution_logs::Error), } + +#[derive(Clone)] +pub(crate) struct Context {} + +#[derive(Clone)] +pub struct Client { + endpoint: String, + credential: std::sync::Arc, + pipeline: azure_core::pipeline::Pipeline, +} + +impl Client { + pub fn endpoint(&self) -> &str { + self.endpoint.as_str() + } + pub fn credential(&self) -> &dyn azure_core::TokenCredential { + self.credential.as_ref() + } + pub fn http_client(&self) -> &dyn azure_core::HttpClient { + self.pipeline.http_client() + } +} + +pub struct OperationsClient(Client); + +impl Client { + pub fn new(endpoint: String, credential: std::sync::Arc) -> Self { + let pipeline = azure_core::pipeline::Pipeline::new( + option_env!("CARGO_PKG_NAME"), + option_env!("CARGO_PKG_VERSION"), + azure_core::ClientOptions::default(), + Vec::new(), + Vec::new(), + ); + Self { + endpoint, + credential, + pipeline, + } + } + + pub fn operations(&self) -> OperationsClient { + OperationsClient(self.clone()) + } +} + +impl OperationsClient { + pub fn list(&self) -> operations::list::Builder { + operations::list::Builder { client: self.0.clone() } + } +} + pub mod operations { use super::{models, API_VERSION}; - pub async fn list(operation_config: &crate::OperationConfig) -> std::result::Result { - let http_client = operation_config.http_client(); - let url_str = &format!("{}/providers/Microsoft.AVS/operations", operation_config.base_path(),); - let mut url = url::Url::parse(url_str).map_err(list::Error::ParseUrlError)?; - let mut req_builder = http::request::Builder::new(); - req_builder = req_builder.method(http::Method::GET); - if let Some(token_credential) = operation_config.token_credential() { - let token_response = token_credential - .get_token(operation_config.token_credential_resource()) - .await - .map_err(list::Error::GetTokenError)?; - req_builder = req_builder.header(http::header::AUTHORIZATION, format!("Bearer {}", token_response.token.secret())); - } - url.query_pairs_mut().append_pair("api-version", super::API_VERSION); - let req_body = bytes::Bytes::from_static(azure_core::EMPTY_BODY); - req_builder = req_builder.uri(url.as_str()); - let req = req_builder.body(req_body).map_err(list::Error::BuildRequestError)?; - let rsp = http_client.execute_request(req).await.map_err(list::Error::ExecuteRequestError)?; - match rsp.status() { - http::StatusCode::OK => { - let rsp_body = rsp.body(); - let rsp_value: models::OperationList = - serde_json::from_slice(rsp_body).map_err(|source| list::Error::DeserializeError(source, rsp_body.clone()))?; - Ok(rsp_value) - } - status_code => { - let rsp_body = rsp.body(); - let rsp_value: models::CloudError = - serde_json::from_slice(rsp_body).map_err(|source| list::Error::DeserializeError(source, rsp_body.clone()))?; - Err(list::Error::DefaultResponse { - status_code, - value: rsp_value, + pub mod list { + use super::{models, API_VERSION}; + + #[derive(Clone)] + pub struct Builder { + pub(crate) client: crate::operations::Client, + } + + impl Builder { + pub fn into_future(self) -> futures::future::BoxFuture<'static, std::result::Result> { + Box::pin(async move { + let http_client = self.client.http_client(); + let url_str = &format!("{}/providers/Microsoft.AVS/operations", &self.client.endpoint); + let mut url = url::Url::parse(url_str).map_err(Error::ParseUrlError)?; + let mut req_builder = http::request::Builder::new(); + req_builder = req_builder.method(http::Method::GET); + let credential = self.client.credential(); + let token_response = credential + .get_token("https://management.azure.com/") // this should be scopes[] + .await + .map_err(Error::GetTokenError)?; + req_builder = req_builder.header(http::header::AUTHORIZATION, format!("Bearer {}", token_response.token.secret())); + url.query_pairs_mut().append_pair("api-version", super::API_VERSION); + let req_body = bytes::Bytes::from_static(azure_core::EMPTY_BODY); + req_builder = req_builder.uri(url.as_str()); + let req = req_builder.body(req_body).map_err(Error::BuildRequestError)?; + let rsp = http_client.execute_request(req).await.map_err(Error::ExecuteRequestError)?; + match rsp.status() { + http::StatusCode::OK => { + let rsp_body = rsp.body(); + let rsp_value: models::OperationList = + serde_json::from_slice(rsp_body).map_err(|source| Error::DeserializeError(source, rsp_body.clone()))?; + Ok(rsp_value) + } + status_code => { + let rsp_body = rsp.body(); + let rsp_value: models::CloudError = + serde_json::from_slice(rsp_body).map_err(|source| Error::DeserializeError(source, rsp_body.clone()))?; + Err(Error::DefaultResponse { + status_code, + value: rsp_value, + }) + } + } }) } } - } - pub mod list { - use super::{models, API_VERSION}; + #[derive(Debug, thiserror :: Error)] pub enum Error { #[error("HTTP status code {}", status_code)] From 92457678d6620a81e50e43205f96256e046d2f0f Mon Sep 17 00:00:00 2001 From: Cameron Taggart Date: Tue, 16 Nov 2021 00:31:19 -0600 Subject: [PATCH 02/10] move Client into module --- .../src/package_2021_12_01/operations.rs | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/services/mgmt/vmware/src/package_2021_12_01/operations.rs b/services/mgmt/vmware/src/package_2021_12_01/operations.rs index a1ec8cd9ce..6f6e86ac56 100644 --- a/services/mgmt/vmware/src/package_2021_12_01/operations.rs +++ b/services/mgmt/vmware/src/package_2021_12_01/operations.rs @@ -223,8 +223,6 @@ impl Client { } } -pub struct OperationsClient(Client); - impl Client { pub fn new(endpoint: String, credential: std::sync::Arc) -> Self { let pipeline = azure_core::pipeline::Pipeline::new( @@ -241,19 +239,22 @@ impl Client { } } - pub fn operations(&self) -> OperationsClient { - OperationsClient(self.clone()) - } -} - -impl OperationsClient { - pub fn list(&self) -> operations::list::Builder { - operations::list::Builder { client: self.0.clone() } + pub fn operations(&self) -> operations::Client { + operations::Client(self.clone()) } } pub mod operations { use super::{models, API_VERSION}; + + pub struct Client(pub(crate) super::Client); + + impl Client { + pub fn list(&self) -> list::Builder { + list::Builder { client: self.0.clone() } + } + } + pub mod list { use super::{models, API_VERSION}; From 39df437bee325418ed87221b824a0a1645c57c61 Mon Sep 17 00:00:00 2001 From: Cameron Taggart Date: Tue, 16 Nov 2021 12:21:06 -0600 Subject: [PATCH 03/10] add scopes --- services/mgmt/vmware/examples/private_cloud_list.rs | 8 +++++--- .../vmware/src/package_2021_12_01/operations.rs | 13 +++++++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/services/mgmt/vmware/examples/private_cloud_list.rs b/services/mgmt/vmware/examples/private_cloud_list.rs index d0ea8f04dc..d6148c845a 100644 --- a/services/mgmt/vmware/examples/private_cloud_list.rs +++ b/services/mgmt/vmware/examples/private_cloud_list.rs @@ -15,9 +15,11 @@ use std::sync::Arc; #[tokio::main] async fn main() -> Result<(), Box> { - let endpoint = "https://management.azure.com".to_owned(); - let credential = AzureCliCredential {}; - let client = azure_mgmt_vmware::Client::new(endpoint, Arc::new(credential)); + let endpoint = "https://management.azure.com"; + let credential = Arc::new(AzureCliCredential {}); + let scopes = &["https://management.azure.com/"]; + let client = azure_mgmt_vmware::Client::new(endpoint, credential, scopes); + let ops = client.operations().list().into_future().await?; println!("# of operations{}", ops.value.len()); diff --git a/services/mgmt/vmware/src/package_2021_12_01/operations.rs b/services/mgmt/vmware/src/package_2021_12_01/operations.rs index 6f6e86ac56..8db6008044 100644 --- a/services/mgmt/vmware/src/package_2021_12_01/operations.rs +++ b/services/mgmt/vmware/src/package_2021_12_01/operations.rs @@ -2,6 +2,8 @@ #![allow(unused_mut)] #![allow(unused_variables)] #![allow(unused_imports)] +use std::ops::Deref; + use super::{models, API_VERSION}; #[non_exhaustive] #[derive(Debug, thiserror :: Error)] @@ -208,6 +210,7 @@ pub(crate) struct Context {} pub struct Client { endpoint: String, credential: std::sync::Arc, + scopes: Vec, pipeline: azure_core::pipeline::Pipeline, } @@ -218,13 +221,18 @@ impl Client { pub fn credential(&self) -> &dyn azure_core::TokenCredential { self.credential.as_ref() } + pub fn scopes(&self) -> Vec<&str> { + self.scopes.iter().map(String::as_str).collect() + } pub fn http_client(&self) -> &dyn azure_core::HttpClient { self.pipeline.http_client() } } impl Client { - pub fn new(endpoint: String, credential: std::sync::Arc) -> Self { + pub fn new(endpoint: &str, credential: std::sync::Arc, scopes: &[&str]) -> Self { + let endpoint = endpoint.to_owned(); + let scopes: Vec = scopes.iter().map(|scope| scope.deref().to_owned()).collect(); let pipeline = azure_core::pipeline::Pipeline::new( option_env!("CARGO_PKG_NAME"), option_env!("CARGO_PKG_VERSION"), @@ -235,6 +243,7 @@ impl Client { Self { endpoint, credential, + scopes, pipeline, } } @@ -273,7 +282,7 @@ pub mod operations { req_builder = req_builder.method(http::Method::GET); let credential = self.client.credential(); let token_response = credential - .get_token("https://management.azure.com/") // this should be scopes[] + .get_token(&self.client.scopes().join(" ")) .await .map_err(Error::GetTokenError)?; req_builder = req_builder.header(http::header::AUTHORIZATION, format!("Bearer {}", token_response.token.secret())); From a17be6647377c7a90262ba92c93c8c9c1146094d Mon Sep 17 00:00:00 2001 From: Cameron Taggart Date: Tue, 16 Nov 2021 18:48:43 -0600 Subject: [PATCH 04/10] send request using pipeline --- .../src/package_2021_12_01/operations.rs | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/services/mgmt/vmware/src/package_2021_12_01/operations.rs b/services/mgmt/vmware/src/package_2021_12_01/operations.rs index 8db6008044..e81478bd33 100644 --- a/services/mgmt/vmware/src/package_2021_12_01/operations.rs +++ b/services/mgmt/vmware/src/package_2021_12_01/operations.rs @@ -203,7 +203,7 @@ pub enum Error { ScriptExecutions_GetExecutionLogs(#[from] script_executions::get_execution_logs::Error), } -#[derive(Clone)] +#[derive(Clone, Default)] pub(crate) struct Context {} #[derive(Clone)] @@ -224,8 +224,10 @@ impl Client { pub fn scopes(&self) -> Vec<&str> { self.scopes.iter().map(String::as_str).collect() } - pub fn http_client(&self) -> &dyn azure_core::HttpClient { - self.pipeline.http_client() + pub(crate) async fn send(&self, request: impl Into) -> Result { + let mut context = azure_core::PipelineContext::new(azure_core::Context::default(), Context::default()); + let mut request = request.into(); + self.pipeline.send(&mut context, &mut request).await } } @@ -275,7 +277,6 @@ pub mod operations { impl Builder { pub fn into_future(self) -> futures::future::BoxFuture<'static, std::result::Result> { Box::pin(async move { - let http_client = self.client.http_client(); let url_str = &format!("{}/providers/Microsoft.AVS/operations", &self.client.endpoint); let mut url = url::Url::parse(url_str).map_err(Error::ParseUrlError)?; let mut req_builder = http::request::Builder::new(); @@ -290,18 +291,23 @@ pub mod operations { let req_body = bytes::Bytes::from_static(azure_core::EMPTY_BODY); req_builder = req_builder.uri(url.as_str()); let req = req_builder.body(req_body).map_err(Error::BuildRequestError)?; - let rsp = http_client.execute_request(req).await.map_err(Error::ExecuteRequestError)?; - match rsp.status() { + let rsp = self.client.send(req).await.map_err(Error::SendError)?; + let (rsp_status, rsp_headers, rsp_stream) = rsp.deconstruct(); + match rsp_status { http::StatusCode::OK => { - let rsp_body = rsp.body(); + let rsp_body = azure_core::collect_pinned_stream(rsp_stream) + .await + .map_err(Error::ResponseBytesError)?; let rsp_value: models::OperationList = - serde_json::from_slice(rsp_body).map_err(|source| Error::DeserializeError(source, rsp_body.clone()))?; + serde_json::from_slice(&rsp_body).map_err(|source| Error::DeserializeError(source, rsp_body.clone()))?; Ok(rsp_value) } status_code => { - let rsp_body = rsp.body(); + let rsp_body = azure_core::collect_pinned_stream(rsp_stream) + .await + .map_err(Error::ResponseBytesError)?; let rsp_value: models::CloudError = - serde_json::from_slice(rsp_body).map_err(|source| Error::DeserializeError(source, rsp_body.clone()))?; + serde_json::from_slice(&rsp_body).map_err(|source| Error::DeserializeError(source, rsp_body.clone()))?; Err(Error::DefaultResponse { status_code, value: rsp_value, @@ -324,7 +330,9 @@ pub mod operations { #[error("Failed to build request: {0}")] BuildRequestError(http::Error), #[error("Failed to execute request: {0}")] - ExecuteRequestError(azure_core::HttpError), + SendError(azure_core::Error), + #[error("Failed to get response bytes: {0}")] + ResponseBytesError(azure_core::StreamError), #[error("Failed to serialize request body: {0}")] SerializeError(serde_json::Error), #[error("Failed to deserialize response: {0}, body: {1:?}")] From ee0345a3ec8f84cf4faa2277df39d0f7a0589a93 Mon Sep 17 00:00:00 2001 From: Cameron Taggart Date: Thu, 18 Nov 2021 10:13:36 -0600 Subject: [PATCH 05/10] ClientBuilder --- .../vmware/examples/private_cloud_list.rs | 4 +- services/mgmt/vmware/src/lib.rs | 2 +- .../src/package_2021_12_01/operations.rs | 43 +++++++++++++++---- 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/services/mgmt/vmware/examples/private_cloud_list.rs b/services/mgmt/vmware/examples/private_cloud_list.rs index d6148c845a..4b5e3d4a6a 100644 --- a/services/mgmt/vmware/examples/private_cloud_list.rs +++ b/services/mgmt/vmware/examples/private_cloud_list.rs @@ -15,10 +15,8 @@ use std::sync::Arc; #[tokio::main] async fn main() -> Result<(), Box> { - let endpoint = "https://management.azure.com"; let credential = Arc::new(AzureCliCredential {}); - let scopes = &["https://management.azure.com/"]; - let client = azure_mgmt_vmware::Client::new(endpoint, credential, scopes); + let client = azure_mgmt_vmware::ClientBuilder::new(credential).build(); let ops = client.operations().list().into_future().await?; println!("# of operations{}", ops.value.len()); diff --git a/services/mgmt/vmware/src/lib.rs b/services/mgmt/vmware/src/lib.rs index 1b2d67788e..e8f908b142 100644 --- a/services/mgmt/vmware/src/lib.rs +++ b/services/mgmt/vmware/src/lib.rs @@ -6,7 +6,7 @@ #[cfg(feature = "package-2021-12-01")] pub mod package_2021_12_01; #[cfg(all(feature = "package-2021-12-01", not(feature = "no-default-version")))] -pub use package_2021_12_01::{models, operations, operations::Client, operations::Error}; +pub use package_2021_12_01::{models, operations, operations::Client, operations::ClientBuilder, operations::Error}; #[cfg(feature = "package-2021-06-01")] pub mod package_2021_06_01; #[cfg(all(feature = "package-2021-06-01", not(feature = "no-default-version")))] diff --git a/services/mgmt/vmware/src/package_2021_12_01/operations.rs b/services/mgmt/vmware/src/package_2021_12_01/operations.rs index e81478bd33..af78616d3c 100644 --- a/services/mgmt/vmware/src/package_2021_12_01/operations.rs +++ b/services/mgmt/vmware/src/package_2021_12_01/operations.rs @@ -203,15 +203,44 @@ pub enum Error { ScriptExecutions_GetExecutionLogs(#[from] script_executions::get_execution_logs::Error), } -#[derive(Clone, Default)] -pub(crate) struct Context {} - #[derive(Clone)] pub struct Client { endpoint: String, credential: std::sync::Arc, scopes: Vec, - pipeline: azure_core::pipeline::Pipeline, + pipeline: azure_core::pipeline::Pipeline, +} + +pub struct ClientBuilder { + credential: std::sync::Arc, + endpoint: Option, + scopes: Option>, +} + +pub const DEFAULT_ENDPOINT: &str = azure_core::resource_manager_endpoint::AZURE_PUBLIC_CLOUD; + +impl ClientBuilder { + pub fn new(credential: std::sync::Arc) -> Self { + Self { + credential, + endpoint: None, + scopes: None, + } + } + + pub fn endpoint(mut self, endpoint: &str) { + self.endpoint = Some(endpoint.to_owned()); + } + + pub fn scopes(mut self, scopes: &[&str]) { + self.scopes = Some(scopes.iter().map(|scope| (*scope).to_owned()).collect()); + } + + pub fn build(self) -> Client { + let endpoint = self.endpoint.unwrap_or_else(|| DEFAULT_ENDPOINT.to_owned()); + let scopes = self.scopes.unwrap_or_else(|| vec![format!("{}/", endpoint)]); + Client::new(endpoint, self.credential, scopes) + } } impl Client { @@ -225,16 +254,14 @@ impl Client { self.scopes.iter().map(String::as_str).collect() } pub(crate) async fn send(&self, request: impl Into) -> Result { - let mut context = azure_core::PipelineContext::new(azure_core::Context::default(), Context::default()); + let mut context = azure_core::Context::default(); let mut request = request.into(); self.pipeline.send(&mut context, &mut request).await } } impl Client { - pub fn new(endpoint: &str, credential: std::sync::Arc, scopes: &[&str]) -> Self { - let endpoint = endpoint.to_owned(); - let scopes: Vec = scopes.iter().map(|scope| scope.deref().to_owned()).collect(); + pub fn new(endpoint: String, credential: std::sync::Arc, scopes: Vec) -> Self { let pipeline = azure_core::pipeline::Pipeline::new( option_env!("CARGO_PKG_NAME"), option_env!("CARGO_PKG_VERSION"), From 84eed8505dd0f39b9f771d9a62c923213a91ee24 Mon Sep 17 00:00:00 2001 From: Cameron Taggart Date: Thu, 18 Nov 2021 10:37:52 -0600 Subject: [PATCH 06/10] impl Into for endpoint Co-authored-by: bmc-msft <41130664+bmc-msft@users.noreply.github.com> --- services/mgmt/vmware/src/package_2021_12_01/operations.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/mgmt/vmware/src/package_2021_12_01/operations.rs b/services/mgmt/vmware/src/package_2021_12_01/operations.rs index af78616d3c..71c3d45092 100644 --- a/services/mgmt/vmware/src/package_2021_12_01/operations.rs +++ b/services/mgmt/vmware/src/package_2021_12_01/operations.rs @@ -228,8 +228,8 @@ impl ClientBuilder { } } - pub fn endpoint(mut self, endpoint: &str) { - self.endpoint = Some(endpoint.to_owned()); + pub fn endpoint(mut self, impl Into) { + self.endpoint = Some(endpoint.into()); } pub fn scopes(mut self, scopes: &[&str]) { From d60b70bd0576702c4f7e4ba59589cd3f1936c6ab Mon Sep 17 00:00:00 2001 From: Cameron Taggart Date: Thu, 25 Nov 2021 07:49:39 -0800 Subject: [PATCH 07/10] impl Into> --- .../mgmt/vmware/examples/private_cloud_list.rs | 4 +++- .../vmware/src/package_2021_12_01/operations.rs | 15 +++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/services/mgmt/vmware/examples/private_cloud_list.rs b/services/mgmt/vmware/examples/private_cloud_list.rs index 4b5e3d4a6a..a567de5d20 100644 --- a/services/mgmt/vmware/examples/private_cloud_list.rs +++ b/services/mgmt/vmware/examples/private_cloud_list.rs @@ -18,7 +18,9 @@ async fn main() -> Result<(), Box> { let credential = Arc::new(AzureCliCredential {}); let client = azure_mgmt_vmware::ClientBuilder::new(credential).build(); - let ops = client.operations().list().into_future().await?; + let name = "George"; // this works + // let name = "Washington".to_owned(); // and so does this + let ops = client.operations().list(name).into_future().await?; println!("# of operations{}", ops.value.len()); // let subscription_id = &AzureCliCredential::get_subscription()?; diff --git a/services/mgmt/vmware/src/package_2021_12_01/operations.rs b/services/mgmt/vmware/src/package_2021_12_01/operations.rs index af78616d3c..a9f4acabc6 100644 --- a/services/mgmt/vmware/src/package_2021_12_01/operations.rs +++ b/services/mgmt/vmware/src/package_2021_12_01/operations.rs @@ -283,28 +283,31 @@ impl Client { } pub mod operations { + use std::borrow::Cow; use super::{models, API_VERSION}; pub struct Client(pub(crate) super::Client); impl Client { - pub fn list(&self) -> list::Builder { - list::Builder { client: self.0.clone() } + pub fn list<'a>(&'a self, name: impl Into>) -> list::Builder { + list::Builder { client: self.0.clone(), name: name.into() } } } pub mod list { + use std::borrow::Cow; use super::{models, API_VERSION}; #[derive(Clone)] - pub struct Builder { + pub struct Builder<'a> { pub(crate) client: crate::operations::Client, + pub(crate) name: Cow<'a, str>, } - impl Builder { - pub fn into_future(self) -> futures::future::BoxFuture<'static, std::result::Result> { + impl<'a> Builder<'a> { + pub fn into_future(self) -> futures::future::BoxFuture<'a, std::result::Result> { Box::pin(async move { - let url_str = &format!("{}/providers/Microsoft.AVS/operations", &self.client.endpoint); + let url_str = &format!("{}/providers/Microsoft.AVS/operations?name={}", &self.client.endpoint, self.name); let mut url = url::Url::parse(url_str).map_err(Error::ParseUrlError)?; let mut req_builder = http::request::Builder::new(); req_builder = req_builder.method(http::Method::GET); From d9017ca17e42295a2daeb26a9938970142b430e7 Mon Sep 17 00:00:00 2001 From: Cameron Taggart Date: Thu, 25 Nov 2021 08:02:33 -0800 Subject: [PATCH 08/10] less Cow, just plain references --- services/autorust/codegen/examples/gen_mgmt.rs | 2 +- services/mgmt/vmware/src/package_2021_12_01/operations.rs | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/services/autorust/codegen/examples/gen_mgmt.rs b/services/autorust/codegen/examples/gen_mgmt.rs index 05c381e0b2..97493abc24 100644 --- a/services/autorust/codegen/examples/gen_mgmt.rs +++ b/services/autorust/codegen/examples/gen_mgmt.rs @@ -5,7 +5,7 @@ use std::{collections::HashSet, fs, path::PathBuf}; const OUTPUT_FOLDER: &str = "../mgmt"; -const ONLY_SERVICES: &[&str] = &[]; +const ONLY_SERVICES: &[&str] = &["vmware"]; const SKIP_SERVICES: &[&str] = &[ "datamigration", diff --git a/services/mgmt/vmware/src/package_2021_12_01/operations.rs b/services/mgmt/vmware/src/package_2021_12_01/operations.rs index a9f4acabc6..6ec49073af 100644 --- a/services/mgmt/vmware/src/package_2021_12_01/operations.rs +++ b/services/mgmt/vmware/src/package_2021_12_01/operations.rs @@ -283,25 +283,23 @@ impl Client { } pub mod operations { - use std::borrow::Cow; use super::{models, API_VERSION}; pub struct Client(pub(crate) super::Client); impl Client { - pub fn list<'a>(&'a self, name: impl Into>) -> list::Builder { + pub fn list<'a>(&'a self, name: &'a str) -> list::Builder { list::Builder { client: self.0.clone(), name: name.into() } } } pub mod list { - use std::borrow::Cow; use super::{models, API_VERSION}; #[derive(Clone)] pub struct Builder<'a> { pub(crate) client: crate::operations::Client, - pub(crate) name: Cow<'a, str>, + pub(crate) name: &'a str, } impl<'a> Builder<'a> { From 0307a185feb53bde9dcd15a825f9c37234f335eb Mon Sep 17 00:00:00 2001 From: Cameron Taggart Date: Thu, 25 Nov 2021 08:08:33 -0800 Subject: [PATCH 09/10] fix enpoint setter --- services/mgmt/vmware/src/package_2021_12_01/operations.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/mgmt/vmware/src/package_2021_12_01/operations.rs b/services/mgmt/vmware/src/package_2021_12_01/operations.rs index ff3ffb67cc..f3897f7144 100644 --- a/services/mgmt/vmware/src/package_2021_12_01/operations.rs +++ b/services/mgmt/vmware/src/package_2021_12_01/operations.rs @@ -228,7 +228,7 @@ impl ClientBuilder { } } - pub fn endpoint(mut self, impl Into) { + pub fn endpoint(mut self, endpoint: impl Into) { self.endpoint = Some(endpoint.into()); } From 3b0693cdad663bd360f81b0374635a14204b8aa0 Mon Sep 17 00:00:00 2001 From: Cameron Taggart Date: Thu, 25 Nov 2021 08:14:53 -0800 Subject: [PATCH 10/10] just &str --- services/mgmt/vmware/examples/private_cloud_list.rs | 3 +-- services/mgmt/vmware/src/package_2021_12_01/operations.rs | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/services/mgmt/vmware/examples/private_cloud_list.rs b/services/mgmt/vmware/examples/private_cloud_list.rs index a567de5d20..bada7d9f0e 100644 --- a/services/mgmt/vmware/examples/private_cloud_list.rs +++ b/services/mgmt/vmware/examples/private_cloud_list.rs @@ -18,8 +18,7 @@ async fn main() -> Result<(), Box> { let credential = Arc::new(AzureCliCredential {}); let client = azure_mgmt_vmware::ClientBuilder::new(credential).build(); - let name = "George"; // this works - // let name = "Washington".to_owned(); // and so does this + let name = "George"; // allow passing a reference for parameters let ops = client.operations().list(name).into_future().await?; println!("# of operations{}", ops.value.len()); diff --git a/services/mgmt/vmware/src/package_2021_12_01/operations.rs b/services/mgmt/vmware/src/package_2021_12_01/operations.rs index f3897f7144..301ef4b822 100644 --- a/services/mgmt/vmware/src/package_2021_12_01/operations.rs +++ b/services/mgmt/vmware/src/package_2021_12_01/operations.rs @@ -289,7 +289,7 @@ pub mod operations { impl Client { pub fn list<'a>(&'a self, name: &'a str) -> list::Builder { - list::Builder { client: self.0.clone(), name: name.into() } + list::Builder { client: self.0.clone(), name } } }