Skip to content

Commit a5b6cf1

Browse files
authored
Import the right features for HTTP-based crates (#2217)
* Import the right features for HTTP-based crates Resolves #2056 by making sure we import the right features for the vast majority of crates, which are HTTP-based on azure_core. Those not using HTTP-based azure_core will need to use a path dependency until after GA and will then probably need to use a version dependency...which should be the norm by then anyway. * Fix wasm32 build Don't really need these features on by default anyway.
1 parent ead6bd0 commit a5b6cf1

File tree

15 files changed

+151
-88
lines changed

15 files changed

+151
-88
lines changed

.taplo.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[formatting]
2+
align_single_comments = false
3+
array_auto_collapse = false
4+
array_trailing_comma = true
5+
indent_string = " "
6+
7+
[[rule]]
8+
include = ["**/Cargo.toml"]
9+
keys = [
10+
"dependencies",
11+
"build-dependencies",
12+
"dev-dependencies",
13+
]
14+
15+
[rule.formatting]
16+
reorder_keys = true

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ repository = "https://github.com/azure/azure-sdk-for-rust"
2828
rust-version = "1.80"
2929

3030
[workspace.dependencies.typespec]
31+
default-features = false
3132
path = "sdk/typespec"
3233
version = "0.2.0"
33-
default-features = false
3434

3535
[workspace.dependencies.typespec_client_core]
36+
default-features = false
3637
path = "sdk/typespec/typespec_client_core"
3738
version = "0.1.0"
38-
default-features = false
3939

4040
[workspace.dependencies.typespec_macros]
4141
version = "0.1.0"

sdk/core/azure_core/Cargo.toml

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,40 +14,45 @@ edition.workspace = true
1414
rust-version.workspace = true
1515

1616
[dependencies]
17-
typespec = { workspace = true, features = ["http", "json"] }
18-
typespec_client_core = { workspace = true, features = ["http", "json"] }
1917
async-lock = { workspace = true }
2018
async-trait.workspace = true
2119
bytes.workspace = true
2220
futures.workspace = true
23-
tracing.workspace = true
21+
hmac = { workspace = true, optional = true }
22+
once_cell.workspace = true
23+
openssl = { workspace = true, optional = true }
24+
paste.workspace = true
25+
pin-project.workspace = true
2426
serde.workspace = true
2527
serde_json.workspace = true
26-
pin-project.workspace = true
27-
paste.workspace = true
28-
tokio = { workspace = true, optional = true }
29-
hmac = { workspace = true, optional = true }
3028
sha2 = { workspace = true, optional = true }
31-
openssl = { workspace = true, optional = true }
32-
once_cell.workspace = true
29+
tokio = { workspace = true, optional = true }
30+
tracing.workspace = true
31+
typespec = { workspace = true, features = ["http", "json"] }
32+
typespec_client_core = { workspace = true, features = ["http", "json"] }
3333

3434
[build-dependencies]
3535
rustc_version.workspace = true
3636

3737
[dev-dependencies]
3838
azure_identity.path = "../../identity/azure_identity"
3939
azure_security_keyvault_secrets.path = "../../keyvault/azure_security_keyvault_secrets"
40+
thiserror.workspace = true
4041
time.workspace = true
41-
tracing-subscriber.workspace = true
4242
tokio.workspace = true
43-
thiserror.workspace = true
43+
tracing-subscriber.workspace = true
4444

4545
[features]
46-
default = []
46+
default = [
47+
"reqwest",
48+
"reqwest_deflate",
49+
"reqwest_gzip",
50+
]
4751
azurite_workaround = []
4852
hmac_openssl = ["dep:openssl"]
4953
hmac_rust = ["dep:sha2", "dep:hmac"]
5054
reqwest = ["typespec_client_core/reqwest"]
55+
reqwest_deflate = ["typespec_client_core/reqwest_deflate"]
5156
reqwest_gzip = ["typespec_client_core/reqwest_gzip"]
5257
reqwest_rustls = ["typespec_client_core/reqwest_rustls"]
5358
test = ["typespec_client_core/test"]
@@ -60,9 +65,9 @@ features = [
6065
"hmac_openssl",
6166
"hmac_rust",
6267
"reqwest",
68+
"reqwest_deflate",
6369
"reqwest_gzip",
6470
"reqwest_rustls",
65-
"test",
6671
"tokio_fs",
6772
"tokio_sleep",
6873
"xml",

sdk/core/azure_core_amqp/Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ categories = ["api-bindings"]
1818
edition = "2021"
1919

2020
[dependencies]
21-
tokio.workspace = true
22-
azure_core.workspace = true
23-
time.workspace = true
24-
tracing.workspace = true
21+
azure_core = { path = "../azure_core", default-features = false }
2522
fe2o3-amqp = { workspace = true, optional = true }
23+
fe2o3-amqp-cbs = { workspace = true, optional = true }
2624
fe2o3-amqp-ext = { workspace = true, optional = true }
2725
fe2o3-amqp-management = { workspace = true, optional = true }
28-
fe2o3-amqp-cbs = { workspace = true, optional = true }
2926
fe2o3-amqp-types = { workspace = true, optional = true }
3027
serde_amqp = { workspace = true, optional = true }
3128
serde_bytes = { workspace = true, optional = true }
29+
time.workspace = true
30+
tokio.workspace = true
31+
tracing.workspace = true
3232
uuid = { workspace = true }
3333

3434
[dev-dependencies]

sdk/core/azure_core_test/src/lib.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use std::path::{Path, PathBuf};
1717

1818
#[cfg_attr(target_arch = "wasm32", allow(dead_code))]
1919
const ASSETS_FILE: &str = "assets.json";
20-
const SPAN_TARGET: &str = "test-proxy";
2120

2221
/// Context information required by recorded client library tests.
2322
///
@@ -28,20 +27,20 @@ pub struct TestContext {
2827
repo_dir: &'static Path,
2928
crate_dir: &'static Path,
3029
service_dir: &'static str,
31-
test_module: &'static str,
32-
test_name: &'static str,
30+
module_name: &'static str,
31+
name: &'static str,
3332
recording: Option<Recording>,
3433
}
3534

3635
impl TestContext {
3736
pub(crate) fn new(
3837
crate_dir: &'static str,
39-
test_module: &'static str,
40-
test_name: &'static str,
38+
module_dir: &'static str,
39+
name: &'static str,
4140
) -> azure_core::Result<Self> {
4241
let service_dir = parent_of(crate_dir, "sdk")
4342
.ok_or_else(|| Error::message(ErrorKind::Other, "not under 'sdk' folder in repo"))?;
44-
let test_module = Path::new(test_module)
43+
let test_module = Path::new(module_dir)
4544
.file_stem()
4645
.ok_or_else(|| Error::message(ErrorKind::Other, "invalid test module"))?
4746
.to_str()
@@ -50,8 +49,8 @@ impl TestContext {
5049
repo_dir: find_ancestor_of(crate_dir, ".git")?,
5150
crate_dir: Path::new(crate_dir),
5251
service_dir,
53-
test_module,
54-
test_name,
52+
module_name: test_module,
53+
name,
5554
recording: None,
5655
})
5756
}
@@ -100,13 +99,13 @@ impl TestContext {
10099
}
101100

102101
/// Gets the module name containing the current test.
103-
pub fn test_module(&self) -> &'static str {
104-
self.test_module
102+
pub fn module_name(&self) -> &'static str {
103+
self.module_name
105104
}
106105

107106
/// Gets the current test function name.
108-
pub fn test_name(&self) -> &'static str {
109-
self.test_name
107+
pub fn name(&self) -> &'static str {
108+
self.name
110109
}
111110

112111
/// Gets the recording assets file under the crate directory.
@@ -153,8 +152,8 @@ impl TestContext {
153152
pub(crate) fn test_recording_file(&self) -> String {
154153
let path = self
155154
.test_data_dir()
156-
.join(self.test_module)
157-
.join(self.test_name)
155+
.join(self.module_name)
156+
.join(self.name)
158157
.as_path()
159158
.with_extension("json");
160159
path.to_str()
@@ -238,8 +237,8 @@ mod tests {
238237
.unwrap()
239238
.replace("\\", "/")
240239
.ends_with("sdk/core/azure_core_test"));
241-
assert_eq!(ctx.test_module(), "lib");
242-
assert_eq!(ctx.test_name(), "test_context_new");
240+
assert_eq!(ctx.module_name(), "lib");
241+
assert_eq!(ctx.name(), "test_context_new");
243242
assert_eq!(
244243
ctx.test_recording_file().replace("\\", "/"),
245244
"sdk/core/azure_core_test/tests/data/lib/test_context_new.json"

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use azure_core::{
1515
ClientMethodOptions, ClientOptions, Context, Method, Pipeline, Request, RequestContent, Result,
1616
Url,
1717
};
18+
use tracing::Span;
1819

1920
/// The test-proxy client.
2021
///
@@ -45,6 +46,7 @@ impl Client {
4546
&self.endpoint
4647
}
4748

49+
#[tracing::instrument(level = "trace", skip_all, fields(endpoint = %self.endpoint), err)]
4850
pub async fn record_start(
4951
&self,
5052
body: RequestContent<StartPayload>,
@@ -66,6 +68,7 @@ impl Client {
6668
Ok(RecordStartResult { recording_id })
6769
}
6870

71+
#[tracing::instrument(level = "trace", skip_all, fields(endpoint = %self.endpoint, recording_id), err)]
6972
pub async fn record_stop(
7073
&self,
7174
recording_id: &str,
@@ -85,12 +88,17 @@ impl Client {
8588
Ok(())
8689
}
8790

91+
#[tracing::instrument(level = "trace", skip_all, fields(endpoint = %self.endpoint, recording_id), err)]
8892
pub async fn playback_start(
8993
&self,
9094
body: RequestContent<StartPayload>,
9195
options: Option<ClientPlaybackStartOptions<'_>>,
9296
) -> Result<PlaybackStartResult> {
9397
let options = options.unwrap_or_default();
98+
Span::current().record(
99+
stringify!(recording_id),
100+
options.recording_id.map(AsRef::as_ref),
101+
);
94102
let ctx = Context::with_context(&options.method_options.context);
95103
let mut url = self.endpoint.clone();
96104
url = url.join("/Playback/Start")?;
@@ -109,6 +117,7 @@ impl Client {
109117
Ok(result)
110118
}
111119

120+
#[tracing::instrument(level = "trace", skip_all, fields(endpoint = %self.endpoint, recording_id), err)]
112121
pub async fn playback_stop(
113122
&self,
114123
recording_id: &str,
@@ -126,12 +135,17 @@ impl Client {
126135
Ok(())
127136
}
128137

138+
#[tracing::instrument(level = "trace", skip_all, fields(endpoint = %self.endpoint, recording_id), err)]
129139
pub async fn set_matcher(
130140
&self,
131141
matcher: Matcher,
132142
options: Option<ClientSetMatcherOptions<'_>>,
133143
) -> Result<()> {
134144
let options = options.unwrap_or_default();
145+
Span::current().record(
146+
stringify!(recording_id),
147+
options.recording_id.map(AsRef::as_ref),
148+
);
135149
let ctx = Context::with_context(&options.method_options.context);
136150
let mut url = self.endpoint.clone();
137151
url = url.join("/Admin/SetMatcher")?;
@@ -144,6 +158,7 @@ impl Client {
144158
Ok(())
145159
}
146160

161+
#[tracing::instrument(level = "trace", skip_all, fields(endpoint = %self.endpoint, recording_id), err)]
147162
pub async fn add_sanitizer<S>(
148163
&self,
149164
sanitizer: S,
@@ -154,6 +169,10 @@ impl Client {
154169
azure_core::Error: From<<S as AsHeaders>::Error>,
155170
{
156171
let options = options.unwrap_or_default();
172+
Span::current().record(
173+
stringify!(recording_id),
174+
options.recording_id.map(AsRef::as_ref),
175+
);
157176
let ctx = Context::with_context(&options.method_options.context);
158177
let mut url = self.endpoint.clone();
159178
url = url.join("/Admin/AddSanitizer")?;
@@ -166,12 +185,17 @@ impl Client {
166185
Ok(())
167186
}
168187

188+
#[tracing::instrument(level = "trace", skip_all, fields(endpoint = %self.endpoint, recording_id), err)]
169189
pub async fn remove_sanitizers(
170190
&self,
171191
body: RequestContent<SanitizerList>,
172192
options: Option<ClientRemoveSanitizersOptions<'_>>,
173193
) -> Result<RemovedSanitizers> {
174194
let options = options.unwrap_or_default();
195+
Span::current().record(
196+
stringify!(recording_id),
197+
options.recording_id.map(AsRef::as_ref),
198+
);
175199
let ctx = Context::with_context(&options.method_options.context);
176200
let mut url = self.endpoint.clone();
177201
url = url.join("/Admin/RemoveSanitizers")?;
@@ -187,8 +211,13 @@ impl Client {
187211
.await
188212
}
189213

214+
#[tracing::instrument(level = "trace", skip_all, fields(endpoint = %self.endpoint, recording_id), err)]
190215
pub async fn reset(&self, options: Option<ClientResetOptions<'_>>) -> Result<()> {
191216
let options = options.unwrap_or_default();
217+
Span::current().record(
218+
stringify!(recording_id),
219+
options.recording_id.map(AsRef::as_ref),
220+
);
192221
let ctx = Context::with_context(&options.method_options.context);
193222
let mut url = self.endpoint.clone();
194223
url = url.join("/Admin/Reset")?;

0 commit comments

Comments
 (0)