Skip to content

Commit c1b3f82

Browse files
committed
Clean up unwrap, refactor
1 parent 9a7d14c commit c1b3f82

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/client/auth/aws.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,6 @@ pub async fn compute_aws_sigv4_payload(
221221
host: &str,
222222
server_nonce: &[u8],
223223
) -> Result<Document> {
224-
let date_str = date.format("%Y%m%dT%H%M%SZ").to_string();
225-
226224
let region = if host == "sts.amazonaws.com" {
227225
"us-east-1"
228226
} else {
@@ -231,7 +229,7 @@ pub async fn compute_aws_sigv4_payload(
231229
};
232230

233231
let url = format!("https://{}", host);
234-
let service = "sts";
232+
let date_str = date.format("%Y%m%dT%H%M%SZ").to_string();
235233
let body_str = "Action=GetCallerIdentity&Version=2011-06-15";
236234
let body_bytes = body_str.as_bytes();
237235
let nonce_b64 = base64::encode(server_nonce);
@@ -255,6 +253,7 @@ pub async fn compute_aws_sigv4_payload(
255253
Error::authentication_error(MECH_NAME, &format!("Failed to build request: {e}"))
256254
})?;
257255

256+
let service = "sts";
258257
let identity = creds.into();
259258

260259
// Set up signing parameters
@@ -274,24 +273,24 @@ pub async fn compute_aws_sigv4_payload(
274273
let signable_request = SignableRequest::new(
275274
request.method().as_str(),
276275
request.uri().to_string(),
277-
request
278-
.headers()
279-
.iter()
280-
.map(|(k, v)| (k.as_str(), std::str::from_utf8(v.as_bytes()).unwrap())),
276+
request.headers().iter().map(|(k, v)| {
277+
(
278+
k.as_str(),
279+
std::str::from_utf8(v.as_bytes()).expect("Header value should be valid UTF-8"),
280+
)
281+
}),
281282
SignableBody::Bytes(request.body().as_bytes()),
282283
)
283284
.map_err(|e| {
284285
Error::authentication_error(MECH_NAME, &format!("Failed to create SignableRequest: {e}"))
285286
})?;
286287

287-
// Sign the request
288288
let (signing_instructions, _signature) = sign(signable_request, &signing_params)
289289
.map_err(|e| Error::authentication_error(MECH_NAME, &format!("Signing failed: {e}")))?
290290
.into_parts();
291291

292292
signing_instructions.apply_to_request_http1x(&mut request);
293293

294-
// Extract the Authorization header
295294
let headers = request.headers();
296295
let authorization_header = headers
297296
.get("authorization")

0 commit comments

Comments
 (0)