Skip to content

Commit 2e631b5

Browse files
committed
Allow modification of user vm details if user.vm.readonly.details is empty
1 parent 50fe265 commit 2e631b5

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

api/src/main/java/org/apache/cloudstack/query/QueryService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.apache.cloudstack.query;
1818

1919
import java.util.Arrays;
20+
import java.util.Collections;
2021
import java.util.List;
2122

2223
import org.apache.cloudstack.affinity.AffinityGroupResponse;
@@ -120,7 +121,7 @@ public interface QueryService {
120121

121122
ConfigKey<String> UserVMReadOnlyDetails = new ConfigKey<>(String.class,
122123
"user.vm.readonly.details", "Advanced", "dataDiskController, rootDiskController",
123-
"List of read-only VM settings/details as comma separated string", true, ConfigKey.Scope.Global, null, null, null, null, null, ConfigKey.Kind.CSV, null);
124+
"List of read-only VM settings/details as comma separated string", true, Collections.singletonList(ConfigKey.Scope.Global), null, null, null, null, null, ConfigKey.Kind.CSV, null, "");
124125

125126
ConfigKey<Boolean> SortKeyAscending = new ConfigKey<>("Advanced", Boolean.class, "sortkey.algorithm", "true",
126127
"Sort algorithm - ascending or descending - to use. For entities that use sort key(template, disk offering, service offering, " +

framework/config/src/main/java/org/apache/cloudstack/framework/config/ConfigKey.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,18 @@ public String toString() {
267267

268268
static ConfigDepotImpl s_depot = null;
269269

270-
static public void init(ConfigDepotImpl depot) {
270+
private String _defaultValueIfEmpty = null;
271+
272+
public static void init(ConfigDepotImpl depot) {
271273
s_depot = depot;
272274
}
273275

276+
public ConfigKey(Class<T> type, String name, String category, String defaultValue, String description, boolean isDynamic, List<Scope> scopes, T multiplier,
277+
String displayText, String parent, Ternary<String, String, Long> group, Pair<String, Long> subGroup, Kind kind, String options, String defaultValueIfEmpty) {
278+
this(type, name, category, defaultValue, description, isDynamic, scopes, multiplier, displayText, parent, group, subGroup, kind, options);
279+
this._defaultValueIfEmpty = defaultValueIfEmpty;
280+
}
281+
274282
public ConfigKey(String category, Class<T> type, String name, String defaultValue, String description, boolean isDynamic, Scope scope) {
275283
this(type, name, category, defaultValue, description, isDynamic, scope, null);
276284
}
@@ -380,7 +388,19 @@ public boolean isSameKeyAs(Object obj) {
380388
public T value() {
381389
if (_value == null || isDynamic()) {
382390
String value = s_depot != null ? s_depot.getConfigStringValue(_name, Scope.Global, null) : null;
383-
_value = valueOf((value == null) ? defaultValue() : value);
391+
392+
String effective;
393+
if (value != null) {
394+
if (value.isEmpty() && _defaultValueIfEmpty != null) {
395+
effective = _defaultValueIfEmpty;
396+
} else {
397+
effective = value;
398+
}
399+
} else {
400+
effective = _defaultValueIfEmpty != null ? _defaultValueIfEmpty : defaultValue();
401+
}
402+
403+
_value = valueOf(effective);
384404
}
385405
return _value;
386406
}
@@ -409,6 +429,9 @@ public T valueInScope(Scope scope, Long id) {
409429
return valueInGlobalOrAvailableParentScope(scope, id);
410430
}
411431
logger.trace("Scope({}) value for config ({}): {}", scope, _name, _value);
432+
if (value.isEmpty() && _defaultValueIfEmpty != null) {
433+
return valueOf(_defaultValueIfEmpty);
434+
}
412435
return valueOf(value);
413436
}
414437

0 commit comments

Comments
 (0)