mirror of
https://github.com/corda/corda.git
synced 2025-02-05 02:29:20 +00:00
Made strict behaviour optional default to true for conf parsing. HSM and Doorman can opt in for this functionality independently.
This commit is contained in:
parent
b39a1a71d9
commit
38208d9e44
@ -102,7 +102,7 @@ fun parseParameters(vararg args: String): NetworkManagementServerParameters {
|
||||
|
||||
val config = argConfig.withFallback(ConfigFactory.parseFile(configFile.toFile(), ConfigParseOptions.defaults().setAllowMissing(true)))
|
||||
.resolve()
|
||||
.parseAs<NetworkManagementServerParameters>()
|
||||
.parseAs<NetworkManagementServerParameters>(false)
|
||||
|
||||
// Make sure trust store password is only specified in root keygen mode.
|
||||
if (config.mode != Mode.ROOT_KEYGEN) {
|
||||
|
@ -73,5 +73,5 @@ fun parseParameters(vararg args: String): Parameters {
|
||||
require(configFile.isRegularFile()) { "Config file $configFile does not exist" }
|
||||
|
||||
val config = argConfig.withFallback(ConfigFactory.parseFile(configFile.toFile(), ConfigParseOptions.defaults().setAllowMissing(true))).resolve()
|
||||
return config.parseAs()
|
||||
return config.parseAs(false)
|
||||
}
|
@ -36,25 +36,27 @@ operator fun <T : Any> Config.getValue(receiver: Any, metadata: KProperty<*>): T
|
||||
return getValueInternal(metadata.name, metadata.returnType)
|
||||
}
|
||||
|
||||
fun <T : Any> Config.parseAs(clazz: KClass<T>): T {
|
||||
fun <T : Any> Config.parseAs(clazz: KClass<T>, strict: Boolean = true): T {
|
||||
require(clazz.isData) { "Only Kotlin data classes can be parsed. Offending: ${clazz.qualifiedName}" }
|
||||
val constructor = clazz.primaryConstructor!!
|
||||
val parameters = constructor.parameters
|
||||
val parameterNames = parameters.flatMap { param ->
|
||||
mutableSetOf<String>().apply {
|
||||
param.name?.let(this::add)
|
||||
clazz.memberProperties.singleOrNull { it.name == param.name }?.let { matchingProperty ->
|
||||
matchingProperty.annotations.filterIsInstance<OldConfig>().map { it.value }.forEach { this.add(it) }
|
||||
if (strict) {
|
||||
val parameterNames = parameters.flatMap { param ->
|
||||
mutableSetOf<String>().apply {
|
||||
param.name?.let(this::add)
|
||||
clazz.memberProperties.singleOrNull { it.name == param.name }?.let { matchingProperty ->
|
||||
matchingProperty.annotations.filterIsInstance<OldConfig>().map { it.value }.forEach { this.add(it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
val unknownConfigurationKeys = this.entrySet()
|
||||
.mapNotNull { it.key.split(".").firstOrNull() }
|
||||
.filterNot { it == CUSTOM_NODE_PROPERTIES_ROOT }
|
||||
.filterNot(parameterNames::contains)
|
||||
.toSortedSet()
|
||||
if (unknownConfigurationKeys.isNotEmpty()) {
|
||||
throw UnknownConfigurationKeysException.of(unknownConfigurationKeys)
|
||||
val unknownConfigurationKeys = this.entrySet()
|
||||
.mapNotNull { it.key.split(".").firstOrNull() }
|
||||
.filterNot { it == CUSTOM_NODE_PROPERTIES_ROOT }
|
||||
.filterNot(parameterNames::contains)
|
||||
.toSortedSet()
|
||||
if (unknownConfigurationKeys.isNotEmpty()) {
|
||||
throw UnknownConfigurationKeysException.of(unknownConfigurationKeys)
|
||||
}
|
||||
}
|
||||
val args = parameters.filterNot { it.isOptional && !hasPath(it.name!!) }.associateBy({ it }) { param ->
|
||||
// Get the matching property for this parameter
|
||||
@ -79,7 +81,7 @@ class UnknownConfigurationKeysException private constructor(val unknownKeys: Set
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <reified T : Any> Config.parseAs(): T = parseAs(T::class)
|
||||
inline fun <reified T : Any> Config.parseAs(strict: Boolean = true): T = parseAs(T::class, strict)
|
||||
|
||||
fun Config.toProperties(): Properties {
|
||||
return entrySet().associateByTo(
|
||||
|
Loading…
x
Reference in New Issue
Block a user