Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use reqwest build_split #4039

Merged
merged 2 commits into from Apr 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 4 additions & 17 deletions object_store/src/aws/credential.rs
Expand Up @@ -81,8 +81,6 @@ const HASH_HEADER: &str = "x-amz-content-sha256";
const TOKEN_HEADER: &str = "x-amz-security-token";
const AUTH_HEADER: &str = "authorization";

const ALL_HEADERS: &[&str; 4] = &[DATE_HEADER, HASH_HEADER, TOKEN_HEADER, AUTH_HEADER];

impl<'a> RequestSigner<'a> {
fn sign(&self, request: &mut Request, pre_calculated_digest: Option<Vec<u8>>) {
if let Some(ref token) = self.credential.token {
Expand Down Expand Up @@ -175,20 +173,15 @@ pub trait CredentialExt {

impl CredentialExt for RequestBuilder {
fn with_aws_sigv4(
mut self,
self,
credential: &AwsCredential,
region: &str,
service: &str,
sign_payload: bool,
payload_sha256: Option<Vec<u8>>,
) -> Self {
// Hack around lack of access to underlying request
// https://github.com/seanmonstar/reqwest/issues/1212
let mut request = self
.try_clone()
.expect("not stream")
.build()
.expect("request valid");
let (client, request) = self.build_split();
let mut request = request.expect("request valid");

let date = Utc::now();
let signer = RequestSigner {
Expand All @@ -200,13 +193,7 @@ impl CredentialExt for RequestBuilder {
};

signer.sign(&mut request, payload_sha256);

for header in ALL_HEADERS {
if let Some(val) = request.headers_mut().remove(*header) {
self = self.header(*header, val)
}
}
self
Self::from_parts(client, request)
}
}

Expand Down
36 changes: 15 additions & 21 deletions object_store/src/azure/credential.rs
Expand Up @@ -124,39 +124,33 @@ impl CredentialExt for RequestBuilder {
.header(DATE, &date_val)
.header(&VERSION, &AZURE_VERSION);

// Hack around lack of access to underlying request
// https://github.com/seanmonstar/reqwest/issues/1212
let request = self
.try_clone()
.expect("not stream")
.build()
.expect("request valid");

match credential {
AzureCredential::AccessKey(key) => {
let (client, request) = self.build_split();
let mut request = request.expect("request valid");

let signature = generate_authorization(
request.headers(),
request.url(),
request.method(),
account,
key.as_str(),
);
self = self
// "signature" is a base 64 encoded string so it should never contain illegal characters.
.header(
AUTHORIZATION,
HeaderValue::from_str(signature.as_str()).unwrap(),
);

// "signature" is a base 64 encoded string so it should never
// contain illegal characters
request.headers_mut().append(
AUTHORIZATION,
HeaderValue::from_str(signature.as_str()).unwrap(),
);

Self::from_parts(client, request)
}
AzureCredential::AuthorizationToken(token) => {
self = self.header(AUTHORIZATION, token);
self.header(AUTHORIZATION, token)
}
AzureCredential::SASToken(query_pairs) => {
self = self.query(&query_pairs);
}
};

self
AzureCredential::SASToken(query_pairs) => self.query(&query_pairs),
}
}
}

Expand Down