-
Notifications
You must be signed in to change notification settings - Fork 224
/
Copy pathconfig.go
617 lines (515 loc) · 23.8 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
/*
_____ _____ _____ ____ ______ _____ ------
| | | | | | | | | | | | |
| | | | | | | | | | | | |
| --- | | | | |-----| |---- | | |-----| |----- ------
| | | | | | | | | | | | |
| ____| |_____ | ____| | ____| | |_____| _____| |_____ |_____
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
Copyright © 2020-2025 Microsoft Corporation. All rights reserved.
Author : <[email protected]>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE
*/
package azstorage
import (
"errors"
"fmt"
"reflect"
"strings"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/blockblob"
"github.com/Azure/azure-storage-fuse/v2/common/config"
"github.com/Azure/azure-storage-fuse/v2/common/log"
"github.com/vibhansa-msft/blobfilter"
"github.com/JeffreyRichter/enum/enum"
)
// AuthType Enum
type AuthType int
var EAuthType = AuthType(0).INVALID_AUTH()
func (AuthType) INVALID_AUTH() AuthType {
return AuthType(0)
}
func (AuthType) KEY() AuthType {
return AuthType(1)
}
func (AuthType) SAS() AuthType {
return AuthType(2)
}
func (AuthType) SPN() AuthType {
return AuthType(3)
}
func (AuthType) MSI() AuthType {
return AuthType(4)
}
func (AuthType) AZCLI() AuthType {
return AuthType(5)
}
func (a AuthType) String() string {
return enum.StringInt(a, reflect.TypeOf(a))
}
func (a *AuthType) Parse(s string) error {
enumVal, err := enum.ParseInt(reflect.TypeOf(a), s, true, false)
if enumVal != nil {
*a = enumVal.(AuthType)
}
return err
}
// AccountType Enum
type AccountType int
var EAccountType = AccountType(0).INVALID_ACC()
func (AccountType) INVALID_ACC() AccountType {
return AccountType(0)
}
func (AccountType) BLOCK() AccountType {
return AccountType(1)
}
func (AccountType) ADLS() AccountType {
return AccountType(2)
}
func (f AccountType) String() string {
return enum.StringInt(f, reflect.TypeOf(f))
}
func (a *AccountType) Parse(s string) error {
enumVal, err := enum.ParseInt(reflect.TypeOf(a), s, true, false)
if enumVal != nil {
*a = enumVal.(AccountType)
}
return err
}
// default value for maximum results returned by a list API call
const DefaultMaxResultsForList int32 = 2
// Environment variable names
// Here we are not reading MSI_ENDPOINT and MSI_SECRET as they are read by go-sdk directly
// https://github.com/Azure/go-autorest/blob/a46566dfcbdc41e736295f94e9f690ceaf50094a/autorest/adal/token.go#L788
// newServicePrincipalTokenFromMSI : reads them directly from env
const (
EnvAzStorageAccount = "AZURE_STORAGE_ACCOUNT"
EnvAzStorageAccountType = "AZURE_STORAGE_ACCOUNT_TYPE"
EnvAzStorageAccessKey = "AZURE_STORAGE_ACCESS_KEY"
EnvAzStorageSasToken = "AZURE_STORAGE_SAS_TOKEN"
EnvAzStorageIdentityClientId = "AZURE_STORAGE_IDENTITY_CLIENT_ID"
EnvAzStorageIdentityResourceId = "AZURE_STORAGE_IDENTITY_RESOURCE_ID"
EnvAzStorageIdentityObjectId = "AZURE_STORAGE_IDENTITY_OBJECT_ID"
EnvAzStorageSpnTenantId = "AZURE_STORAGE_SPN_TENANT_ID"
EnvAzStorageSpnClientId = "AZURE_STORAGE_SPN_CLIENT_ID"
EnvAzStorageSpnClientSecret = "AZURE_STORAGE_SPN_CLIENT_SECRET"
EnvAzStorageSpnOAuthTokenFilePath = "AZURE_OAUTH_TOKEN_FILE"
EnvAzStorageSpnWorkloadIdentityToken = "WORKLOAD_IDENTITY_TOKEN"
EnvAzStorageAadEndpoint = "AZURE_STORAGE_AAD_ENDPOINT"
EnvAzStorageAuthType = "AZURE_STORAGE_AUTH_TYPE"
EnvAzStorageBlobEndpoint = "AZURE_STORAGE_BLOB_ENDPOINT"
EnvAzStorageAccountContainer = "AZURE_STORAGE_ACCOUNT_CONTAINER"
EnvAzAuthResource = "AZURE_STORAGE_AUTH_RESOURCE"
EnvAzStorageCpkEncryptionKey = "AZURE_STORAGE_CPK_ENCRYPTION_KEY"
EnvAzStorageCpkEncryptionKeySha256 = "AZURE_STORAGE_CPK_ENCRYPTION_KEY_SHA256"
)
type AzStorageOptions struct {
AccountType string `config:"type" yaml:"type,omitempty"`
UseHTTP bool `config:"use-http" yaml:"use-http,omitempty"`
AccountName string `config:"account-name" yaml:"account-name,omitempty"`
AccountKey string `config:"account-key" yaml:"account-key,omitempty"`
SaSKey string `config:"sas" yaml:"sas,omitempty"`
ApplicationID string `config:"appid" yaml:"appid,omitempty"`
ResourceID string `config:"resid" yaml:"resid,omitempty"`
ObjectID string `config:"objid" yaml:"objid,omitempty"`
TenantID string `config:"tenantid" yaml:"tenantid,omitempty"`
ClientID string `config:"clientid" yaml:"clientid,omitempty"`
ClientSecret string `config:"clientsecret" yaml:"clientsecret,omitempty"`
OAuthTokenFilePath string `config:"oauth-token-path" yaml:"oauth-token-path,omitempty"`
WorkloadIdentityToken string `config:"workload-identity-token" yaml:"workload-identity-token,omitempty"`
ActiveDirectoryEndpoint string `config:"aadendpoint" yaml:"aadendpoint,omitempty"`
Endpoint string `config:"endpoint" yaml:"endpoint,omitempty"`
AuthMode string `config:"mode" yaml:"mode,omitempty"`
Container string `config:"container" yaml:"container,omitempty"`
PrefixPath string `config:"subdirectory" yaml:"subdirectory,omitempty"`
BlockSize int64 `config:"block-size-mb" yaml:"block-size-mb,omitempty"`
MaxConcurrency uint16 `config:"max-concurrency" yaml:"max-concurrency,omitempty"`
DefaultTier string `config:"tier" yaml:"tier,omitempty"`
CancelListForSeconds uint16 `config:"block-list-on-mount-sec" yaml:"block-list-on-mount-sec,omitempty"`
MaxRetries int32 `config:"max-retries" yaml:"max-retries,omitempty"`
MaxTimeout int32 `config:"max-retry-timeout-sec" yaml:"max-retry-timeout-sec,omitempty"`
BackoffTime int32 `config:"retry-backoff-sec" yaml:"retry-backoff-sec,omitempty"`
MaxRetryDelay int32 `config:"max-retry-delay-sec" yaml:"max-retry-delay-sec,omitempty"`
HttpProxyAddress string `config:"http-proxy" yaml:"http-proxy,omitempty"`
HttpsProxyAddress string `config:"https-proxy" yaml:"https-proxy,omitempty"`
FailUnsupportedOp bool `config:"fail-unsupported-op" yaml:"fail-unsupported-op,omitempty"`
AuthResourceString string `config:"auth-resource" yaml:"auth-resource,omitempty"`
UpdateMD5 bool `config:"update-md5" yaml:"update-md5"`
ValidateMD5 bool `config:"validate-md5" yaml:"validate-md5"`
VirtualDirectory bool `config:"virtual-directory" yaml:"virtual-directory"`
MaxResultsForList int32 `config:"max-results-for-list" yaml:"max-results-for-list"`
DisableCompression bool `config:"disable-compression" yaml:"disable-compression"`
Telemetry string `config:"telemetry" yaml:"telemetry"`
HonourACL bool `config:"honour-acl" yaml:"honour-acl"`
CPKEnabled bool `config:"cpk-enabled" yaml:"cpk-enabled"`
CPKEncryptionKey string `config:"cpk-encryption-key" yaml:"cpk-encryption-key"`
CPKEncryptionKeySha256 string `config:"cpk-encryption-key-sha256" yaml:"cpk-encryption-key-sha256"`
PreserveACL bool `config:"preserve-acl" yaml:"preserve-acl"`
Filter string `config:"filter" yaml:"filter"`
// v1 support
UseAdls bool `config:"use-adls" yaml:"-"`
UseHTTPS bool `config:"use-https" yaml:"-"`
SetContentType bool `config:"set-content-type" yaml:"-"`
CaCertFile string `config:"ca-cert-file" yaml:"-"`
}
// RegisterEnvVariables : Register environment varilables
func RegisterEnvVariables() {
config.BindEnv("azstorage.account-name", EnvAzStorageAccount)
config.BindEnv("azstorage.type", EnvAzStorageAccountType)
config.BindEnv("azstorage.account-key", EnvAzStorageAccessKey)
config.BindEnv("azstorage.sas", EnvAzStorageSasToken)
config.BindEnv("azstorage.appid", EnvAzStorageIdentityClientId)
config.BindEnv("azstorage.resid", EnvAzStorageIdentityResourceId)
config.BindEnv("azstorage.tenantid", EnvAzStorageSpnTenantId)
config.BindEnv("azstorage.clientid", EnvAzStorageSpnClientId)
config.BindEnv("azstorage.clientsecret", EnvAzStorageSpnClientSecret)
config.BindEnv("azstorage.oauth-token-path", EnvAzStorageSpnOAuthTokenFilePath)
config.BindEnv("azstorage.workload-identity-token", EnvAzStorageSpnWorkloadIdentityToken)
config.BindEnv("azstorage.objid", EnvAzStorageIdentityObjectId)
config.BindEnv("azstorage.aadendpoint", EnvAzStorageAadEndpoint)
config.BindEnv("azstorage.endpoint", EnvAzStorageBlobEndpoint)
config.BindEnv("azstorage.mode", EnvAzStorageAuthType)
config.BindEnv("azstorage.container", EnvAzStorageAccountContainer)
config.BindEnv("azstorage.auth-resource", EnvAzAuthResource)
config.BindEnv("azstorage.cpk-encryption-key", EnvAzStorageCpkEncryptionKey)
config.BindEnv("azstorage.cpk-encryption-key-sha256", EnvAzStorageCpkEncryptionKeySha256)
}
// ----------- Config Parsing and Validation ---------------
// formatEndpointProtocol : add the protocol and missing "/" at the end to the endpoint
func formatEndpointProtocol(endpoint string, http bool) string {
correctedEndpoint := endpoint
// If the pvtEndpoint does not have protocol mentioned in front, pvtEndpoint parsing will fail while
// creating URI also the string shall end with "/"
if correctedEndpoint != "" {
if !(strings.HasPrefix(correctedEndpoint, "https://") ||
strings.HasPrefix(correctedEndpoint, "http://")) {
if http {
correctedEndpoint = "http://" + correctedEndpoint
} else {
correctedEndpoint = "https://" + correctedEndpoint
}
}
if correctedEndpoint[len(correctedEndpoint)-1] != '/' {
correctedEndpoint = correctedEndpoint + "/"
}
}
return correctedEndpoint
}
// formatEndpointAccountType : format the endpoint to match the account type
func formatEndpointAccountType(endpoint string, account AccountType) string {
// TODO : Modify this method when file share support is merged
correctedEndpoint := endpoint
if strings.Contains(correctedEndpoint, ".blob.") {
if account == EAccountType.ADLS() {
correctedEndpoint = strings.Replace(correctedEndpoint, ".blob.", ".dfs.", 1)
}
} else if strings.Contains(correctedEndpoint, ".dfs.") {
if account == EAccountType.BLOCK() {
correctedEndpoint = strings.Replace(correctedEndpoint, ".dfs.", ".blob.", 1)
}
}
return correctedEndpoint
}
func validateMsiConfig(opt AzStorageOptions) error {
v := make(map[string]bool, 3)
if opt.ApplicationID != "" {
v[opt.ApplicationID] = true
}
if opt.ObjectID != "" {
v[opt.ObjectID] = true
}
if opt.ResourceID != "" {
v[opt.ResourceID] = true
}
if len(v) > 1 {
return errors.New("client ID, object ID and MSI resource ID are mutually exclusive and zero or one of the inputs need to be provided")
}
return nil
}
// ParseAndValidateConfig : Parse and validate config
func ParseAndValidateConfig(az *AzStorage, opt AzStorageOptions) error {
log.Trace("ParseAndValidateConfig : Parsing config")
// Validate account name is present or not
if opt.AccountName == "" {
return errors.New("account name not provided")
}
az.stConfig.authConfig.AccountName = opt.AccountName
// Validate account type property
if opt.AccountType == "" {
opt.AccountType = "block"
}
if config.IsSet(compName + ".use-adls") {
if opt.UseAdls {
az.stConfig.authConfig.AccountType = az.stConfig.authConfig.AccountType.ADLS()
} else {
az.stConfig.authConfig.AccountType = az.stConfig.authConfig.AccountType.BLOCK()
}
} else {
var accountType AccountType
err := accountType.Parse(opt.AccountType)
if err != nil {
log.Err("ParseAndValidateConfig : Failed to parse account type %s", opt.AccountType)
return errors.New("invalid account type")
}
if accountType == EAccountType.INVALID_ACC() {
log.Err("ParseAndValidateConfig : Invalid account type %s", opt.AccountType)
return errors.New("invalid account type")
}
az.stConfig.authConfig.AccountType = accountType
}
if opt.BlockSize != 0 {
if opt.BlockSize > blockblob.MaxStageBlockBytes {
log.Err("ParseAndValidateConfig : Block size is too large. Block size has to be smaller than %s Bytes", blockblob.MaxStageBlockBytes)
return errors.New("block size is too large")
}
az.stConfig.blockSize = opt.BlockSize * 1024 * 1024
}
// Validate container name is present or not
err := config.UnmarshalKey("mount-all-containers", &az.stConfig.mountAllContainers)
if err != nil {
log.Err("ParseAndValidateConfig : Failed to detect mount-all-container")
}
if !az.stConfig.mountAllContainers && opt.Container == "" {
return errors.New("container name not provided")
}
az.stConfig.container = opt.Container
if config.IsSet(compName + ".use-https") {
opt.UseHTTP = !opt.UseHTTPS
}
if opt.CPKEnabled {
if opt.CPKEncryptionKey == "" || opt.CPKEncryptionKeySha256 == "" {
log.Err("ParseAndValidateConfig : CPK key or CPK key sha256 not provided")
return errors.New("CPK key or key sha256 not provided")
}
az.stConfig.cpkEnabled = opt.CPKEnabled
az.stConfig.cpkEncryptionKey = opt.CPKEncryptionKey
az.stConfig.cpkEncryptionKeySha256 = opt.CPKEncryptionKeySha256
}
// Validate endpoint
if opt.Endpoint == "" {
log.Warn("ParseAndValidateConfig : account endpoint not provided, assuming the default .core.windows.net style endpoint")
if az.stConfig.authConfig.AccountType == EAccountType.BLOCK() {
opt.Endpoint = fmt.Sprintf("%s.blob.core.windows.net", opt.AccountName)
} else if az.stConfig.authConfig.AccountType == EAccountType.ADLS() {
opt.Endpoint = fmt.Sprintf("%s.dfs.core.windows.net", opt.AccountName)
}
}
az.stConfig.authConfig.Endpoint = opt.Endpoint
az.stConfig.authConfig.Endpoint = formatEndpointProtocol(az.stConfig.authConfig.Endpoint, opt.UseHTTP)
az.stConfig.authConfig.Endpoint = formatEndpointAccountType(az.stConfig.authConfig.Endpoint, az.stConfig.authConfig.AccountType)
az.stConfig.authConfig.ActiveDirectoryEndpoint = opt.ActiveDirectoryEndpoint
az.stConfig.authConfig.ActiveDirectoryEndpoint = formatEndpointProtocol(az.stConfig.authConfig.ActiveDirectoryEndpoint, false)
// If subdirectory is mounted, take the prefix path
az.stConfig.prefixPath = removeLeadingSlashes(opt.PrefixPath)
// Block list call on mount for given amount of time
az.stConfig.cancelListForSeconds = opt.CancelListForSeconds
az.stConfig.telemetry = opt.Telemetry
httpProxyProvided := opt.HttpProxyAddress != ""
httpsProxyProvided := opt.HttpsProxyAddress != ""
// Set whether to use http or https and proxy
if opt.UseHTTP {
az.stConfig.authConfig.UseHTTP = true
if httpProxyProvided {
az.stConfig.proxyAddress = opt.HttpProxyAddress
} else if httpsProxyProvided {
az.stConfig.proxyAddress = opt.HttpsProxyAddress
}
} else {
if httpsProxyProvided {
az.stConfig.proxyAddress = opt.HttpsProxyAddress
} else {
if httpProxyProvided {
log.Err("ParseAndValidateConfig : `http-proxy` Invalid : must set `use-http: true` in your config file")
return errors.New("`http-proxy` Invalid : must set `use-http: true` in your config file")
}
}
}
az.stConfig.proxyAddress = formatEndpointProtocol(az.stConfig.proxyAddress, opt.UseHTTP)
log.Info("ParseAndValidateConfig : using the following proxy address from the config file: %s", az.stConfig.proxyAddress)
err = ParseAndReadDynamicConfig(az, opt, false)
if err != nil {
return err
}
log.Debug("ParseAndValidateConfig : Getting auth type")
if opt.AuthMode == "" {
// Based on other config decide the auth mode
// for e.g. if sas token is set then mode shall be set to sas and if key is set then authmode shall be key
opt.AuthMode = autoDetectAuthMode(opt)
log.Debug("ParseAndValidateConfig : Auth type %s", opt.AuthMode)
}
var authType AuthType
err = authType.Parse(opt.AuthMode)
if err != nil {
log.Err("ParseAndValidateConfig : Invalid auth type %s", opt.AccountType)
return errors.New("invalid auth type")
}
az.stConfig.authConfig.ObjectID = opt.ObjectID
switch authType {
case EAuthType.KEY():
az.stConfig.authConfig.AuthMode = EAuthType.KEY()
if opt.AccountKey == "" {
return errors.New("storage key not provided")
}
az.stConfig.authConfig.AccountKey = opt.AccountKey
case EAuthType.SAS():
az.stConfig.authConfig.AuthMode = EAuthType.SAS()
if opt.SaSKey == "" {
return errors.New("SAS key not provided")
}
az.stConfig.authConfig.SASKey = sanitizeSASKey(opt.SaSKey)
case EAuthType.MSI():
az.stConfig.authConfig.AuthMode = EAuthType.MSI()
err := validateMsiConfig(opt)
if err != nil {
return err
}
az.stConfig.authConfig.ApplicationID = opt.ApplicationID
az.stConfig.authConfig.ResourceID = opt.ResourceID
case EAuthType.SPN():
az.stConfig.authConfig.AuthMode = EAuthType.SPN()
if opt.ClientID == "" || (opt.ClientSecret == "" && opt.OAuthTokenFilePath == "" && opt.WorkloadIdentityToken == "") || opt.TenantID == "" {
//lint:ignore ST1005 ignore
return errors.New("Client ID, Tenant ID or Client Secret, OAuthTokenFilePath, WorkloadIdentityToken not provided")
}
az.stConfig.authConfig.ClientID = opt.ClientID
az.stConfig.authConfig.ClientSecret = opt.ClientSecret
az.stConfig.authConfig.TenantID = opt.TenantID
az.stConfig.authConfig.OAuthTokenFilePath = opt.OAuthTokenFilePath
az.stConfig.authConfig.WorkloadIdentityToken = opt.WorkloadIdentityToken
case EAuthType.AZCLI():
az.stConfig.authConfig.AuthMode = EAuthType.AZCLI()
default:
log.Err("ParseAndValidateConfig : Invalid auth mode %s", opt.AuthMode)
return errors.New("invalid auth mode")
}
az.stConfig.authConfig.AuthResource = opt.AuthResourceString
// Retry policy configuration
// A user provided value of 0 doesn't make sense for MaxRetries, MaxTimeout, BackoffTime, or MaxRetryDelay.
az.stConfig.maxRetries = 5 // Max number of retry to be done (default 4) (v1 : 0)
az.stConfig.maxTimeout = 900 // Max timeout for any single retry (default 1 min) (v1 : 60)
az.stConfig.backoffTime = 4 // Delay before any retry (exponential increase) (default 4 sec)
az.stConfig.maxRetryDelay = 60 // Maximum allowed delay before retry (default 120 sec) (v1 : 1.2)
if opt.MaxRetries != 0 {
az.stConfig.maxRetries = opt.MaxRetries
}
if opt.MaxTimeout != 0 {
az.stConfig.maxTimeout = opt.MaxTimeout
}
if opt.BackoffTime != 0 {
az.stConfig.backoffTime = opt.BackoffTime
}
if opt.MaxRetryDelay != 0 {
az.stConfig.maxRetryDelay = opt.MaxRetryDelay
}
if config.IsSet(compName + ".set-content-type") {
log.Warn("unsupported v1 CLI parameter: set-content-type is always true in blobfuse2.")
}
if config.IsSet(compName + ".ca-cert-file") {
log.Warn("unsupported v1 CLI parameter: ca-cert-file is not supported in blobfuse2. Use the default ca cert path for your environment.")
}
if config.IsSet(compName + ".debug-libcurl") {
log.Warn("unsupported v1 CLI parameter: debug-libcurl is not applicable in blobfuse2.")
}
az.stConfig.preserveACL = opt.PreserveACL
if opt.Filter != "" {
err = configureBlobFilter(az, opt)
if err != nil {
return err
}
}
log.Crit("ParseAndValidateConfig : account %s, container %s, account-type %s, auth %s, prefix %s, endpoint %s, MD5 %v %v, virtual-directory %v, disable-compression %v, CPK %v",
az.stConfig.authConfig.AccountName, az.stConfig.container, az.stConfig.authConfig.AccountType, az.stConfig.authConfig.AuthMode,
az.stConfig.prefixPath, az.stConfig.authConfig.Endpoint, az.stConfig.validateMD5, az.stConfig.updateMD5, az.stConfig.virtualDirectory, az.stConfig.disableCompression, az.stConfig.cpkEnabled)
log.Crit("ParseAndValidateConfig : use-HTTP %t, block-size %d, max-concurrency %d, default-tier %s, fail-unsupported-op %t, mount-all-containers %t", az.stConfig.authConfig.UseHTTP, az.stConfig.blockSize, az.stConfig.maxConcurrency, az.stConfig.defaultTier, az.stConfig.ignoreAccessModifiers, az.stConfig.mountAllContainers)
log.Crit("ParseAndValidateConfig : Retry Config: retry-count %d, max-timeout %d, backoff-time %d, max-delay %d, preserve-acl: %v",
az.stConfig.maxRetries, az.stConfig.maxTimeout, az.stConfig.backoffTime, az.stConfig.maxRetryDelay, az.stConfig.preserveACL)
log.Crit("ParseAndValidateConfig : Telemetry : %s, honour-ACL %v", az.stConfig.telemetry, az.stConfig.honourACL)
return nil
}
func configureBlobFilter(azStorage *AzStorage, opt AzStorageOptions) error {
readonly := false
_ = config.UnmarshalKey("read-only", &readonly)
if !readonly {
log.Err("configureBlobFilter: Blob filters are supported only in read-only mode")
return errors.New("blobfilter is supported only in read-only mode")
}
azStorage.stConfig.filter = &blobfilter.BlobFilter{}
err := azStorage.stConfig.filter.Configure(opt.Filter)
if err != nil {
log.Err("configureBlobFilter : Failed to configure blob filter %s", err.Error())
return errors.New("failed to configure blob filter")
}
log.Crit("configureBlobFilter : Blob filter configured %s", opt.Filter)
return nil
}
// ParseAndReadDynamicConfig : On config change read only the required config
func ParseAndReadDynamicConfig(az *AzStorage, opt AzStorageOptions, reload bool) error {
log.Trace("ParseAndReadDynamicConfig : Reparsing config")
// If block size and max concurrency is configured use those
// A user provided value of 0 doesn't make sense for BlockSize, or MaxConcurrency.
if opt.BlockSize != 0 {
az.stConfig.blockSize = opt.BlockSize * 1024 * 1024
}
if opt.MaxConcurrency != 0 {
az.stConfig.maxConcurrency = opt.MaxConcurrency
}
// Populate default tier
if opt.DefaultTier != "" {
az.stConfig.defaultTier = getAccessTierType(opt.DefaultTier)
}
az.stConfig.ignoreAccessModifiers = !opt.FailUnsupportedOp
az.stConfig.validateMD5 = opt.ValidateMD5
az.stConfig.updateMD5 = opt.UpdateMD5
if config.IsSet(compName + ".virtual-directory") {
az.stConfig.virtualDirectory = opt.VirtualDirectory
} else {
az.stConfig.virtualDirectory = true
}
if config.IsSet(compName+".max-results-for-list") && opt.MaxResultsForList > 0 {
az.stConfig.maxResultsForList = opt.MaxResultsForList
} else {
az.stConfig.maxResultsForList = DefaultMaxResultsForList
}
if config.IsSet(compName + ".disable-compression") {
az.stConfig.disableCompression = opt.DisableCompression
} else {
az.stConfig.disableCompression = DisableCompression
}
if config.IsSet(compName + ".honour-acl") {
az.stConfig.honourACL = opt.HonourACL
} else {
az.stConfig.honourACL = false
}
// Auth related reconfig
switch opt.AuthMode {
case "sas":
az.stConfig.authConfig.AuthMode = EAuthType.SAS()
if opt.SaSKey == "" {
return errors.New("SAS key not provided")
}
oldSas := az.stConfig.authConfig.SASKey
az.stConfig.authConfig.SASKey = sanitizeSASKey(opt.SaSKey)
if reload {
log.Info("ParseAndReadDynamicConfig : SAS Key updated")
if err := az.storage.UpdateServiceClient("saskey", az.stConfig.authConfig.SASKey); err != nil {
az.stConfig.authConfig.SASKey = oldSas
_ = az.storage.UpdateServiceClient("saskey", az.stConfig.authConfig.SASKey)
return errors.New("SAS key update failure")
}
}
}
return nil
}