Skip to content

Commit bbfd1b0

Browse files
Refactor RequestContent conversion for Spector (Azure#2957)
Co-authored-by: Larry Osterman <[email protected]>
1 parent b0483f5 commit bbfd1b0

File tree

10 files changed

+108
-109
lines changed

10 files changed

+108
-109
lines changed

sdk/core/azure_core/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,17 @@
44

55
### Features Added
66

7+
- Added `RequestContent::from_slice()`.
8+
- Added `TryFrom<T> for RequestContent<T, JsonFormat>` for JSON primitives.
9+
- Added support for WASM to the `async_runtime` module.
710
- Added logging policy to log HTTP requests and responses in the pipeline. As a part of this change, sanitization support was added to places which log HTTP headers and URLs. The `azure_core::http::ClientOptions` has been enhanced with a `LoggingOptions` which allows a user/service client to specify headers or URL query parameters which should be allowed. Note that the sanitization feature is disabled if you build with the `debug` feature enabled.
811

912
### Breaking Changes
1013

14+
- Changed `FromStr for RequestContent<T, F>` to `RequestContent::from_str()`.
15+
- Changed `TryFrom<&'static str> for RequestContent<T, F>` to `RequestContent::from_static()`.
16+
- Changed `TryFrom<Bytes> for RequestContent<T, F>` to `From<Bytes> for RequestContent<T, F>` because it was already infallible.
17+
- Removed `TryFrom<Vec<u8>> for RequestContent<T, F>` since `RequestContent::from()` already exists.
1118
- Removed feature `reqwest_rustls_tls`. See [README.md](https://github.com/heaths/azure-sdk-for-rust/blob/main/sdk/core/azure_core/README.md) for alternative HTTP client configuration.
1219
- Removed the `fs` module including the `FileStream` and `FileStreamBuilder` types. Moved to `examples/` for `typespec_client_core` to copy if needed.
1320
- Removed the `setters` macro.

sdk/core/azure_core_test/src/proxy/models.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pub struct StartPayload {
6969
impl TryFrom<StartPayload> for RequestContent<StartPayload> {
7070
type Error = azure_core::Error;
7171
fn try_from(value: StartPayload) -> Result<Self, Self::Error> {
72-
RequestContent::try_from(to_json(&value)?)
72+
Ok(to_json(&value)?.into())
7373
}
7474
}
7575

@@ -88,7 +88,7 @@ pub struct VariablePayload {
8888
impl TryFrom<VariablePayload> for RequestContent<VariablePayload> {
8989
type Error = azure_core::Error;
9090
fn try_from(value: VariablePayload) -> Result<Self, Self::Error> {
91-
RequestContent::try_from(to_json(&value)?)
91+
Ok(to_json(&value)?.into())
9292
}
9393
}
9494

@@ -111,7 +111,7 @@ pub struct SanitizerList {
111111
impl TryFrom<SanitizerList> for RequestContent<SanitizerList> {
112112
type Error = azure_core::Error;
113113
fn try_from(value: SanitizerList) -> Result<Self, Self::Error> {
114-
RequestContent::try_from(to_json(&value)?)
114+
Ok(to_json(&value)?.into())
115115
}
116116
}
117117

sdk/keyvault/azure_security_keyvault_certificates/src/generated/models/models_impl.rs

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/keyvault/azure_security_keyvault_keys/src/generated/models/models_impl.rs

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/keyvault/azure_security_keyvault_keys/tests/key_client.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ async fn update_key_properties(ctx: TestContext) -> Result<()> {
104104

105105
#[recorded::test]
106106
async fn list_keys(ctx: TestContext) -> Result<()> {
107+
use azure_core::http::RequestContent;
108+
107109
let recording = ctx.recording();
108110

109111
let mut options = KeyClientOptions::default();
@@ -120,7 +122,7 @@ async fn list_keys(ctx: TestContext) -> Result<()> {
120122
let secret1 = client
121123
.create_key(
122124
names[0],
123-
r#"{"kty":"EC","curve":"P-384"}"#.try_into()?,
125+
RequestContent::from_str(r#"{"kty":"EC","curve":"P-384"}"#),
124126
None,
125127
)
126128
.await?
@@ -131,7 +133,7 @@ async fn list_keys(ctx: TestContext) -> Result<()> {
131133
let secret2 = client
132134
.create_key(
133135
names[1],
134-
r#"{"kty":"EC","curve":"P-384"}"#.try_into()?,
136+
RequestContent::from_str(r#"{"kty":"EC","curve":"P-384"}"#),
135137
None,
136138
)
137139
.await?

sdk/keyvault/azure_security_keyvault_secrets/src/generated/models/models_impl.rs

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/keyvault/azure_security_keyvault_secrets/tests/secret_client.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ async fn update_secret_properties(ctx: TestContext) -> Result<()> {
107107

108108
#[recorded::test]
109109
async fn list_secrets(ctx: TestContext) -> Result<()> {
110+
use azure_core::http::RequestContent;
111+
110112
let recording = ctx.recording();
111113

112114
let mut options = SecretClientOptions::default();
@@ -121,14 +123,22 @@ async fn list_secrets(ctx: TestContext) -> Result<()> {
121123
// Create several secrets.
122124
let mut names = vec!["list-secrets-1", "list-secrets-2"];
123125
let secret1 = client
124-
.set_secret(names[0], r#"{"value":"secret-value-1"}"#.try_into()?, None)
126+
.set_secret(
127+
names[0],
128+
RequestContent::from_str(r#"{"value":"secret-value-1"}"#),
129+
None,
130+
)
125131
.await?
126132
.into_body()
127133
.await?;
128134
assert_eq!(secret1.value, Some("secret-value-1".into()));
129135

130136
let secret2 = client
131-
.set_secret(names[1], r#"{"value":"secret-value-2"}"#.try_into()?, None)
137+
.set_secret(
138+
names[1],
139+
RequestContent::from_str(r#"{"value":"secret-value-2"}"#),
140+
None,
141+
)
132142
.await?
133143
.into_body()
134144
.await?;

sdk/storage/azure_storage_blob/src/generated/models/models_impl.rs

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/typespec/typespec_client_core/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,16 @@
44

55
### Features Added
66

7+
- Added `RequestContent::from_slice()`.
8+
- Added `TryFrom<T> for RequestContent<T, JsonFormat>` for JSON primitives.
79
- Added support for WASM to the `async_runtime` module.
810

911
### Breaking Changes
1012

13+
- Changed `FromStr for RequestContent<T, F>` to `RequestContent::from_str()`.
14+
- Changed `TryFrom<&'static str> for RequestContent<T, F>` to `RequestContent::from_static()`.
15+
- Changed `TryFrom<Bytes> for RequestContent<T, F>` to `From<Bytes> for RequestContent<T, F>` because it was already infallible.
16+
- Removed `TryFrom<Vec<u8>> for RequestContent<T, F>` since `RequestContent::from()` already exists.
1117
- Removed feature `reqwest_rustls_tls`. See [README.md](https://github.com/heaths/azure-sdk-for-rust/blob/main/sdk/typespec/typespec_client_core/README.md) for alternative HTTP client configuration.
1218
- Removed the `fs` module including the `FileStream` and `FileStreamBuilder` types. Moved to `examples/` to copy if needed.
1319
- Removed the `setters` macro.

0 commit comments

Comments
 (0)