mirror of
https://github.com/corda/corda.git
synced 2025-06-17 14:48:16 +00:00
Fixed parsing of --network-root-truststore so that it defaults to the base dir correctly (#3958)
This commit is contained in:
@ -24,10 +24,8 @@ class NodeCmdLineOptions {
|
|||||||
names = ["-f", "--config-file"],
|
names = ["-f", "--config-file"],
|
||||||
description = ["The path to the config file. By default this is node.conf in the base directory."]
|
description = ["The path to the config file. By default this is node.conf in the base directory."]
|
||||||
)
|
)
|
||||||
var configFileArgument: Path? = null
|
private var _configFile: Path? = null
|
||||||
|
val configFile: Path get() = _configFile ?: (baseDirectory / "node.conf")
|
||||||
val configFile : Path
|
|
||||||
get() = configFileArgument ?: (baseDirectory / "node.conf")
|
|
||||||
|
|
||||||
@Option(
|
@Option(
|
||||||
names = ["--sshd"],
|
names = ["--sshd"],
|
||||||
@ -57,7 +55,8 @@ class NodeCmdLineOptions {
|
|||||||
names = ["-t", "--network-root-truststore"],
|
names = ["-t", "--network-root-truststore"],
|
||||||
description = ["Network root trust store obtained from network operator."]
|
description = ["Network root trust store obtained from network operator."]
|
||||||
)
|
)
|
||||||
var networkRootTrustStorePath: Path = baseDirectory / "certificates" / "network-root-truststore.jks"
|
private var _networkRootTrustStorePath: Path? = null
|
||||||
|
val networkRootTrustStorePath: Path get() = _networkRootTrustStorePath ?: baseDirectory / "certificates" / "network-root-truststore.jks"
|
||||||
|
|
||||||
@Option(
|
@Option(
|
||||||
names = ["-p", "--network-root-truststore-password"],
|
names = ["-p", "--network-root-truststore-password"],
|
||||||
@ -101,7 +100,7 @@ class NodeCmdLineOptions {
|
|||||||
)
|
)
|
||||||
var clearNetworkMapCache: Boolean = false
|
var clearNetworkMapCache: Boolean = false
|
||||||
|
|
||||||
val nodeRegistrationOption : NodeRegistrationOption? by lazy {
|
val nodeRegistrationOption: NodeRegistrationOption? by lazy {
|
||||||
if (isRegistration) {
|
if (isRegistration) {
|
||||||
requireNotNull(networkRootTrustStorePassword) { "Network root trust store password must be provided in registration mode using --network-root-truststore-password." }
|
requireNotNull(networkRootTrustStorePassword) { "Network root trust store password must be provided in registration mode using --network-root-truststore-password." }
|
||||||
require(networkRootTrustStorePath.exists()) { "Network root trust store path: '$networkRootTrustStorePath' doesn't exist" }
|
require(networkRootTrustStorePath.exists()) { "Network root trust store path: '$networkRootTrustStorePath' doesn't exist" }
|
||||||
|
@ -7,24 +7,14 @@ import io.netty.channel.unix.Errors
|
|||||||
import net.corda.cliutils.CordaCliWrapper
|
import net.corda.cliutils.CordaCliWrapper
|
||||||
import net.corda.cliutils.CordaVersionProvider
|
import net.corda.cliutils.CordaVersionProvider
|
||||||
import net.corda.cliutils.ExitCodes
|
import net.corda.cliutils.ExitCodes
|
||||||
import net.corda.core.CordaRuntimeException
|
|
||||||
import net.corda.core.crypto.Crypto
|
import net.corda.core.crypto.Crypto
|
||||||
import net.corda.core.internal.Emoji
|
import net.corda.core.internal.*
|
||||||
import net.corda.core.internal.concurrent.thenMatch
|
import net.corda.core.internal.concurrent.thenMatch
|
||||||
import net.corda.core.internal.cordapp.CordappImpl
|
import net.corda.core.internal.cordapp.CordappImpl
|
||||||
import net.corda.core.internal.createDirectories
|
|
||||||
import net.corda.core.internal.div
|
|
||||||
import net.corda.core.internal.errors.AddressBindingException
|
import net.corda.core.internal.errors.AddressBindingException
|
||||||
import net.corda.core.internal.exists
|
|
||||||
import net.corda.core.internal.location
|
|
||||||
import net.corda.core.internal.randomOrNull
|
|
||||||
import net.corda.core.utilities.Try
|
import net.corda.core.utilities.Try
|
||||||
import net.corda.core.utilities.loggerFor
|
import net.corda.core.utilities.loggerFor
|
||||||
import net.corda.node.NodeCmdLineOptions
|
import net.corda.node.*
|
||||||
import net.corda.node.NodeRegistrationOption
|
|
||||||
import net.corda.node.SerialFilter
|
|
||||||
import net.corda.node.VersionInfo
|
|
||||||
import net.corda.node.defaultSerialFilter
|
|
||||||
import net.corda.node.internal.cordapp.MultipleCordappsForFlowException
|
import net.corda.node.internal.cordapp.MultipleCordappsForFlowException
|
||||||
import net.corda.node.services.config.NodeConfiguration
|
import net.corda.node.services.config.NodeConfiguration
|
||||||
import net.corda.node.services.config.NodeConfigurationImpl
|
import net.corda.node.services.config.NodeConfigurationImpl
|
||||||
@ -51,7 +41,6 @@ import java.io.Console
|
|||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.io.RandomAccessFile
|
import java.io.RandomAccessFile
|
||||||
import java.lang.IllegalStateException
|
|
||||||
import java.lang.management.ManagementFactory
|
import java.lang.management.ManagementFactory
|
||||||
import java.net.InetAddress
|
import java.net.InetAddress
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
@ -62,7 +51,7 @@ import java.util.*
|
|||||||
import kotlin.system.exitProcess
|
import kotlin.system.exitProcess
|
||||||
|
|
||||||
/** This class is responsible for starting a Node from command line arguments. */
|
/** This class is responsible for starting a Node from command line arguments. */
|
||||||
open class NodeStartup: CordaCliWrapper("corda", "Runs a Corda Node") {
|
open class NodeStartup : CordaCliWrapper("corda", "Runs a Corda Node") {
|
||||||
companion object {
|
companion object {
|
||||||
private val logger by lazy { loggerFor<Node>() } // I guess this is lazy to allow for logging init, but why Node?
|
private val logger by lazy { loggerFor<Node>() } // I guess this is lazy to allow for logging init, but why Node?
|
||||||
const val LOGS_DIRECTORY_NAME = "logs"
|
const val LOGS_DIRECTORY_NAME = "logs"
|
||||||
@ -71,7 +60,7 @@ open class NodeStartup: CordaCliWrapper("corda", "Runs a Corda Node") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Mixin
|
@Mixin
|
||||||
var cmdLineOptions = NodeCmdLineOptions()
|
val cmdLineOptions = NodeCmdLineOptions()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return exit code based on the success of the node startup. This value is intended to be the exit code of the process.
|
* @return exit code based on the success of the node startup. This value is intended to be the exit code of the process.
|
||||||
@ -221,15 +210,14 @@ open class NodeStartup: CordaCliWrapper("corda", "Runs a Corda Node") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun checkRegistrationMode(): Boolean {
|
private fun checkRegistrationMode(): Boolean {
|
||||||
val baseDirectory = cmdLineOptions.baseDirectory.normalize().toAbsolutePath()
|
|
||||||
// If the node was started with `--initial-registration`, create marker file.
|
// If the node was started with `--initial-registration`, create marker file.
|
||||||
// We do this here to ensure the marker is created even if parsing the args with NodeArgsParser fails.
|
// We do this here to ensure the marker is created even if parsing the args with NodeArgsParser fails.
|
||||||
val marker = File((baseDirectory / INITIAL_REGISTRATION_MARKER).toUri())
|
val marker = cmdLineOptions.baseDirectory / INITIAL_REGISTRATION_MARKER
|
||||||
if (!cmdLineOptions.isRegistration && !marker.exists()) {
|
if (!cmdLineOptions.isRegistration && !marker.exists()) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
marker.createNewFile()
|
marker.createFile()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
logger.warn("Could not create marker file for `--initial-registration`.", e)
|
logger.warn("Could not create marker file for `--initial-registration`.", e)
|
||||||
}
|
}
|
||||||
|
@ -1,43 +0,0 @@
|
|||||||
package net.corda.node
|
|
||||||
|
|
||||||
import net.corda.core.internal.div
|
|
||||||
import net.corda.node.internal.NodeStartup
|
|
||||||
import net.corda.nodeapi.internal.config.UnknownConfigKeysPolicy
|
|
||||||
import org.assertj.core.api.Assertions.assertThat
|
|
||||||
import org.junit.BeforeClass
|
|
||||||
import org.junit.Test
|
|
||||||
import org.slf4j.event.Level
|
|
||||||
import java.nio.file.Path
|
|
||||||
import java.nio.file.Paths
|
|
||||||
|
|
||||||
class NodeCmdLineOptionsTest {
|
|
||||||
private val parser = NodeStartup()
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
private lateinit var workingDirectory: Path
|
|
||||||
|
|
||||||
@BeforeClass
|
|
||||||
@JvmStatic
|
|
||||||
fun initDirectories() {
|
|
||||||
workingDirectory = Paths.get(".").normalize().toAbsolutePath()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `no command line arguments`() {
|
|
||||||
assertThat(parser.cmdLineOptions.baseDirectory).isEqualTo(workingDirectory)
|
|
||||||
assertThat(parser.cmdLineOptions.configFile).isEqualTo(workingDirectory / "node.conf")
|
|
||||||
assertThat(parser.verbose).isEqualTo(false)
|
|
||||||
assertThat(parser.loggingLevel).isEqualTo(Level.INFO)
|
|
||||||
assertThat(parser.cmdLineOptions.nodeRegistrationOption).isEqualTo(null)
|
|
||||||
assertThat(parser.cmdLineOptions.noLocalShell).isEqualTo(false)
|
|
||||||
assertThat(parser.cmdLineOptions.sshdServer).isEqualTo(false)
|
|
||||||
assertThat(parser.cmdLineOptions.justGenerateNodeInfo).isEqualTo(false)
|
|
||||||
assertThat(parser.cmdLineOptions.justGenerateRpcSslCerts).isEqualTo(false)
|
|
||||||
assertThat(parser.cmdLineOptions.bootstrapRaftCluster).isEqualTo(false)
|
|
||||||
assertThat(parser.cmdLineOptions.unknownConfigKeysPolicy).isEqualTo(UnknownConfigKeysPolicy.FAIL)
|
|
||||||
assertThat(parser.cmdLineOptions.devMode).isEqualTo(null)
|
|
||||||
assertThat(parser.cmdLineOptions.clearNetworkMapCache).isEqualTo(false)
|
|
||||||
assertThat(parser.cmdLineOptions.networkRootTrustStorePath).isEqualTo(workingDirectory / "certificates" / "network-root-truststore.jks")
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,52 @@
|
|||||||
|
package net.corda.node.internal
|
||||||
|
|
||||||
|
import net.corda.core.internal.div
|
||||||
|
import net.corda.nodeapi.internal.config.UnknownConfigKeysPolicy
|
||||||
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
|
import org.junit.BeforeClass
|
||||||
|
import org.junit.Test
|
||||||
|
import org.slf4j.event.Level
|
||||||
|
import picocli.CommandLine
|
||||||
|
import java.nio.file.Path
|
||||||
|
import java.nio.file.Paths
|
||||||
|
|
||||||
|
class NodeStartupTest {
|
||||||
|
private val startup = NodeStartup()
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private lateinit var workingDirectory: Path
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
@JvmStatic
|
||||||
|
fun initDirectories() {
|
||||||
|
workingDirectory = Paths.get(".").normalize().toAbsolutePath()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `no command line arguments`() {
|
||||||
|
CommandLine.populateCommand(startup)
|
||||||
|
assertThat(startup.cmdLineOptions.baseDirectory).isEqualTo(workingDirectory)
|
||||||
|
assertThat(startup.cmdLineOptions.configFile).isEqualTo(workingDirectory / "node.conf")
|
||||||
|
assertThat(startup.verbose).isEqualTo(false)
|
||||||
|
assertThat(startup.loggingLevel).isEqualTo(Level.INFO)
|
||||||
|
assertThat(startup.cmdLineOptions.nodeRegistrationOption).isEqualTo(null)
|
||||||
|
assertThat(startup.cmdLineOptions.noLocalShell).isEqualTo(false)
|
||||||
|
assertThat(startup.cmdLineOptions.sshdServer).isEqualTo(false)
|
||||||
|
assertThat(startup.cmdLineOptions.justGenerateNodeInfo).isEqualTo(false)
|
||||||
|
assertThat(startup.cmdLineOptions.justGenerateRpcSslCerts).isEqualTo(false)
|
||||||
|
assertThat(startup.cmdLineOptions.bootstrapRaftCluster).isEqualTo(false)
|
||||||
|
assertThat(startup.cmdLineOptions.unknownConfigKeysPolicy).isEqualTo(UnknownConfigKeysPolicy.FAIL)
|
||||||
|
assertThat(startup.cmdLineOptions.devMode).isEqualTo(null)
|
||||||
|
assertThat(startup.cmdLineOptions.clearNetworkMapCache).isEqualTo(false)
|
||||||
|
assertThat(startup.cmdLineOptions.networkRootTrustStorePath).isEqualTo(workingDirectory / "certificates" / "network-root-truststore.jks")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `--base-directory`() {
|
||||||
|
CommandLine.populateCommand(startup, "--base-directory", (workingDirectory / "another-base-dir").toString())
|
||||||
|
assertThat(startup.cmdLineOptions.baseDirectory).isEqualTo(workingDirectory / "another-base-dir")
|
||||||
|
assertThat(startup.cmdLineOptions.configFile).isEqualTo(workingDirectory / "another-base-dir" / "node.conf")
|
||||||
|
assertThat(startup.cmdLineOptions.networkRootTrustStorePath).isEqualTo(workingDirectory / "another-base-dir" / "certificates" / "network-root-truststore.jks")
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user