|
@@ -82,52 +82,42 @@ public class AzureStorageSettings {
|
|
|
AzureStorageSettings primaryStorage = null;
|
|
|
Map<String, AzureStorageSettings> secondaryStorage = new HashMap<>();
|
|
|
|
|
|
- // We check for deprecated settings
|
|
|
- String account = settings.get(Storage.ACCOUNT_DEPRECATED);
|
|
|
- String key = settings.get(Storage.KEY_DEPRECATED);
|
|
|
-
|
|
|
TimeValue globalTimeout = settings.getAsTime(Storage.TIMEOUT, TimeValue.timeValueMinutes(5));
|
|
|
|
|
|
- if (account != null) {
|
|
|
- logger.warn("[{}] and [{}] have been deprecated. Use now [{}xxx.account] and [{}xxx.key] where xxx is any name",
|
|
|
- Storage.ACCOUNT_DEPRECATED, Storage.KEY_DEPRECATED, Storage.PREFIX, Storage.PREFIX);
|
|
|
- primaryStorage = new AzureStorageSettings(null, account, key, globalTimeout);
|
|
|
- } else {
|
|
|
- Settings storageSettings = settings.getByPrefix(Storage.PREFIX);
|
|
|
- if (storageSettings != null) {
|
|
|
- Map<String, Object> asMap = storageSettings.getAsStructuredMap();
|
|
|
- for (Map.Entry<String, Object> storage : asMap.entrySet()) {
|
|
|
- if (storage.getValue() instanceof Map) {
|
|
|
- @SuppressWarnings("unchecked")
|
|
|
- Map<String, String> map = (Map) storage.getValue();
|
|
|
- TimeValue timeout = TimeValue.parseTimeValue(map.get("timeout"), globalTimeout, Storage.PREFIX + storage.getKey() + ".timeout");
|
|
|
- AzureStorageSettings current = new AzureStorageSettings(storage.getKey(), map.get("account"), map.get("key"), timeout);
|
|
|
- boolean activeByDefault = Boolean.parseBoolean(map.getOrDefault("default", "false"));
|
|
|
- if (activeByDefault) {
|
|
|
- if (primaryStorage == null) {
|
|
|
- primaryStorage = current;
|
|
|
- } else {
|
|
|
- logger.warn("default storage settings has already been defined. You can not define it to [{}]", storage.getKey());
|
|
|
- secondaryStorage.put(storage.getKey(), current);
|
|
|
- }
|
|
|
+ Settings storageSettings = settings.getByPrefix(Storage.PREFIX);
|
|
|
+ if (storageSettings != null) {
|
|
|
+ Map<String, Object> asMap = storageSettings.getAsStructuredMap();
|
|
|
+ for (Map.Entry<String, Object> storage : asMap.entrySet()) {
|
|
|
+ if (storage.getValue() instanceof Map) {
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ Map<String, String> map = (Map) storage.getValue();
|
|
|
+ TimeValue timeout = TimeValue.parseTimeValue(map.get("timeout"), globalTimeout, Storage.PREFIX + storage.getKey() + ".timeout");
|
|
|
+ AzureStorageSettings current = new AzureStorageSettings(storage.getKey(), map.get("account"), map.get("key"), timeout);
|
|
|
+ boolean activeByDefault = Boolean.parseBoolean(map.getOrDefault("default", "false"));
|
|
|
+ if (activeByDefault) {
|
|
|
+ if (primaryStorage == null) {
|
|
|
+ primaryStorage = current;
|
|
|
} else {
|
|
|
+ logger.warn("default storage settings has already been defined. You can not define it to [{}]", storage.getKey());
|
|
|
secondaryStorage.put(storage.getKey(), current);
|
|
|
}
|
|
|
+ } else {
|
|
|
+ secondaryStorage.put(storage.getKey(), current);
|
|
|
}
|
|
|
}
|
|
|
- // If we did not set any default storage, we should complain and define it
|
|
|
- if (primaryStorage == null && secondaryStorage.isEmpty() == false) {
|
|
|
- Map.Entry<String, AzureStorageSettings> fallback = secondaryStorage.entrySet().iterator().next();
|
|
|
- // We only warn if the number of secondary storage if > to 1
|
|
|
- // If the user defined only one storage account, that's fine. We know it's the default one.
|
|
|
- if (secondaryStorage.size() > 1) {
|
|
|
- logger.warn("no default storage settings has been defined. " +
|
|
|
- "Add \"default\": true to the settings you want to activate by default. " +
|
|
|
- "Forcing default to [{}].", fallback.getKey());
|
|
|
- }
|
|
|
- primaryStorage = fallback.getValue();
|
|
|
- secondaryStorage.remove(fallback.getKey());
|
|
|
+ }
|
|
|
+ // If we did not set any default storage, we should complain and define it
|
|
|
+ if (primaryStorage == null && secondaryStorage.isEmpty() == false) {
|
|
|
+ Map.Entry<String, AzureStorageSettings> fallback = secondaryStorage.entrySet().iterator().next();
|
|
|
+ // We only warn if the number of secondary storage if > to 1
|
|
|
+ // If the user defined only one storage account, that's fine. We know it's the default one.
|
|
|
+ if (secondaryStorage.size() > 1) {
|
|
|
+ logger.warn("no default storage settings has been defined. " +
|
|
|
+ "Add \"default\": true to the settings you want to activate by default. " +
|
|
|
+ "Forcing default to [{}].", fallback.getKey());
|
|
|
}
|
|
|
+ primaryStorage = fallback.getValue();
|
|
|
+ secondaryStorage.remove(fallback.getKey());
|
|
|
}
|
|
|
}
|
|
|
|