From ae1046585cbb7e490f24eeae5eb3b1d15c3c0435 Mon Sep 17 00:00:00 2001 From: Ainur Date: Tue, 4 Oct 2022 14:25:55 +0200 Subject: [PATCH 1/6] CB-2077 save pattern variables --- .../io/cloudbeaver/server/CBApplication.java | 85 ++++++++++++++----- 1 file changed, 63 insertions(+), 22 deletions(-) diff --git a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBApplication.java b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBApplication.java index 365531dece..c35bfed5a1 100644 --- a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBApplication.java +++ b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBApplication.java @@ -109,6 +109,7 @@ public class CBApplication extends BaseWebApplication implements WebAuthApplicat protected final Map databaseConfiguration = new HashMap<>(); private final CBAppConfig appConfiguration = new CBAppConfig(); private Map externalProperties = new LinkedHashMap<>(); + private Map configProperties = new LinkedHashMap<>(); // Persistence private SMAdminController securityController; @@ -643,13 +644,9 @@ public class CBApplication extends BaseWebApplication implements WebAuthApplicat Map configProps = new LinkedHashMap<>(); if (configFile.exists()) { log.debug("Read configuration [" + configFile.getAbsolutePath() + "]"); - try (Reader reader = new InputStreamReader(new FileInputStream(configFile), StandardCharsets.UTF_8)) { - configProps.putAll(JSONUtils.parseMap(getGson(), reader)); - patchConfigurationWithProperties(configProps); // patch original properties - - } catch (IOException e) { - throw new DBException("Error parsing server configuration", e); - } + readConfigurationFile(configFile, configProperties); + readConfigurationFile(configFile, configProps); + patchConfigurationWithProperties(configProps); // patch original properties } readAdditionalConfiguration(configProps); @@ -675,6 +672,15 @@ public class CBApplication extends BaseWebApplication implements WebAuthApplicat return configProps; } + private void readConfigurationFile(File configFile, Map configProps) throws DBException { + try (Reader reader = new InputStreamReader(new FileInputStream(configFile), StandardCharsets.UTF_8)) { + configProps.putAll(JSONUtils.parseMap(getGson(), reader)); + + } catch (IOException e) { + throw new DBException("Error parsing server configuration", e); + } + } + private Gson getGson() { // Stupid way to populate existing objects but ok google (https://github.com/google/gson/issues/431) InstanceCreator appConfigCreator = type -> appConfiguration; @@ -867,36 +873,57 @@ public class CBApplication extends BaseWebApplication implements WebAuthApplicat Map rootConfig = new LinkedHashMap<>(); { var serverConfigProperties = new LinkedHashMap(); + var originServerConfig = getServerConfigProps(configProperties); rootConfig.put("server", serverConfigProperties); if (!CommonUtils.isEmpty(newServerName)) { - serverConfigProperties.put(CBConstants.PARAM_SERVER_NAME, newServerName); + putToRuntimeConfig(originServerConfig, serverConfigProperties, CBConstants.PARAM_SERVER_NAME, newServerName); } if (!CommonUtils.isEmpty(newServerURL)) { - serverConfigProperties.put(CBConstants.PARAM_SERVER_URL, newServerURL); + putToRuntimeConfig( + originServerConfig, serverConfigProperties, CBConstants.PARAM_SERVER_URL, newServerURL); } if (sessionExpireTime > 0) { - serverConfigProperties.put(CBConstants.PARAM_SESSION_EXPIRE_PERIOD, sessionExpireTime); + putToRuntimeConfig( + originServerConfig, serverConfigProperties, CBConstants.PARAM_SESSION_EXPIRE_PERIOD, sessionExpireTime); } - + var databaseConfigProperties = new LinkedHashMap(); + Map oldRuntimeDBConfig = JSONUtils.getObject(originServerConfig, CBConstants.PARAM_DB_CONFIGURATION); if (!CommonUtils.isEmpty(databaseConfiguration)) { - serverConfigProperties.put(CBConstants.PARAM_DB_CONFIGURATION, databaseConfiguration); + for (Map.Entry mp : databaseConfiguration.entrySet()) { + putToRuntimeConfig(oldRuntimeDBConfig, databaseConfigProperties, mp.getKey(), mp.getValue()); + } + serverConfigProperties.put(CBConstants.PARAM_DB_CONFIGURATION, databaseConfigProperties); } } { var appConfigProperties = new LinkedHashMap(); + Map oldAppConfig = JSONUtils.getObject(configProperties, "app"); rootConfig.put("app", appConfigProperties); - appConfigProperties.put("anonymousAccessEnabled", appConfig.isAnonymousAccessEnabled()); - appConfigProperties.put("supportsCustomConnections", appConfig.isSupportsCustomConnections()); - appConfigProperties.put("publicCredentialsSaveEnabled", appConfig.isPublicCredentialsSaveEnabled()); - appConfigProperties.put("adminCredentialsSaveEnabled", appConfig.isAdminCredentialsSaveEnabled()); - appConfigProperties.put("enableReverseProxyAuth", appConfig.isEnabledReverseProxyAuth()); - appConfigProperties.put("forwardProxy", appConfig.isEnabledForwardProxy()); - appConfigProperties.put("linkExternalCredentialsWithUser", appConfig.isLinkExternalCredentialsWithUser()); - appConfigProperties.put("redirectOnFederatedAuth", appConfig.isRedirectOnFederatedAuth()); - appConfigProperties.put(CBConstants.PARAM_RESOURCE_MANAGER_ENABLED, appConfig.isResourceManagerEnabled()); + putToRuntimeConfig( + oldAppConfig, appConfigProperties, "anonymousAccessEnabled", appConfig.isAnonymousAccessEnabled()); + putToRuntimeConfig( + oldAppConfig, appConfigProperties, "supportsCustomConnections", appConfig.isSupportsCustomConnections()); + putToRuntimeConfig( + oldAppConfig, appConfigProperties, "publicCredentialsSaveEnabled", appConfig.isPublicCredentialsSaveEnabled()); + putToRuntimeConfig( + oldAppConfig, appConfigProperties, "adminCredentialsSaveEnabled", appConfig.isAdminCredentialsSaveEnabled()); + putToRuntimeConfig( + oldAppConfig, appConfigProperties, "enableReverseProxyAuth", appConfig.isEnabledReverseProxyAuth()); + putToRuntimeConfig( + oldAppConfig, appConfigProperties, "forwardProxy", appConfig.isEnabledForwardProxy()); + putToRuntimeConfig( + oldAppConfig, appConfigProperties, "linkExternalCredentialsWithUser", appConfig.isLinkExternalCredentialsWithUser()); + putToRuntimeConfig( + oldAppConfig, appConfigProperties, "redirectOnFederatedAuth", appConfig.isRedirectOnFederatedAuth()); + putToRuntimeConfig( + oldAppConfig, appConfigProperties, CBConstants.PARAM_RESOURCE_MANAGER_ENABLED, appConfig.isResourceManagerEnabled()); - Map resourceQuotas = appConfig.getResourceQuotas(); + Map resourceQuotas = new LinkedHashMap<>(); + Map originResourceQuotas = JSONUtils.getObject(oldAppConfig, CBConstants.PARAM_RESOURCE_QUOTAS); + for (Map.Entry mp : appConfig.getResourceQuotas().entrySet()) { + putToRuntimeConfig(originResourceQuotas, appConfigProperties, mp.getKey(), mp.getValue()); + } appConfigProperties.put(CBConstants.PARAM_RESOURCE_QUOTAS, resourceQuotas); { @@ -999,4 +1026,18 @@ public class CBApplication extends BaseWebApplication implements WebAuthApplicat public WebDriverRegistry getDriverRegistry() { return WebDriverRegistry.getInstance(); } + + private void putToRuntimeConfig(Map oldConfig, Map newConfig, String key, Object defaultValue) { + Object oldValue = oldConfig.get(key); + if (oldValue instanceof String && GeneralUtils.isVariablePattern((String) oldValue)) { + String extractedVariable = GeneralUtils.extractVariableName((String) oldValue); + if (extractedVariable != null) { + newConfig.put(key, GeneralUtils.variablePattern(extractedVariable + ":" + defaultValue)); + } else { + newConfig.put(key, defaultValue); + } + } else { + newConfig.put(key, defaultValue); + } + } } From 5c83fb99d61dbb0733f2434378ab8c60471349ed Mon Sep 17 00:00:00 2001 From: Ainur Date: Tue, 11 Oct 2022 15:54:55 +0200 Subject: [PATCH 2/6] CB-2077 add comments for original config file --- .../src/io/cloudbeaver/server/CBApplication.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBApplication.java b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBApplication.java index c35bfed5a1..221b2521f5 100644 --- a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBApplication.java +++ b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBApplication.java @@ -644,7 +644,7 @@ public class CBApplication extends BaseWebApplication implements WebAuthApplicat Map configProps = new LinkedHashMap<>(); if (configFile.exists()) { log.debug("Read configuration [" + configFile.getAbsolutePath() + "]"); - readConfigurationFile(configFile, configProperties); + readConfigurationFile(configFile, this.configProperties); // saves original configuration file readConfigurationFile(configFile, configProps); patchConfigurationWithProperties(configProps); // patch original properties } @@ -873,7 +873,7 @@ public class CBApplication extends BaseWebApplication implements WebAuthApplicat Map rootConfig = new LinkedHashMap<>(); { var serverConfigProperties = new LinkedHashMap(); - var originServerConfig = getServerConfigProps(configProperties); + var originServerConfig = getServerConfigProps(this.configProperties); // get server properties from original configuration file rootConfig.put("server", serverConfigProperties); if (!CommonUtils.isEmpty(newServerName)) { putToRuntimeConfig(originServerConfig, serverConfigProperties, CBConstants.PARAM_SERVER_NAME, newServerName); @@ -1027,6 +1027,7 @@ public class CBApplication extends BaseWebApplication implements WebAuthApplicat return WebDriverRegistry.getInstance(); } + // gets info about patterns from original configuration file and saves it to runtime config private void putToRuntimeConfig(Map oldConfig, Map newConfig, String key, Object defaultValue) { Object oldValue = oldConfig.get(key); if (oldValue instanceof String && GeneralUtils.isVariablePattern((String) oldValue)) { From 7529430afd2caea2054ef19c41b3d560610f3225 Mon Sep 17 00:00:00 2001 From: Ainur Date: Wed, 12 Oct 2022 15:27:06 +0200 Subject: [PATCH 3/6] CB-2077 code style fix --- .../io/cloudbeaver/server/CBApplication.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBApplication.java b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBApplication.java index 221b2521f5..c788fe6b96 100644 --- a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBApplication.java +++ b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBApplication.java @@ -109,7 +109,7 @@ public class CBApplication extends BaseWebApplication implements WebAuthApplicat protected final Map databaseConfiguration = new HashMap<>(); private final CBAppConfig appConfiguration = new CBAppConfig(); private Map externalProperties = new LinkedHashMap<>(); - private Map configProperties = new LinkedHashMap<>(); + private Map originalConfigurationProperties = new LinkedHashMap<>(); // Persistence private SMAdminController securityController; @@ -644,8 +644,10 @@ public class CBApplication extends BaseWebApplication implements WebAuthApplicat Map configProps = new LinkedHashMap<>(); if (configFile.exists()) { log.debug("Read configuration [" + configFile.getAbsolutePath() + "]"); - readConfigurationFile(configFile, this.configProperties); // saves original configuration file - readConfigurationFile(configFile, configProps); + // saves original configuration file + this.originalConfigurationProperties.putAll(readConfigurationFile(configFile)); + + configProps.putAll(readConfigurationFile(configFile)); patchConfigurationWithProperties(configProps); // patch original properties } @@ -672,10 +674,9 @@ public class CBApplication extends BaseWebApplication implements WebAuthApplicat return configProps; } - private void readConfigurationFile(File configFile, Map configProps) throws DBException { + private Map readConfigurationFile(File configFile) throws DBException { try (Reader reader = new InputStreamReader(new FileInputStream(configFile), StandardCharsets.UTF_8)) { - configProps.putAll(JSONUtils.parseMap(getGson(), reader)); - + return JSONUtils.parseMap(getGson(), reader); } catch (IOException e) { throw new DBException("Error parsing server configuration", e); } @@ -873,7 +874,7 @@ public class CBApplication extends BaseWebApplication implements WebAuthApplicat Map rootConfig = new LinkedHashMap<>(); { var serverConfigProperties = new LinkedHashMap(); - var originServerConfig = getServerConfigProps(this.configProperties); // get server properties from original configuration file + var originServerConfig = getServerConfigProps(this.originalConfigurationProperties); // get server properties from original configuration file rootConfig.put("server", serverConfigProperties); if (!CommonUtils.isEmpty(newServerName)) { putToRuntimeConfig(originServerConfig, serverConfigProperties, CBConstants.PARAM_SERVER_NAME, newServerName); @@ -897,7 +898,7 @@ public class CBApplication extends BaseWebApplication implements WebAuthApplicat } { var appConfigProperties = new LinkedHashMap(); - Map oldAppConfig = JSONUtils.getObject(configProperties, "app"); + Map oldAppConfig = JSONUtils.getObject(this.originalConfigurationProperties, "app"); rootConfig.put("app", appConfigProperties); putToRuntimeConfig( From 4374ce92f00897ebaad4e6fc5495709b6bcf9521 Mon Sep 17 00:00:00 2001 From: Ainur Date: Fri, 14 Oct 2022 12:24:18 +0200 Subject: [PATCH 4/6] CB-2077 get variable patterns from map config --- .../io/cloudbeaver/server/CBApplication.java | 63 ++++++++++++------- 1 file changed, 40 insertions(+), 23 deletions(-) diff --git a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBApplication.java b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBApplication.java index d3e3cd0b51..2b273a8507 100644 --- a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBApplication.java +++ b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBApplication.java @@ -877,21 +877,21 @@ public class CBApplication extends BaseWebApplication implements WebAuthApplicat var originServerConfig = getServerConfigProps(this.originalConfigurationProperties); // get server properties from original configuration file rootConfig.put("server", serverConfigProperties); if (!CommonUtils.isEmpty(newServerName)) { - putToRuntimeConfig(originServerConfig, serverConfigProperties, CBConstants.PARAM_SERVER_NAME, newServerName); + copyConfigValue(originServerConfig, serverConfigProperties, CBConstants.PARAM_SERVER_NAME, newServerName); } if (!CommonUtils.isEmpty(newServerURL)) { - putToRuntimeConfig( + copyConfigValue( originServerConfig, serverConfigProperties, CBConstants.PARAM_SERVER_URL, newServerURL); } if (sessionExpireTime > 0) { - putToRuntimeConfig( + copyConfigValue( originServerConfig, serverConfigProperties, CBConstants.PARAM_SESSION_EXPIRE_PERIOD, sessionExpireTime); } var databaseConfigProperties = new LinkedHashMap(); Map oldRuntimeDBConfig = JSONUtils.getObject(originServerConfig, CBConstants.PARAM_DB_CONFIGURATION); if (!CommonUtils.isEmpty(databaseConfiguration)) { for (Map.Entry mp : databaseConfiguration.entrySet()) { - putToRuntimeConfig(oldRuntimeDBConfig, databaseConfigProperties, mp.getKey(), mp.getValue()); + copyConfigValue(oldRuntimeDBConfig, databaseConfigProperties, mp.getKey(), mp.getValue()); } serverConfigProperties.put(CBConstants.PARAM_DB_CONFIGURATION, databaseConfigProperties); } @@ -901,29 +901,29 @@ public class CBApplication extends BaseWebApplication implements WebAuthApplicat Map oldAppConfig = JSONUtils.getObject(this.originalConfigurationProperties, "app"); rootConfig.put("app", appConfigProperties); - putToRuntimeConfig( + copyConfigValue( oldAppConfig, appConfigProperties, "anonymousAccessEnabled", appConfig.isAnonymousAccessEnabled()); - putToRuntimeConfig( + copyConfigValue( oldAppConfig, appConfigProperties, "supportsCustomConnections", appConfig.isSupportsCustomConnections()); - putToRuntimeConfig( + copyConfigValue( oldAppConfig, appConfigProperties, "publicCredentialsSaveEnabled", appConfig.isPublicCredentialsSaveEnabled()); - putToRuntimeConfig( + copyConfigValue( oldAppConfig, appConfigProperties, "adminCredentialsSaveEnabled", appConfig.isAdminCredentialsSaveEnabled()); - putToRuntimeConfig( + copyConfigValue( oldAppConfig, appConfigProperties, "enableReverseProxyAuth", appConfig.isEnabledReverseProxyAuth()); - putToRuntimeConfig( + copyConfigValue( oldAppConfig, appConfigProperties, "forwardProxy", appConfig.isEnabledForwardProxy()); - putToRuntimeConfig( + copyConfigValue( oldAppConfig, appConfigProperties, "linkExternalCredentialsWithUser", appConfig.isLinkExternalCredentialsWithUser()); - putToRuntimeConfig( + copyConfigValue( oldAppConfig, appConfigProperties, "redirectOnFederatedAuth", appConfig.isRedirectOnFederatedAuth()); - putToRuntimeConfig( + copyConfigValue( oldAppConfig, appConfigProperties, CBConstants.PARAM_RESOURCE_MANAGER_ENABLED, appConfig.isResourceManagerEnabled()); Map resourceQuotas = new LinkedHashMap<>(); Map originResourceQuotas = JSONUtils.getObject(oldAppConfig, CBConstants.PARAM_RESOURCE_QUOTAS); for (Map.Entry mp : appConfig.getResourceQuotas().entrySet()) { - putToRuntimeConfig(originResourceQuotas, appConfigProperties, mp.getKey(), mp.getValue()); + copyConfigValue(originResourceQuotas, resourceQuotas, mp.getKey(), mp.getValue()); } appConfigProperties.put(CBConstants.PARAM_RESOURCE_QUOTAS, resourceQuotas); @@ -1029,17 +1029,34 @@ public class CBApplication extends BaseWebApplication implements WebAuthApplicat } // gets info about patterns from original configuration file and saves it to runtime config - private void putToRuntimeConfig(Map oldConfig, Map newConfig, String key, Object defaultValue) { - Object oldValue = oldConfig.get(key); - if (oldValue instanceof String && GeneralUtils.isVariablePattern((String) oldValue)) { - String extractedVariable = GeneralUtils.extractVariableName((String) oldValue); - if (extractedVariable != null) { - newConfig.put(key, GeneralUtils.variablePattern(extractedVariable + ":" + defaultValue)); - } else { - newConfig.put(key, defaultValue); + private void copyConfigValue(Map oldConfig, Map newConfig, String key, Object defaultValue) { + Object value = oldConfig.get(key); + if (value instanceof Map && defaultValue instanceof Map) { + Map subValue = new LinkedHashMap<>(); + Map oldConfigValue = JSONUtils.getObject(oldConfig, key); + for (Map.Entry entry : oldConfigValue.entrySet()) { + copyConfigValue(oldConfigValue, subValue, entry.getKey(), ((Map) defaultValue).get(entry.getKey())); } + newConfig.put(key, subValue); } else { - newConfig.put(key, defaultValue); + Object newConfigValue = getExtractedValue(oldConfig.get(key), defaultValue); + newConfig.put(key, newConfigValue); + } + } + + private Object getExtractedValue(Object oldValue, Object newValue) { + if (!(oldValue instanceof String)) { + return newValue; + } + String value = (String) oldValue; + if (!GeneralUtils.isVariablePattern(value)) { + return newValue; + } + String extractedVariable = GeneralUtils.extractVariableName(value); + if (extractedVariable != null) { + return GeneralUtils.variablePattern(extractedVariable + ":" + newValue); + } else { + return newValue; } } } From 33a814943f19103112bca3f5efa69c1ad74cf674 Mon Sep 17 00:00:00 2001 From: Ainur Date: Mon, 17 Oct 2022 15:21:54 +0200 Subject: [PATCH 5/6] CB-2077 save pattern variables in dc --- .../src/io/cloudbeaver/utils/WebAppUtils.java | 42 +++++++++++++++++++ .../io/cloudbeaver/server/CBApplication.java | 20 +-------- 2 files changed, 44 insertions(+), 18 deletions(-) diff --git a/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/utils/WebAppUtils.java b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/utils/WebAppUtils.java index 8f1ecf3442..b9af9a72cc 100644 --- a/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/utils/WebAppUtils.java +++ b/server/bundles/io.cloudbeaver.model/src/io/cloudbeaver/utils/WebAppUtils.java @@ -27,6 +27,7 @@ import org.jkiss.dbeaver.model.app.DBPProject; import org.jkiss.dbeaver.model.auth.SMAuthenticationManager; import org.jkiss.dbeaver.model.rm.RMProjectType; import org.jkiss.dbeaver.runtime.DBWorkbench; +import org.jkiss.dbeaver.utils.GeneralUtils; import org.jkiss.utils.CommonUtils; import javax.servlet.http.Cookie; @@ -92,6 +93,47 @@ public class WebAppUtils { return resultConfig; } + @SuppressWarnings("unchecked") + public static Map mergeConfigurationsWithVariables(Map origin, Map additional) { + var resultConfig = new HashMap(); + Set rootKeys = new HashSet<>(additional.keySet()); + + for (var rootKey : rootKeys) { + var originValue = origin.get(rootKey); + var additionalValue = additional.get(rootKey); + + if (additionalValue == null) { + continue; + } + + if (originValue instanceof Map) { + var resultValue = mergeConfigurationsWithVariables((Map) originValue, (Map) additionalValue); + resultConfig.put(rootKey, resultValue); + } else { + resultConfig.put(rootKey, getExtractedValue(originValue, additionalValue)); + } + + } + + return resultConfig; + } + + public static Object getExtractedValue(Object oldValue, Object newValue) { + if (!(oldValue instanceof String)) { + return newValue; + } + String value = (String) oldValue; + if (!GeneralUtils.isVariablePattern(value)) { + return newValue; + } + String extractedVariable = GeneralUtils.extractVariableName(value); + if (extractedVariable != null) { + return GeneralUtils.variablePattern(extractedVariable + ":" + newValue); + } else { + return newValue; + } + } + @NotNull public static String removeSideSlashes(String action) { diff --git a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBApplication.java b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBApplication.java index 2b273a8507..9e1d45ae59 100644 --- a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBApplication.java +++ b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBApplication.java @@ -674,7 +674,7 @@ public class CBApplication extends BaseWebApplication implements WebAuthApplicat return configProps; } - private Map readConfigurationFile(File configFile) throws DBException { + public Map readConfigurationFile(File configFile) throws DBException { try (Reader reader = new InputStreamReader(new FileInputStream(configFile), StandardCharsets.UTF_8)) { return JSONUtils.parseMap(getGson(), reader); } catch (IOException e) { @@ -1039,24 +1039,8 @@ public class CBApplication extends BaseWebApplication implements WebAuthApplicat } newConfig.put(key, subValue); } else { - Object newConfigValue = getExtractedValue(oldConfig.get(key), defaultValue); + Object newConfigValue = WebAppUtils.getExtractedValue(oldConfig.get(key), defaultValue); newConfig.put(key, newConfigValue); } } - - private Object getExtractedValue(Object oldValue, Object newValue) { - if (!(oldValue instanceof String)) { - return newValue; - } - String value = (String) oldValue; - if (!GeneralUtils.isVariablePattern(value)) { - return newValue; - } - String extractedVariable = GeneralUtils.extractVariableName(value); - if (extractedVariable != null) { - return GeneralUtils.variablePattern(extractedVariable + ":" + newValue); - } else { - return newValue; - } - } } From f9d67d73c85c457c4006221ad1bc1fa5047f6878 Mon Sep 17 00:00:00 2001 From: Ainur Date: Tue, 18 Oct 2022 20:14:00 +0200 Subject: [PATCH 6/6] CB-2077 resource quotas fix --- .../src/io/cloudbeaver/server/CBAppConfig.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBAppConfig.java b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBAppConfig.java index 32028cfbcb..7682ae1a2f 100644 --- a/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBAppConfig.java +++ b/server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/server/CBAppConfig.java @@ -218,12 +218,16 @@ public class CBAppConfig extends BaseAuthWebAppConfiguration implements WebAuthC } public T getResourceQuota(String quotaId) { - return (T) resourceQuotas.get(quotaId); + Object quota = resourceQuotas.get(quotaId); + if (quota instanceof String) { + quota = CommonUtils.toDouble(quota); + } + return (T) quota; } public T getResourceQuota(String quotaId, T defaultValue) { if (resourceQuotas.containsKey(quotaId)) { - return (T) resourceQuotas.get(quotaId); + return (T) getResourceQuota(quotaId); } else { return defaultValue; }