From fc88cefbc86577b43577e39998fdb287b8aebb10 Mon Sep 17 00:00:00 2001 From: szymonsztuka Date: Mon, 21 May 2018 10:55:44 +0100 Subject: [PATCH] CORDA-1288 Node properties can be set as system properties. (#3172) --- docs/source/corda-configuration-file.rst | 12 +++++++++++- .../corda/node/services/config/ConfigUtilities.kt | 13 +++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/docs/source/corda-configuration-file.rst b/docs/source/corda-configuration-file.rst index 3632bdd1d4..8307e2995d 100644 --- a/docs/source/corda-configuration-file.rst +++ b/docs/source/corda-configuration-file.rst @@ -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. \ No newline at end of file + 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 \ No newline at end of file diff --git a/node/src/main/kotlin/net/corda/node/services/config/ConfigUtilities.kt b/node/src/main/kotlin/net/corda/node/services/config/ConfigUtilities.kt index 3c45410f1f..39b2682621 100644 --- a/node/src/main/kotlin/net/corda/node/services/config/ConfigUtilities.kt +++ b/node/src/main/kotlin/net/corda/node/services/config/ConfigUtilities.kt @@ -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): Config = ConfigFactory.parseMap( operator fun Config.plus(overrides: Map): 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) }) + } } /**