Skip to content

Commit f45367f

Browse files
committed
update
1 parent 2c00368 commit f45367f

File tree

1 file changed

+30
-16
lines changed

1 file changed

+30
-16
lines changed

modules/setting/storage.go

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ func getStorage(rootCfg ConfigProvider, name, typ string, sec ConfigSection) (*S
118118
return getStorageForLocal(targetSec, overrideSec, tp, name)
119119
case string(MinioStorageType):
120120
return getStorageForMinio(targetSec, overrideSec, tp, name)
121+
case string(AzureBlobStorageType):
122+
return getStorageForAzureBlob(targetSec, overrideSec, tp, name)
121123
default:
122124
return nil, fmt.Errorf("unsupported storage type %q", targetType)
123125
}
@@ -251,22 +253,6 @@ func getStorageForLocal(targetSec, overrideSec ConfigSection, tp targetSecType,
251253
storage.Path = filepath.Join(targetPath, storage.Path)
252254
}
253255
}
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-
}
270256
}
271257

272258
return &storage, nil
@@ -300,3 +286,31 @@ func getStorageForMinio(targetSec, overrideSec ConfigSection, tp targetSecType,
300286
}
301287
return &storage, nil
302288
}
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

Comments
 (0)