Skip to content

Commit 4e18162

Browse files
committed
Use named format parameters
1 parent a602501 commit 4e18162

File tree

4 files changed

+33
-51
lines changed

4 files changed

+33
-51
lines changed

sdk/security_keyvault/src/certificate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ impl<'a, T: TokenCredential> CertificateClient<'a, T> {
206206
let response_body = self.get_authed(uri.to_string()).await?;
207207
let response = serde_json::from_str::<KeyVaultGetCertificateResponse>(&response_body)
208208
.with_context(ErrorKind::DataConversion, || {
209-
format!("failed to parse get certificate response. uri: {} certificate_name: {} response_body: {}", uri, name, response_body)
209+
format!("failed to parse get certificate response. uri: {uri} certificate_name: {name} response_body: {response_body}")
210210
})?;
211211
Ok(KeyVaultCertificate {
212212
key_id: response.kid,
@@ -469,7 +469,7 @@ impl<'a, T: TokenCredential> CertificateClient<'a, T> {
469469
let backup_blob =
470470
serde_json::from_str::<KeyVaultCertificateBackupResponseRaw>(&response_body)
471471
.with_context(ErrorKind::DataConversion, || {
472-
format!("failed to parse certificate backup response. uri: {}", uri)
472+
format!("failed to parse certificate backup response. uri: {uri}")
473473
})?;
474474

475475
Ok(CertificateBackupResult {

sdk/security_keyvault/src/client.rs

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl<'a, T: TokenCredential> KeyClient<'a, T> {
3737
/// ```
3838
pub fn new(vault_url: &str, token_credential: &'a T) -> Result<Self, Error> {
3939
let vault_url = Url::parse(vault_url).with_context(ErrorKind::DataConversion, || {
40-
format!("failed to parse vault url: {}", vault_url)
40+
format!("failed to parse vault url: {vault_url}")
4141
})?;
4242
let endpoint = extract_endpoint(&vault_url)?;
4343
let client = KeyClient {
@@ -74,7 +74,7 @@ impl<'a, T: TokenCredential> KeyClient<'a, T> {
7474
.await
7575
.unwrap();
7676
let body = resp.text().await.with_context(ErrorKind::Io, || {
77-
format!("failed to read response body text. uri: {}", uri)
77+
format!("failed to read response body text. uri: {uri}")
7878
})?;
7979
Ok(body)
8080
}
@@ -91,7 +91,7 @@ impl<'a, T: TokenCredential> KeyClient<'a, T> {
9191
.await
9292
.unwrap();
9393
let body = resp.text().await.with_context(ErrorKind::Io, || {
94-
format!("failed to read response body text. uri: {}", uri)
94+
format!("failed to read response body text. uri: {uri}")
9595
})?;
9696
Ok(body)
9797
}
@@ -114,27 +114,24 @@ impl<'a, T: TokenCredential> KeyClient<'a, T> {
114114
}
115115

116116
let resp = req.send().await.with_context(ErrorKind::Io, || {
117-
format!("failed to send request. uri: {}", uri)
117+
format!("failed to send request. uri: {uri}")
118118
})?;
119119

120120
let body = resp.text().await.with_context(ErrorKind::Io, || {
121-
format!("failed to read response body text. uri: {}", uri)
121+
format!("failed to read response body text. uri: {uri}")
122122
})?;
123123
let body_deserialized = serde_json::from_str::<serde_json::Value>(&body).unwrap();
124124

125125
if let Some(err) = body_deserialized.get("error") {
126126
let msg = err.get("message").ok_or_else(|| {
127127
Error::with_message(
128128
ErrorKind::DataConversion,
129-
format!(
130-
"failed to read message field from error response. body: {}",
131-
body
132-
),
129+
format!("failed to read message field from error response. body: {body}"),
133130
)
134131
})?;
135132
Err(Error::with_message(
136133
ErrorKind::Other,
137-
format!("post response error: {}", msg),
134+
format!("post response error: {msg}"),
138135
))
139136
} else {
140137
Ok(body)
@@ -158,18 +155,15 @@ impl<'a, T: TokenCredential> KeyClient<'a, T> {
158155
.unwrap();
159156

160157
let body = resp.text().await.with_context(ErrorKind::Io, || {
161-
format!("failed to read response body text. uri: {}", uri)
158+
format!("failed to read response body text. uri: {uri}")
162159
})?;
163160
let body_deserialized = serde_json::from_str::<serde_json::Value>(&body).unwrap();
164161

165162
if let Some(err) = body_deserialized.get("error") {
166163
let msg = err.get("message").ok_or_else(|| {
167164
Error::with_message(
168165
ErrorKind::DataConversion,
169-
format!(
170-
"failed to read message field from error response. body: {}",
171-
body
172-
),
166+
format!("failed to read message field from error response. body: {body}"),
173167
)
174168
})?;
175169
Err(Error::with_message(
@@ -192,7 +186,7 @@ impl<'a, T: TokenCredential> KeyClient<'a, T> {
192186
.await
193187
.unwrap();
194188
let body = resp.text().await.with_context(ErrorKind::Io, || {
195-
format!("failed to read response body text. uri: {}", uri)
189+
format!("failed to read response body text. uri: {uri}")
196190
})?;
197191
Ok(body)
198192
}
@@ -229,7 +223,7 @@ impl<'a, T: TokenCredential> CertificateClient<'a, T> {
229223
/// ```
230224
pub fn new(vault_url: &str, token_credential: &'a T) -> Result<Self, Error> {
231225
let vault_url = Url::parse(vault_url).with_context(ErrorKind::DataConversion, || {
232-
format!("failed to parse vault url: {}", vault_url)
226+
format!("failed to parse vault url: {vault_url}")
233227
})?;
234228
let endpoint = extract_endpoint(&vault_url)?;
235229
let client = CertificateClient {
@@ -266,7 +260,7 @@ impl<'a, T: TokenCredential> CertificateClient<'a, T> {
266260
.await
267261
.unwrap();
268262
let body = resp.text().await.with_context(ErrorKind::Io, || {
269-
format!("failed to read response body text. uri: {}", uri)
263+
format!("failed to read response body text. uri: {uri}")
270264
})?;
271265
Ok(body)
272266
}
@@ -283,7 +277,7 @@ impl<'a, T: TokenCredential> CertificateClient<'a, T> {
283277
.await
284278
.unwrap();
285279
let body = resp.text().await.with_context(ErrorKind::Io, || {
286-
format!("failed to read response body text. uri: {}", uri)
280+
format!("failed to read response body text. uri: {uri}")
287281
})?;
288282
Ok(body)
289283
}
@@ -306,11 +300,11 @@ impl<'a, T: TokenCredential> CertificateClient<'a, T> {
306300
}
307301

308302
let resp = req.send().await.with_context(ErrorKind::Io, || {
309-
format!("failed to send request. uri: {}", uri)
303+
format!("failed to send request. uri: {uri}")
310304
})?;
311305

312306
let body = resp.text().await.with_context(ErrorKind::Io, || {
313-
format!("failed to read response body text. uri: {}", uri)
307+
format!("failed to read response body text. uri: {uri}")
314308
})?;
315309
let body_deserialized = serde_json::from_str::<serde_json::Value>(&body).unwrap();
316310

@@ -319,14 +313,13 @@ impl<'a, T: TokenCredential> CertificateClient<'a, T> {
319313
Error::with_message(
320314
ErrorKind::DataConversion,
321315
format!(
322-
"failed to read message field from error response. uri: {} body: {}",
323-
uri, body
316+
"failed to read message field from error response. uri: {uri} body: {body}"
324317
),
325318
)
326319
})?;
327320
Err(Error::with_message(
328321
ErrorKind::Other,
329-
format!("post response error: {}", msg),
322+
format!("post response error: {msg}"),
330323
))
331324
} else {
332325
Ok(body)
@@ -360,15 +353,12 @@ impl<'a, T: TokenCredential> CertificateClient<'a, T> {
360353
let msg = err.get("message").ok_or_else(|| {
361354
Error::with_message(
362355
ErrorKind::DataConversion,
363-
format!(
364-
"failed to read message field from error response. body: {}",
365-
body
366-
),
356+
format!("failed to read message field from error response. body: {body}"),
367357
)
368358
})?;
369359
Err(Error::with_message(
370360
ErrorKind::Other,
371-
format!("post response error. uri: {} msg: {}", uri, msg),
361+
format!("post response error. uri: {uri} msg: {msg}"),
372362
))
373363
} else {
374364
Ok(body)
@@ -386,7 +376,7 @@ impl<'a, T: TokenCredential> CertificateClient<'a, T> {
386376
.await
387377
.unwrap();
388378
let body = resp.text().await.with_context(ErrorKind::Io, || {
389-
format!("failed to read response body text. uri: {}", uri)
379+
format!("failed to read response body text. uri: {uri}")
390380
})?;
391381
Ok(body)
392382
}
@@ -400,15 +390,15 @@ fn extract_endpoint(url: &Url) -> Result<String, Error> {
400390
.ok_or_else(|| {
401391
Error::with_message(
402392
ErrorKind::DataConversion,
403-
format!("failed to parse host from url. url: {}", url),
393+
format!("failed to parse host from url. url: {url}"),
404394
)
405395
})?
406396
.splitn(2, '.') // FIXME: replace with split_once() when it is in stable
407397
.last()
408398
.ok_or_else(|| {
409399
Error::with_message(
410400
ErrorKind::DataConversion,
411-
format!("failed to extract endpoint from url. url: {}", url),
401+
format!("failed to extract endpoint from url. url: {url}"),
412402
)
413403
})?;
414404
Ok(format!("{}://{}", url.scheme(), endpoint))

sdk/security_keyvault/src/key.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ impl RsaDecryptParameters {
315315
| EncryptionAlgorithm::RsaOaep256 => Ok(Self { algorithm }),
316316
_ => Err(Error::with_message(
317317
ErrorKind::Other,
318-
format!("unexpected encryption algorithm: {}", algorithm),
318+
format!("unexpected encryption algorithm: {algorithm}"),
319319
)),
320320
}
321321
}
@@ -353,7 +353,7 @@ impl AesGcmDecryptParameters {
353353
}),
354354
_ => Err(Error::with_message(
355355
ErrorKind::Other,
356-
format!("unexpected encryption algorithm: {}", algorithm),
356+
format!("unexpected encryption algorithm: {algorithm}"),
357357
)),
358358
}
359359
}
@@ -377,7 +377,7 @@ impl AesCbcDecryptParameters {
377377
| EncryptionAlgorithm::A256CbcPad => Ok(Self { algorithm, iv }),
378378
_ => Err(Error::with_message(
379379
ErrorKind::Other,
380-
format!("unexpected encryption algorithm: {}", algorithm),
380+
format!("unexpected encryption algorithm: {algorithm}"),
381381
)),
382382
}
383383
}

sdk/security_keyvault/src/secret.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,7 @@ impl<'a, T: TokenCredential> KeyClient<'a, T> {
154154
let response = serde_json::from_str::<KeyVaultGetSecretResponse>(&response_body)
155155
.with_context(ErrorKind::DataConversion, || {
156156
format!(
157-
"failed to parse KeyVaultGetSecretResponse. secret_name: {} secret_version_name: {} response_body: {}",
158-
secret_name, secret_version_name, response_body
157+
"failed to parse KeyVaultGetSecretResponse. secret_name: {secret_name} secret_version_name: {secret_version_name} response_body: {response_body}"
159158
)
160159
})?;
161160
Ok(KeyVaultSecret {
@@ -198,10 +197,7 @@ impl<'a, T: TokenCredential> KeyClient<'a, T> {
198197
let resp_body = self.get_authed(uri.to_string()).await?;
199198
let response = serde_json::from_str::<KeyVaultGetSecretsResponse>(&resp_body)
200199
.with_context(ErrorKind::DataConversion, || {
201-
format!(
202-
"failed to parse KeyVaultGetSecretsResponse. resp_body: {}",
203-
resp_body
204-
)
200+
format!("failed to parse KeyVaultGetSecretsResponse. resp_body: {resp_body}")
205201
})?;
206202

207203
secrets.extend(
@@ -262,10 +258,7 @@ impl<'a, T: TokenCredential> KeyClient<'a, T> {
262258
let resp_body = self.get_authed(uri.to_string()).await?;
263259
let response = serde_json::from_str::<KeyVaultGetSecretsResponse>(&resp_body)
264260
.with_context(ErrorKind::DataConversion, || {
265-
format!(
266-
"failed to parse KeyVaultGetSecretsResponse. resp_body: {}",
267-
resp_body
268-
)
261+
format!("failed to parse KeyVaultGetSecretsResponse. resp_body: {resp_body}")
269262
})?;
270263

271264
secret_versions.extend(
@@ -336,7 +329,7 @@ impl<'a, T: TokenCredential> KeyClient<'a, T> {
336329
self.put_authed(uri.to_string(), Value::Object(request_body).to_string())
337330
.await
338331
.with_context(ErrorKind::Other, || {
339-
format!("failed to set secret. secret_name: {}", secret_name)
332+
format!("failed to set secret. secret_name: {secret_name}")
340333
})?;
341334

342335
Ok(())
@@ -380,7 +373,7 @@ impl<'a, T: TokenCredential> KeyClient<'a, T> {
380373
self.update_secret(secret_name, secret_version, attributes)
381374
.await
382375
.with_context(ErrorKind::Other, || {
383-
format!("failed to update secret, secret_name: {}", secret_name)
376+
format!("failed to update secret, secret_name: {secret_name}")
384377
})?;
385378

386379
Ok(())
@@ -562,8 +555,7 @@ impl<'a, T: TokenCredential> KeyClient<'a, T> {
562555
let backup_blob = serde_json::from_str::<KeyVaultSecretBackupResponseRaw>(&response_body)
563556
.with_context(ErrorKind::DataConversion, || {
564557
format!(
565-
"failed to parse secret backup response. secret_name: {} response: {}",
566-
secret_name, response_body
558+
"failed to parse secret backup response. secret_name: {secret_name} response: {response_body}"
567559
)
568560
})?;
569561

0 commit comments

Comments
 (0)