@@ -118,6 +118,8 @@ func getStorage(rootCfg ConfigProvider, name, typ string, sec ConfigSection) (*S
118
118
return getStorageForLocal (targetSec , overrideSec , tp , name )
119
119
case string (MinioStorageType ):
120
120
return getStorageForMinio (targetSec , overrideSec , tp , name )
121
+ case string (AzureBlobStorageType ):
122
+ return getStorageForAzureBlob (targetSec , overrideSec , tp , name )
121
123
default :
122
124
return nil , fmt .Errorf ("unsupported storage type %q" , targetType )
123
125
}
@@ -251,22 +253,6 @@ func getStorageForLocal(targetSec, overrideSec ConfigSection, tp targetSecType,
251
253
storage .Path = filepath .Join (targetPath , storage .Path )
252
254
}
253
255
}
254
- case string (AzureBlobStorageType ):
255
- storage .AzureBlobConfig .BasePath = name + "/"
256
-
257
- if err := targetSec .MapTo (& storage .AzureBlobConfig ); err != nil {
258
- return nil , fmt .Errorf ("map azure blob config failed: %v" , err )
259
- }
260
- // extra config section will be read SERVE_DIRECT, PATH, MINIO_BASE_PATH to override the targetsec
261
- extraConfigSec := sec
262
- if extraConfigSec == nil {
263
- extraConfigSec = storageNameSec
264
- }
265
-
266
- if extraConfigSec != nil {
267
- storage .AzureBlobConfig .BasePath = ConfigSectionKeyString (extraConfigSec , "AZUREBLOB_BASE_PATH" , storage .AzureBlobConfig .BasePath )
268
- storage .AzureBlobConfig .Container = ConfigSectionKeyString (extraConfigSec , "AZUREBLOB_CONTAINER" , storage .AzureBlobConfig .Container )
269
- }
270
256
}
271
257
272
258
return & storage , nil
@@ -300,3 +286,31 @@ func getStorageForMinio(targetSec, overrideSec ConfigSection, tp targetSecType,
300
286
}
301
287
return & storage , nil
302
288
}
289
+
290
+ func getStorageForAzureBlob (targetSec , overrideSec ConfigSection , tp targetSecType , name string ) (* Storage , error ) {
291
+ var storage Storage
292
+ storage .Type = StorageType (targetSec .Key ("STORAGE_TYPE" ).String ())
293
+ if err := targetSec .MapTo (& storage .AzureBlobConfig ); err != nil {
294
+ return nil , fmt .Errorf ("map azure blob config failed: %v" , err )
295
+ }
296
+
297
+ var defaultPath string
298
+ if storage .AzureBlobConfig .BasePath != "" {
299
+ if tp == targetSecIsStorage || tp == targetSecIsDefault {
300
+ defaultPath = strings .TrimSuffix (storage .AzureBlobConfig .BasePath , "/" ) + "/" + name + "/"
301
+ } else {
302
+ defaultPath = storage .AzureBlobConfig .BasePath
303
+ }
304
+ }
305
+ if defaultPath == "" {
306
+ defaultPath = name + "/"
307
+ }
308
+
309
+ if overrideSec != nil {
310
+ storage .AzureBlobConfig .BasePath = ConfigSectionKeyString (overrideSec , "AZUREBLOB_BASE_PATH" , storage .AzureBlobConfig .BasePath )
311
+ storage .AzureBlobConfig .Container = ConfigSectionKeyString (overrideSec , "AZUREBLOB_CONTAINER" , storage .AzureBlobConfig .Container )
312
+ } else {
313
+ storage .AzureBlobConfig .BasePath = defaultPath
314
+ }
315
+ return & storage , nil
316
+ }
0 commit comments