CORDA-1288 Node properties can be set as system properties. (#3172)

This commit is contained in:
szymonsztuka 2018-05-21 10:55:44 +01:00 committed by Michele Sollecito
parent 8990e9f783
commit fc88cefbc8
2 changed files with 24 additions and 1 deletions

View File

@ -301,4 +301,14 @@ path to the node's base directory.
:permissions: A list of permissions for starting flows via RPC. To give the user the permission to start the flow
``foo.bar.FlowClass``, add the string ``StartFlow.foo.bar.FlowClass`` to the list. If the list
contains the string ``ALL``, the user can start any flow via RPC. This value is intended for administrator
users and for development.
users and for development.
Fields Override
---------------
JVM options or environmental variables prefixed ``corda.`` can override ``node.conf`` fields.
Provided system properties also can set value for absent fields in ``node.conf``.
Example adding/overriding keyStore password when starting Corda node:
.. sourcecode:: shell
java -Dcorda.rpcSettings.ssl.keyStorePassword=mypassword -jar node.jar

View File

@ -10,6 +10,7 @@ import net.corda.core.internal.div
import net.corda.core.internal.exists
import net.corda.nodeapi.internal.*
import net.corda.nodeapi.internal.config.SSLConfiguration
import net.corda.nodeapi.internal.config.toProperties
import net.corda.nodeapi.internal.crypto.X509KeyStore
import net.corda.nodeapi.internal.crypto.loadKeyStore
import net.corda.nodeapi.internal.crypto.save
@ -20,6 +21,9 @@ fun configOf(vararg pairs: Pair<String, Any?>): Config = ConfigFactory.parseMap(
operator fun Config.plus(overrides: Map<String, Any?>): Config = ConfigFactory.parseMap(overrides).withFallback(this)
object ConfigHelper {
private const val CORDA_PROPERTY_PREFIX = "corda."
private val log = LoggerFactory.getLogger(javaClass)
fun loadConfig(baseDirectory: Path,
configFile: Path = baseDirectory / "node.conf",
@ -33,10 +37,14 @@ object ConfigHelper {
val smartDevMode = CordaSystemUtils.isOsMac() || (CordaSystemUtils.isOsWindows() && !CordaSystemUtils.getOsName().toLowerCase().contains("server"))
val devModeConfig = ConfigFactory.parseMap(mapOf("devMode" to smartDevMode))
val systemOverrides = ConfigFactory.systemProperties().cordaEntriesOnly()
val environmentOverrides = ConfigFactory.systemEnvironment().cordaEntriesOnly()
val finalConfig = configOf(
// Add substitution values here
"baseDirectory" to baseDirectory.toString())
.withFallback(configOverrides)
.withFallback(systemOverrides)
.withFallback(environmentOverrides)
.withFallback(appConfig)
.withFallback(devModeConfig) // this needs to be after the appConfig, so it doesn't override the configured devMode
.withFallback(defaultConfig)
@ -52,6 +60,11 @@ object ConfigHelper {
return finalConfig
}
private fun Config.cordaEntriesOnly(): Config {
return ConfigFactory.parseMap(toProperties().filterKeys { (it as String).startsWith(CORDA_PROPERTY_PREFIX) }.mapKeys { (it.key as String).removePrefix(CORDA_PROPERTY_PREFIX) })
}
}
/**