Skip to content

Commit 05f6c8f

Browse files
authored
Update azure_core, azure_identity to 0.22. Fixes due to API changes. Release 0.26. (#591)
* Update azure_core, azure_identity to 0.22. Fixes due to API changes. * Workaround for uuid build failure on wasm32
1 parent e3f73c3 commit 05f6c8f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+4718
-4527
lines changed

CHANGELOG.md

+25
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,31 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [0.26.0]
11+
12+
This is a significant change due to updating to the first offical releases of
13+
`azure_core` (0.22) and `azure_identity` (0.22). These crates have a number of
14+
breaking changes over previous versions.
15+
16+
## Breaking changes
17+
- Update `azure_core`, `azure_identity` to 0.22.
18+
- `ClientBuilder::per_retry_policies()` renamed to `per_try_policies()` to align with
19+
`azure_core` API naming.
20+
- `Response::into_body()` renamed to `Response::into_raw_body()` to align with
21+
`azure_core` API naming.
22+
- Renamed crate features to align with `azure_core`:
23+
- `enable_reqwest` => `reqwest`
24+
- `enable_reqwest_rustls` => `reqwest_rustls`
25+
26+
- Notes on changes to `azure_core` API:
27+
- `Response::into_body()` is renamed `Response::into_raw_body()`
28+
- Notes on changes to `azure_identity` API:
29+
- The credential creation functions now return values wrapped in `Arc<_>`,
30+
so you no longer need to do this in your client code.
31+
- Example: `DefaultAzureCredential::new()` previously returned
32+
`Result<DefaultAzureCredential>` but now returns a
33+
`Result<Arc<DefaultAzureCredential>>`.
34+
1035
## [0.25.0]
1136

1237
### Breaking change

autorust/codegen/src/codegen_models.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,7 @@ fn create_struct(
11661166
serde.add_with("azure_core::date::rfc1123::option");
11671167
} else if type_name.is_vec() {
11681168
serde.add_default();
1169-
serde.add_deserialize_with("azure_core::util::deserialize_null_as_default");
1169+
serde.add_deserialize_with("crate::serde::deserialize_null_as_default");
11701170
serde.add_skip_serializing_if("Vec::is_empty");
11711171
} else {
11721172
serde.add_default();

autorust/codegen/src/codegen_operations/create_client_and_builder.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -79,31 +79,31 @@ pub fn create_client(modules: &[String], endpoint: Option<&str>) -> Result<Token
7979
#[doc = "Set the retry options."]
8080
#[must_use]
8181
pub fn retry(mut self, retry: impl Into<azure_core::RetryOptions>) -> Self {
82-
self.options = self.options.retry(retry);
82+
self.options.retry = Some(retry.into());
8383
self
8484
}
8585

8686
#[doc = "Set the transport options."]
8787
#[must_use]
8888
pub fn transport(mut self, transport: impl Into<azure_core::TransportOptions>) -> Self {
89-
self.options = self.options.transport(transport);
89+
self.options.transport = Some(transport.into());
9090
self
9191
}
9292

9393
#[doc = "Set per-call policies."]
9494
#[must_use]
9595
pub fn per_call_policies(mut self, policies: impl Into<Vec<std::sync::Arc<dyn azure_core::Policy>>>) -> Self {
96-
self.options = self.options.per_call_policies(policies);
96+
self.options.per_call_policies = policies.into();
9797
self
9898
}
9999

100-
#[doc = "Set per-retry policies."]
100+
#[doc = "Set per-try policies."]
101101
#[must_use]
102-
pub fn per_retry_policies(
102+
pub fn per_try_policies(
103103
mut self,
104104
policies: impl Into<Vec<std::sync::Arc<dyn azure_core::Policy>>>,
105105
) -> Self {
106-
self.options = self.options.per_retry_policies(policies);
106+
self.options.per_try_policies = policies.into();
107107
self
108108
}
109109

autorust/codegen/src/codegen_operations/request_builder_into_future.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl ToTokens for RequestBuilderIntoFutureCode {
7474
let response = self.client.send(&mut req).await?;
7575
let headers = response.headers();
7676
let retry_after = get_retry_after(headers);
77-
let bytes = response.into_body().collect().await?;
77+
let bytes = response.into_raw_body().collect().await?;
7878
let provisioning_state = get_provisioning_state(&bytes).ok_or_else(||
7979
Error::message(ErrorKind::Other, "Long running operation failed (missing provisioning state)".to_string())
8080
)?;
@@ -113,7 +113,7 @@ impl ToTokens for RequestBuilderIntoFutureCode {
113113

114114
(
115115
quote! {
116-
self.send().await?.into_body().await
116+
self.send().await?.into_raw_body().await
117117
},
118118
quote! {
119119
#[doc = "Returns a future that sends the request and returns the parsed response body."]
@@ -159,7 +159,7 @@ impl ToTokens for RequestBuilderIntoFutureCode {
159159
} else {
160160
(
161161
quote! {
162-
self.send().await?.into_body().await
162+
self.send().await?.into_raw_body().await
163163
},
164164
quote! {
165165
#[doc = "Returns a future that sends the request and returns the parsed response body."]

autorust/codegen/src/codegen_operations/request_builder_send.rs

+16-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ use crate::codegen::PARAM_RE;
66
use crate::Result;
77
use crate::{codegen::parse_path_params, identifier::SnakeCaseIdent};
88

9-
use super::{new_request_code::NewRequestCode, response_code::ResponseCode, set_request_code::SetRequestCode};
9+
use super::{
10+
new_request_code::NewRequestCode, response_code::ResponseCode, set_request_code::SetRequestCode,
11+
};
1012
/// The `send` function of the request builder.
1113
pub struct RequestBuilderSendCode {
1214
new_request_code: NewRequestCode,
@@ -16,7 +18,11 @@ pub struct RequestBuilderSendCode {
1618
}
1719

1820
impl RequestBuilderSendCode {
19-
pub fn new(new_request_code: NewRequestCode, request_builder: SetRequestCode, response_code: ResponseCode) -> Result<Self> {
21+
pub fn new(
22+
new_request_code: NewRequestCode,
23+
request_builder: SetRequestCode,
24+
response_code: ResponseCode,
25+
) -> Result<Self> {
2026
let params = parse_path_params(&new_request_code.path);
2127
let url_args: Result<Vec<_>> = params.iter().map(|s| s.to_snake_case_ident()).collect();
2228
let url_args = url_args?;
@@ -121,12 +127,17 @@ impl ToTokens for RequestBuilderSendCode {
121127
req.insert_header(azure_core::headers::VERSION, #api_version);
122128
});
123129
}
124-
let response_type = self.response_code.response_type().expect("pageable response has a body");
130+
let response_type = self
131+
.response_code
132+
.response_type()
133+
.expect("pageable response has a body");
125134

126135
// some of the pageable requests specify the continuation token
127136
// as a parameter. In this case, use the basic request builder,
128137
// but insert the continuation parameter
129-
if let Some(continuable_param) = get_continuable_param(next_link_name, request_builder) {
138+
if let Some(continuable_param) =
139+
get_continuable_param(next_link_name, request_builder)
140+
{
130141
quote! {
131142
pub fn into_stream(self) -> azure_core::Pageable<#response_type, azure_core::error::Error> {
132143
let make_request = move |continuation: Option<String>| {
@@ -144,7 +155,7 @@ impl ToTokens for RequestBuilderSendCode {
144155
match rsp.status() {
145156
#match_status
146157
};
147-
rsp?.into_body().await
158+
rsp?.into_raw_body().await
148159
}
149160
};
150161

autorust/codegen/src/codegen_operations/response_code.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ impl ToTokens for ResponseCode {
115115
}
116116
};
117117
let into_body = quote! {
118-
pub async fn into_body(self) -> azure_core::Result<#response_type> {
119-
let bytes = self.0.into_body().collect().await?;
118+
pub async fn into_raw_body(self) -> azure_core::Result<#response_type> {
119+
let bytes = self.0.into_raw_body().collect().await?;
120120
#deserialize_body
121121
Ok(body)
122122
}

autorust/codegen/src/codegen_operations/set_request_param_code.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,12 @@ impl ToTokens for SetRequestParamsCode {
111111

112112
// TODO: more work needs to be done to ensure we're using
113113
// the right encoder.
114-
let encoder = if !self.params.has_content_type_header() && self.content_type.starts_with("application/xml") {
114+
let encoder = if !self.params.has_content_type_header()
115+
&& self.content_type.starts_with("application/xml")
116+
{
115117
quote! {azure_core::xml::to_xml}
116118
} else {
117-
quote! { azure_core::to_json }
119+
quote! { azure_core::json::to_json }
118120
};
119121

120122
if !param.is_optional() || is_vec {

azure_devops_rust_api/Cargo.toml

+12-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
[package]
55
name = "azure_devops_rust_api"
6-
version = "0.25.0"
6+
version = "0.26.0"
77
edition = "2021"
88
authors = ["John Batty <[email protected]>"]
99
description = "Rust API library for Azure DevOps"
@@ -23,7 +23,7 @@ rust-version = "1.64.0"
2323
doctest = false
2424

2525
[dependencies]
26-
azure_core = { version = "0.21", default-features = true }
26+
azure_core = { version = "0.22", default-features = true }
2727
serde = { version = "1", features = ["derive"] }
2828
serde_json = "1"
2929
bytes = "1"
@@ -34,16 +34,22 @@ async-trait = "0.1"
3434
tracing = "0.1"
3535
once_cell = "1"
3636

37+
# uuid is an indirect dependency that fails to build on wasm32.
38+
# See: https://github.com/uuid-rs/uuid/issues/802
39+
# As a workaround, include it directly and enable the "js" feature.
40+
[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies]
41+
uuid = { version = "1", features = ["serde", "v4", "js"] }
42+
3743
[dev-dependencies]
38-
azure_identity = "0.21"
44+
azure_identity = "0.22"
3945
tokio = { version = "1", features = ["full"] }
4046
anyhow = "1"
4147
tracing-subscriber = "0.3"
4248

4349
[features]
44-
default = ["enable_reqwest"]
45-
enable_reqwest = ["azure_core/enable_reqwest"]
46-
enable_reqwest_rustls = ["azure_core/enable_reqwest_rustls"]
50+
default = ["reqwest"]
51+
reqwest = ["azure_core/reqwest"]
52+
reqwest_rustls = ["azure_core/reqwest_rustls"]
4753
no-default-tag = []
4854
accounts = []
4955
approvals_and_checks = []

azure_devops_rust_api/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Example application `Cargo.toml` dependency spec showing how to specify desired
6767
```toml
6868
[dependencies]
6969
...
70-
azure_devops_rust_api = { version = "0.25.0", features = ["git", "pipelines"] }
70+
azure_devops_rust_api = { version = "0.26.0", features = ["git", "pipelines"] }
7171
```
7272

7373
## Examples

azure_devops_rust_api/examples/git_items_get.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ async fn main() -> Result<()> {
4848
.await?
4949
.into_raw_response();
5050

51-
let file_data = rsp.into_body().collect_string().await?;
51+
let file_data = rsp.into_raw_body().collect_string().await?;
5252
println!("\n{file_path} contents:\n{}", file_data);
5353

5454
// Download the entire repo as a zip archive.
@@ -71,7 +71,7 @@ async fn main() -> Result<()> {
7171
.await?
7272
.into_raw_response();
7373

74-
let mut body = rsp.into_body();
74+
let mut body = rsp.into_raw_body();
7575
let mut file = std::fs::File::create("full_repo.zip")?;
7676
while let Some(chunk_result) = body.next().await {
7777
let chunk = chunk_result.context("Error reading chunk")?;

azure_devops_rust_api/examples/git_repo_download_zip.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ async fn main() -> Result<()> {
8989
.send()
9090
.await?
9191
.into_raw_response()
92-
.into_body();
92+
.into_raw_body();
9393

9494
let mut file = std::fs::File::create("blobs.zip")?;
9595
while let Some(chunk_result) = body.next().await {

azure_devops_rust_api/examples/git_repo_get_raw_rsp.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ async fn main() -> Result<()> {
3636
// Display the raw response details
3737
println!("status: {:#?}", rsp.status());
3838
println!("headers:\n{:#?}", rsp.headers());
39-
println!("body:\n{:#?}", rsp.into_body().collect_string().await?);
39+
println!("body:\n{:#?}", rsp.into_raw_body().collect_string().await?);
4040

4141
Ok(())
4242
}

azure_devops_rust_api/examples/utils/mod.rs

+2-15
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,12 @@ use anyhow::Result;
55
use async_trait::async_trait;
66
use azure_core::{Context, Policy, PolicyResult, Request};
77
use azure_devops_rust_api::Credential;
8-
use azure_identity::DefaultAzureCredentialBuilder;
8+
use azure_identity::DefaultAzureCredential;
99
use std::sync::Arc;
1010

1111
fn authenticate_with_default_credential() -> Result<Credential> {
1212
println!("Authenticate using auto-refreshing DefaultAzureCredential");
13-
// `DefaultAzureCredential` can authenticate using one of:
14-
// - `EnvironmentCredential`
15-
// - `ManagedIdentityCredential`
16-
// - `AzureCliCredential`
17-
// For examples we just want to use AzureCliCredential, so exclude the
18-
// other mechanisms.
19-
// It would be simpler to directly create `AzureCliCredential` here, but I want to
20-
// demonstrate use of `DefaultAzureCredentialBuilder`.
21-
let default_azure_credential = Arc::new(
22-
DefaultAzureCredentialBuilder::new()
23-
.exclude_environment_credential()
24-
.exclude_managed_identity_credential()
25-
.build()?,
26-
);
13+
let default_azure_credential = DefaultAzureCredential::new()?;
2714

2815
Ok(Credential::from_token_credential(default_azure_credential))
2916
}

azure_devops_rust_api/examples/wiki_pages_create_or_update.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,15 @@ async fn get_wiki_page_etag(
113113
}
114114
Err(e) => {
115115
// If the response is a 404 then we need to create the page
116-
if e.as_http_error()
117-
.expect("Failed cast to http error")
118-
.status()
116+
if e.http_status()
117+
.expect("Failed to retrieve HTTP status")
119118
.canonical_reason()
120119
== "Not Found"
121120
{
122121
println!("Wiki page does not exist");
123122
None
124123
} else {
125-
panic!("Failed to retrieve etag: {}", e)
124+
panic!("Failed to retrieve etag")
126125
}
127126
}
128127
}

azure_devops_rust_api/src/accounts/mod.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ impl ClientBuilder {
4848
#[doc = "Set the retry options."]
4949
#[must_use]
5050
pub fn retry(mut self, retry: impl Into<azure_core::RetryOptions>) -> Self {
51-
self.options = self.options.retry(retry);
51+
self.options.retry = Some(retry.into());
5252
self
5353
}
5454
#[doc = "Set the transport options."]
5555
#[must_use]
5656
pub fn transport(mut self, transport: impl Into<azure_core::TransportOptions>) -> Self {
57-
self.options = self.options.transport(transport);
57+
self.options.transport = Some(transport.into());
5858
self
5959
}
6060
#[doc = "Set per-call policies."]
@@ -63,16 +63,16 @@ impl ClientBuilder {
6363
mut self,
6464
policies: impl Into<Vec<std::sync::Arc<dyn azure_core::Policy>>>,
6565
) -> Self {
66-
self.options = self.options.per_call_policies(policies);
66+
self.options.per_call_policies = policies.into();
6767
self
6868
}
69-
#[doc = "Set per-retry policies."]
69+
#[doc = "Set per-try policies."]
7070
#[must_use]
71-
pub fn per_retry_policies(
71+
pub fn per_try_policies(
7272
mut self,
7373
policies: impl Into<Vec<std::sync::Arc<dyn azure_core::Policy>>>,
7474
) -> Self {
75-
self.options = self.options.per_retry_policies(policies);
75+
self.options.per_try_policies = policies.into();
7676
self
7777
}
7878
#[doc = "Convert the builder into a `Client` instance."]
@@ -160,8 +160,8 @@ pub mod accounts {
160160
#[derive(Debug)]
161161
pub struct Response(azure_core::Response);
162162
impl Response {
163-
pub async fn into_body(self) -> azure_core::Result<models::AccountList> {
164-
let bytes = self.0.into_body().collect().await?;
163+
pub async fn into_raw_body(self) -> azure_core::Result<models::AccountList> {
164+
let bytes = self.0.into_raw_body().collect().await?;
165165
let body: models::AccountList = serde_json::from_slice(&bytes).map_err(|e| {
166166
azure_core::error::Error::full(
167167
azure_core::error::ErrorKind::DataConversion,
@@ -289,7 +289,7 @@ pub mod accounts {
289289
#[doc = ""]
290290
#[doc = "See [IntoFuture documentation](https://doc.rust-lang.org/std/future/trait.IntoFuture.html) for more details."]
291291
fn into_future(self) -> Self::IntoFuture {
292-
Box::pin(async move { self.send().await?.into_body().await })
292+
Box::pin(async move { self.send().await?.into_raw_body().await })
293293
}
294294
}
295295
}

0 commit comments

Comments
 (0)