Skip to content

Commit 25d9161

Browse files
Override service version if requested (#1673)
1 parent 60a9c14 commit 25d9161

3 files changed

Lines changed: 95 additions & 27 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
## 2.4.2 (Unreleased)
2+
**Bug Fixes**
3+
- [#1630](https://github.com/Azure/azure-storage-fuse/issues/1426) Added support to mount special containers in `mount all` command.
4+
- [#1647](https://github.com/Azure/azure-storage-fuse/issues/1647) Provide detailed error when authentication fails.
5+
26
**Features**
37
- Added `Client Assertion` based authentication for containers. Configure `tenant-id, client-id, aad-application-id and security scope` with `authMode` set to `workloadidentity`.
8+
- Use `AZURE_STORAGE_SERVICE_API_VERSION` to override the `x-ms-version` parameter in REST calls.
49
- Auto detection of account-type (block/adls) when user has not provided the type explicitly.
510

6-
**Bug Fixes**
7-
[#1630](https://github.com/Azure/azure-storage-fuse/issues/1426) Added support to mount special containers in `mount all` command.
8-
[#1647](https://github.com/Azure/azure-storage-fuse/issues/1647) Provide detailed error when authentication fails.
9-
1011
## 2.4.1 (2025-02-18)
1112
**Bug Fixes**
1213
- Create block pool only in the child process.

component/azstorage/policies.go

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
_____ _____ _____ ____ ______ _____ ------
3+
| | | | | | | | | | | | |
4+
| | | | | | | | | | | | |
5+
| --- | | | | |-----| |---- | | |-----| |----- ------
6+
| | | | | | | | | | | | |
7+
| ____| |_____ | ____| | ____| | |_____| _____| |_____ |_____
8+
9+
10+
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
11+
12+
Copyright © 2020-2025 Microsoft Corporation. All rights reserved.
13+
Author : <blobfusedev@microsoft.com>
14+
15+
Permission is hereby granted, free of charge, to any person obtaining a copy
16+
of this software and associated documentation files (the "Software"), to deal
17+
in the Software without restriction, including without limitation the rights
18+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19+
copies of the Software, and to permit persons to whom the Software is
20+
furnished to do so, subject to the following conditions:
21+
22+
The above copyright notice and this permission notice shall be included in all
23+
copies or substantial portions of the Software.
24+
25+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31+
SOFTWARE
32+
*/
33+
34+
package azstorage
35+
36+
import (
37+
"fmt"
38+
"net/http"
39+
40+
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
41+
"github.com/Azure/azure-storage-fuse/v2/common"
42+
)
43+
44+
// blobfuseTelemetryPolicy is a custom pipeline policy to prepend the blobfuse user agent string to the one coming from SDK.
45+
// This is added in the PerCallPolicies which executes after the SDK's default telemetry policy.
46+
type blobfuseTelemetryPolicy struct {
47+
telemetryValue string
48+
}
49+
50+
// newBlobfuseTelemetryPolicy creates an object which prepends the blobfuse user agent string to the User-Agent request header
51+
func newBlobfuseTelemetryPolicy(telemetryValue string) policy.Policy {
52+
return &blobfuseTelemetryPolicy{telemetryValue: telemetryValue}
53+
}
54+
55+
func (p blobfuseTelemetryPolicy) Do(req *policy.Request) (*http.Response, error) {
56+
userAgent := p.telemetryValue
57+
58+
// prepend the blobfuse user agent string
59+
if ua := req.Raw().Header.Get(common.UserAgentHeader); ua != "" {
60+
userAgent = fmt.Sprintf("%s %s", userAgent, ua)
61+
}
62+
req.Raw().Header.Set(common.UserAgentHeader, userAgent)
63+
return req.Next()
64+
}
65+
66+
// ---------------------------------------------------------------------------------------------------------------------------------------------------
67+
// Policy to override the service version if requested by user
68+
type serviceVersionPolicy struct {
69+
serviceApiVersion string
70+
}
71+
72+
func newServiceVersionPolicy(version string) policy.Policy {
73+
return &serviceVersionPolicy{
74+
serviceApiVersion: version,
75+
}
76+
}
77+
78+
func (r *serviceVersionPolicy) Do(req *policy.Request) (*http.Response, error) {
79+
req.Raw().Header["x-ms-version"] = []string{r.serviceApiVersion}
80+
return req.Next()
81+
}

component/azstorage/utils.go

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,18 @@ func getAzStorageClientOptions(conf *AzStorageConfig) (azcore.ClientOptions, err
106106
log.Err("utils::getAzStorageClientOptions : Failed to create transport client [%s]", err.Error())
107107
}
108108

109+
perCallPolicies := []policy.Policy{telemetryPolicy}
110+
111+
serviceApiVersion := os.Getenv("AZURE_STORAGE_SERVICE_API_VERSION")
112+
if serviceApiVersion != "" {
113+
// We need to override the service version
114+
perCallPolicies = append(perCallPolicies, newServiceVersionPolicy(serviceApiVersion))
115+
}
116+
109117
return azcore.ClientOptions{
110118
Retry: retryOptions,
111119
Logging: logOptions,
112-
PerCallPolicies: []policy.Policy{telemetryPolicy},
120+
PerCallPolicies: perCallPolicies,
113121
Transport: transportOptions,
114122
}, err
115123
}
@@ -207,28 +215,6 @@ func getCloudConfiguration(endpoint string) cloud.Configuration {
207215
}
208216
}
209217

210-
// blobfuseTelemetryPolicy is a custom pipeline policy to prepend the blobfuse user agent string to the one coming from SDK.
211-
// This is added in the PerCallPolicies which executes after the SDK's default telemetry policy.
212-
type blobfuseTelemetryPolicy struct {
213-
telemetryValue string
214-
}
215-
216-
// newBlobfuseTelemetryPolicy creates an object which prepends the blobfuse user agent string to the User-Agent request header
217-
func newBlobfuseTelemetryPolicy(telemetryValue string) policy.Policy {
218-
return &blobfuseTelemetryPolicy{telemetryValue: telemetryValue}
219-
}
220-
221-
func (p blobfuseTelemetryPolicy) Do(req *policy.Request) (*http.Response, error) {
222-
userAgent := p.telemetryValue
223-
224-
// prepend the blobfuse user agent string
225-
if ua := req.Raw().Header.Get(common.UserAgentHeader); ua != "" {
226-
userAgent = fmt.Sprintf("%s %s", userAgent, ua)
227-
}
228-
req.Raw().Header.Set(common.UserAgentHeader, userAgent)
229-
return req.Next()
230-
}
231-
232218
// ----------- Store error code handling ---------------
233219
const (
234220
ErrNoErr uint16 = iota

0 commit comments

Comments
 (0)