mirror of
https://github.com/corda/corda.git
synced 2024-12-29 09:18:58 +00:00
address PR issues
This commit is contained in:
parent
db2840c76a
commit
42a6a8302c
@ -10,7 +10,7 @@ import net.corda.node.services.config.getValue
|
|||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class DoormanParameters(args: Array<String>) {
|
class DoormanParameters(vararg args: String) {
|
||||||
private val argConfig = args.toConfigWithOptions {
|
private val argConfig = args.toConfigWithOptions {
|
||||||
accepts("basedir", "Overriding configuration filepath, default to current directory.").withRequiredArg().defaultsTo(".").describedAs("filepath")
|
accepts("basedir", "Overriding configuration filepath, default to current directory.").withRequiredArg().defaultsTo(".").describedAs("filepath")
|
||||||
accepts("configFile", "Overriding configuration file, default to <<current directory>>/node.conf.").withRequiredArg().describedAs("filepath")
|
accepts("configFile", "Overriding configuration file, default to <<current directory>>/node.conf.").withRequiredArg().describedAs("filepath")
|
||||||
|
@ -201,7 +201,7 @@ private fun DoormanParameters.startDoorman() {
|
|||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
try {
|
try {
|
||||||
// TODO : Remove config overrides and solely use config file after testnet is finalized.
|
// TODO : Remove config overrides and solely use config file after testnet is finalized.
|
||||||
DoormanParameters(args).run {
|
DoormanParameters(*args).run {
|
||||||
when (mode) {
|
when (mode) {
|
||||||
DoormanParameters.Mode.ROOT_KEYGEN -> generateRootKeyPair()
|
DoormanParameters.Mode.ROOT_KEYGEN -> generateRootKeyPair()
|
||||||
DoormanParameters.Mode.CA_KEYGEN -> generateCAKeyPair()
|
DoormanParameters.Mode.CA_KEYGEN -> generateCAKeyPair()
|
||||||
|
@ -9,7 +9,7 @@ import joptsimple.OptionParser
|
|||||||
* Convert commandline arguments to [Config] object will allow us to use kotlin delegate with [ConfigHelper].
|
* Convert commandline arguments to [Config] object will allow us to use kotlin delegate with [ConfigHelper].
|
||||||
*/
|
*/
|
||||||
object OptionParserHelper {
|
object OptionParserHelper {
|
||||||
fun Array<String>.toConfigWithOptions(registerOptions: OptionParser.() -> Unit): Config {
|
fun Array<out String>.toConfigWithOptions(registerOptions: OptionParser.() -> Unit): Config {
|
||||||
val parser = OptionParser()
|
val parser = OptionParser()
|
||||||
val helpOption = parser.acceptsAll(listOf("h", "?", "help"), "show help").forHelp();
|
val helpOption = parser.acceptsAll(listOf("h", "?", "help"), "show help").forHelp();
|
||||||
registerOptions(parser)
|
registerOptions(parser)
|
||||||
|
@ -3,6 +3,7 @@ package com.r3.corda.doorman
|
|||||||
import com.typesafe.config.ConfigException
|
import com.typesafe.config.ConfigException
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.nio.file.Paths
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
import kotlin.test.assertFailsWith
|
import kotlin.test.assertFailsWith
|
||||||
|
|
||||||
@ -10,23 +11,27 @@ class DoormanParametersTest {
|
|||||||
private val testDummyPath = ".${File.separator}testDummyPath.jks"
|
private val testDummyPath = ".${File.separator}testDummyPath.jks"
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `parse arg correctly`() {
|
fun `parse mode flag arg correctly`() {
|
||||||
val ref = javaClass.getResource("/node.conf")
|
assertEquals(DoormanParameters.Mode.CA_KEYGEN, DoormanParameters("--keygen").mode)
|
||||||
val params = DoormanParameters(arrayOf("--keygen", "--keystorePath", testDummyPath, "--configFile", ref.path))
|
assertEquals(DoormanParameters.Mode.ROOT_KEYGEN, DoormanParameters("--rootKeygen").mode)
|
||||||
assertEquals(DoormanParameters.Mode.CA_KEYGEN, params.mode)
|
assertEquals(DoormanParameters.Mode.DOORMAN, DoormanParameters().mode)
|
||||||
assertEquals(testDummyPath, params.keystorePath.toString())
|
}
|
||||||
assertEquals(8080, params.port)
|
|
||||||
|
|
||||||
val params2 = DoormanParameters(arrayOf("--keystorePath", testDummyPath, "--port", "1000"))
|
@Test
|
||||||
assertEquals(DoormanParameters.Mode.DOORMAN, params2.mode)
|
fun `command line arg should override config file`() {
|
||||||
assertEquals(testDummyPath, params2.keystorePath.toString())
|
val params = DoormanParameters("--keystorePath", testDummyPath, "--port", "1000", "--configFile", javaClass.getResource("/node.conf").path)
|
||||||
assertEquals(1000, params2.port)
|
assertEquals(testDummyPath, params.keystorePath.toString())
|
||||||
|
assertEquals(1000, params.port)
|
||||||
|
|
||||||
|
val params2 = DoormanParameters("--configFile", javaClass.getResource("/node.conf").path)
|
||||||
|
assertEquals(Paths.get("/opt/doorman/certificates/caKeystore.jks"), params2.keystorePath)
|
||||||
|
assertEquals(8080, params2.port)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `should fail when config missing`() {
|
fun `should fail when config missing`() {
|
||||||
// dataSourceProperties is missing from node_fail.conf and it should fail when accessed, and shouldn't use default from reference.conf.
|
// dataSourceProperties is missing from node_fail.conf and it should fail when accessed, and shouldn't use default from reference.conf.
|
||||||
val params = DoormanParameters(arrayOf("--keygen", "--keystorePath", testDummyPath, "--configFile", javaClass.getResource("/node_fail.conf").path))
|
val params = DoormanParameters("--keygen", "--keystorePath", testDummyPath, "--configFile", javaClass.getResource("/node_fail.conf").path)
|
||||||
assertFailsWith<ConfigException.Missing> { params.dataSourceProperties }
|
assertFailsWith<ConfigException.Missing> { params.dataSourceProperties }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user