Skip to content

Commit 043482e

Browse files
committed
config: add error logging when fail to decrypt a encrypted global configuration
1 parent 4a49ffa commit 043482e

4 files changed

Lines changed: 15 additions & 11 deletions

File tree

framework/config/src/main/java/org/apache/cloudstack/framework/config/dao/ConfigurationDaoImpl.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,17 @@ public boolean update(String name, String category, String value) {
174174
@Override
175175
public String getValue(String name) {
176176
ConfigurationVO config = findByName(name);
177-
return (config == null) ? null : config.getValue();
177+
if (config == null) {
178+
return null;
179+
}
180+
try {
181+
return config.getValue();
182+
} catch (CloudRuntimeException ex) {
183+
logger.error("Unable to get global configuration {}: {}. " +
184+
"We expect the value of setting to be encrypted in the database with the Management Server's key, " +
185+
"but we were unable to decrypt it using this key", name, ex.getMessage());
186+
throw ex;
187+
}
178188
}
179189

180190
@Override

framework/config/src/main/java/org/apache/cloudstack/framework/config/impl/ConfigDepotImpl.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,7 @@ protected String getConfigStringValueInternal(Ternary<String, ConfigKey.Scope, L
286286
}
287287
return scopedConfigStorage.getConfigValue(scopeId, key);
288288
}
289-
ConfigurationVO configurationVO = _configDao.findById(key);
290-
if (configurationVO != null) {
291-
return configurationVO.getValue();
292-
}
293-
return null;
289+
return _configDao.getValue(key);
294290
}
295291

296292
protected Ternary<String, ConfigKey.Scope, Long> getConfigCacheKey(String key, ConfigKey.Scope scope, Long scopeId) {

framework/config/src/main/java/org/apache/cloudstack/framework/config/impl/ConfigurationVO.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public void setName(String name) {
155155

156156
@Override
157157
public String getValue() {
158-
if(isEncrypted()) {
158+
if (isEncrypted()) {
159159
return DBEncryptionUtil.decrypt(value);
160160
} else {
161161
return value;

framework/config/src/test/java/org/apache/cloudstack/framework/config/impl/ConfigDepotImplTest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,7 @@ public void testIsNewConfig() {
7777
}
7878

7979
private void runTestGetConfigStringValue(String key, String value) {
80-
ConfigurationVO configurationVO = Mockito.mock(ConfigurationVO.class);
81-
Mockito.when(configurationVO.getValue()).thenReturn(value);
82-
Mockito.when(_configDao.findById(key)).thenReturn(configurationVO);
80+
Mockito.when(_configDao.getValue(key)).thenReturn(value);
8381
String result = configDepotImpl.getConfigStringValue(key, ConfigKey.Scope.Global, null);
8482
Assert.assertEquals(value, result);
8583
}
@@ -106,7 +104,7 @@ private void runTestGetConfigStringValueExpiry(long wait, int configDBRetrieval)
106104
}
107105
String result = configDepotImpl.getConfigStringValue(key, ConfigKey.Scope.Global, null);
108106
Assert.assertEquals(value, result);
109-
Mockito.verify(_configDao, Mockito.times(configDBRetrieval)).findById(key);
107+
Mockito.verify(_configDao, Mockito.times(configDBRetrieval)).getValue(key);
110108
}
111109

112110
@Test

0 commit comments

Comments
 (0)