Skip to content

Commit 2554589

Browse files
committed
return stored value for secure configs so listConfigurations stays the same
1 parent 1a48a87 commit 2554589

3 files changed

Lines changed: 29 additions & 1 deletion

File tree

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,13 @@ public String getValue() {
162162
}
163163
}
164164

165+
/**
166+
* Returns the value as stored in the database, without decrypting it.
167+
*/
168+
public String getRawValue() {
169+
return value;
170+
}
171+
165172
public void setValue(String value) {
166173
if(isEncrypted()) {
167174
this.value = DBEncryptionUtil.encrypt(value);

‎server/src/main/java/com/cloud/api/ApiResponseHelper.java‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@
213213
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
214214
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotDataFactory;
215215
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo;
216+
import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
216217
import org.apache.cloudstack.framework.jobs.AsyncJob;
217218
import org.apache.cloudstack.framework.jobs.AsyncJobManager;
218219
import org.apache.cloudstack.framework.jobs.dao.AsyncJobDao;
@@ -686,7 +687,9 @@ public ConfigurationResponse createConfigurationResponse(Configuration cfg) {
686687
cfgResponse.setSubGroup(configGroupAndSubGroup.second());
687688
cfgResponse.setDescription(cfg.getDescription());
688689
cfgResponse.setName(cfg.getName());
689-
if (cfg.isEncrypted()) {
690+
if (cfg instanceof ConfigurationVO && cfg.isEncrypted()) {
691+
cfgResponse.setValue(((ConfigurationVO) cfg).getRawValue());
692+
} else if (cfg.isEncrypted()) {
690693
cfgResponse.setValue(DBEncryptionUtil.encrypt(cfg.getValue()));
691694
} else {
692695
cfgResponse.setValue(cfg.getValue());

‎server/src/test/java/com/cloud/api/ApiResponseHelperTest.java‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.apache.cloudstack.api.ResponseObject;
4747
import org.apache.cloudstack.api.response.AutoScaleVmGroupResponse;
4848
import org.apache.cloudstack.api.response.AutoScaleVmProfileResponse;
49+
import org.apache.cloudstack.api.response.ConfigurationResponse;
4950
import org.apache.cloudstack.api.response.ConsoleSessionResponse;
5051
import org.apache.cloudstack.api.response.DirectDownloadCertificateResponse;
5152
import org.apache.cloudstack.api.response.GuestOSCategoryResponse;
@@ -57,10 +58,12 @@
5758
import org.apache.cloudstack.api.response.UsageRecordResponse;
5859
import org.apache.cloudstack.api.response.TrafficTypeResponse;
5960
import org.apache.cloudstack.context.CallContext;
61+
import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
6062
import org.apache.cloudstack.usage.UsageService;
6163
import org.apache.cloudstack.vm.UnmanagedInstanceTO;
6264

6365
import com.cloud.capacity.Capacity;
66+
import com.cloud.configuration.ConfigurationManager;
6467
import com.cloud.configuration.Resource;
6568
import com.cloud.domain.DomainVO;
6669
import com.cloud.host.HostVO;
@@ -93,6 +96,7 @@
9396
import com.cloud.user.UserDataVO;
9497
import com.cloud.user.UserVO;
9598
import com.cloud.user.dao.UserDataDao;
99+
import com.cloud.utils.Pair;
96100
import com.cloud.utils.net.Ip;
97101
import com.cloud.vm.ConsoleSessionVO;
98102
import com.cloud.vm.NicSecondaryIp;
@@ -137,6 +141,9 @@ public class ApiResponseHelperTest {
137141
@Mock
138142
ResourceIconManager resourceIconManager;
139143

144+
@Mock
145+
ConfigurationManager configurationManagerMock;
146+
140147
@Mock
141148
private ConsoleSessionVO consoleSessionMock;
142149
@Mock
@@ -800,4 +807,15 @@ public void createConsoleSessionResponseTestShouldReturnFullResponse() {
800807
Assert.assertEquals(expected.getVmName(), response.getVmName());
801808
}
802809
}
810+
811+
@Test
812+
public void testCreateConfigurationResponseSecureValueIsReturnedAsStored() {
813+
ConfigurationVO cfg = new ConfigurationVO("Secure", "DEFAULT", "test", "test.secure.setting", null, "test");
814+
ReflectionTestUtils.setField(cfg, "value", "storedEncryptedValue");
815+
Mockito.when(configurationManagerMock.getConfigurationGroupAndSubGroup(cfg.getName())).thenReturn(new Pair<>("Miscellaneous", "Others"));
816+
817+
ConfigurationResponse response = apiResponseHelper.createConfigurationResponse(cfg);
818+
819+
assertEquals("storedEncryptedValue", response.getValue());
820+
}
803821
}

0 commit comments

Comments
 (0)