Repository navigation
Version all Azure requests #21366
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
Version all Azure requests #21366
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,43 @@ | ||
| use http::Extensions; | ||
| use std::fmt::Debug; | ||
| use uv_auth::AzureEndpointProvider; | ||
| use uv_preview::Preview; | ||
| use uv_redacted::DisplaySafeUrl; | ||
|
|
||
| use reqwest::header::HeaderValue; | ||
| use reqwest::{Request, Response}; | ||
| use reqwest_middleware::{Middleware, Next}; | ||
|
|
||
| pub(crate) struct AzureStorageMiddleware { | ||
| pub(crate) preview: Preview, | ||
| } | ||
|
|
||
| #[async_trait::async_trait] | ||
| impl Middleware for AzureStorageMiddleware { | ||
| async fn handle( | ||
| &self, | ||
| mut request: Request, | ||
| extensions: &mut Extensions, | ||
| next: Next<'_>, | ||
| ) -> reqwest_middleware::Result<Response> { | ||
| if AzureEndpointProvider::is_azure_endpoint(request.url(), self.preview)? { | ||
| // Anonymous requests need 2019-12-12 or later to return a 401 | ||
| // bearer challenge instead of 409 when account-level public access | ||
| // is disabled. Use the earliest such version supported by Azure | ||
| // Stack Hub (2301 and later). | ||
| // | ||
| // https://learn.microsoft.com/en-us/rest/api/storageservices/authorize-with-azure-active-directory#bearer-challenge | ||
| // https://learn.microsoft.com/en-us/azure-stack/user/azure-stack-acs-differences#api-version | ||
| request | ||
| .headers_mut() | ||
| .entry("x-ms-version") | ||
| .or_insert(HeaderValue::from_static("2020-10-02")); | ||
|
Comment on lines
+31
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a Useful? React with 👍 / 👎.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like this was previously dismissed? |
||
| } | ||
|
|
||
| next.run(request, extensions).await | ||
| } | ||
| } | ||
|
|
||
| /// A custom error type for the offline middleware. | ||
| #[derive(Debug, Clone, PartialEq, Eq)] | ||
| pub(crate) struct OfflineError { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a caller explicitly supplies an
x-ms-versionolder than 2019-12-12, the new middleware intentionally preserves it viaor_insert, so a private Azure blob can still answer the anonymous request with409 PublicAccessNotPermitted. This status check now returns that response immediately instead of discovering Azure credentials, even though the removedresponse_requires_authenticationpath handled precisely this case; retain the targeted 409 fallback for requests whose explicit version is not upgraded.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably don't need to handle this