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.util.*
|
||||
|
||||
class DoormanParameters(args: Array<String>) {
|
||||
class DoormanParameters(vararg args: String) {
|
||||
private val argConfig = args.toConfigWithOptions {
|
||||
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")
|
||||
|
@ -201,7 +201,7 @@ private fun DoormanParameters.startDoorman() {
|
||||
fun main(args: Array<String>) {
|
||||
try {
|
||||
// TODO : Remove config overrides and solely use config file after testnet is finalized.
|
||||
DoormanParameters(args).run {
|
||||
DoormanParameters(*args).run {
|
||||
when (mode) {
|
||||
DoormanParameters.Mode.ROOT_KEYGEN -> generateRootKeyPair()
|
||||
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].
|
||||
*/
|
||||
object OptionParserHelper {
|
||||
fun Array<String>.toConfigWithOptions(registerOptions: OptionParser.() -> Unit): Config {
|
||||
fun Array<out String>.toConfigWithOptions(registerOptions: OptionParser.() -> Unit): Config {
|
||||
val parser = OptionParser()
|
||||
val helpOption = parser.acceptsAll(listOf("h", "?", "help"), "show help").forHelp();
|
||||
registerOptions(parser)
|
||||
|
@ -3,6 +3,7 @@ package com.r3.corda.doorman
|
||||
import com.typesafe.config.ConfigException
|
||||
import org.junit.Test
|
||||
import java.io.File
|
||||
import java.nio.file.Paths
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFailsWith
|
||||
|
||||
@ -10,23 +11,27 @@ class DoormanParametersTest {
|
||||
private val testDummyPath = ".${File.separator}testDummyPath.jks"
|
||||
|
||||
@Test
|
||||
fun `parse arg correctly`() {
|
||||
val ref = javaClass.getResource("/node.conf")
|
||||
val params = DoormanParameters(arrayOf("--keygen", "--keystorePath", testDummyPath, "--configFile", ref.path))
|
||||
assertEquals(DoormanParameters.Mode.CA_KEYGEN, params.mode)
|
||||
assertEquals(testDummyPath, params.keystorePath.toString())
|
||||
assertEquals(8080, params.port)
|
||||
fun `parse mode flag arg correctly`() {
|
||||
assertEquals(DoormanParameters.Mode.CA_KEYGEN, DoormanParameters("--keygen").mode)
|
||||
assertEquals(DoormanParameters.Mode.ROOT_KEYGEN, DoormanParameters("--rootKeygen").mode)
|
||||
assertEquals(DoormanParameters.Mode.DOORMAN, DoormanParameters().mode)
|
||||
}
|
||||
|
||||
val params2 = DoormanParameters(arrayOf("--keystorePath", testDummyPath, "--port", "1000"))
|
||||
assertEquals(DoormanParameters.Mode.DOORMAN, params2.mode)
|
||||
assertEquals(testDummyPath, params2.keystorePath.toString())
|
||||
assertEquals(1000, params2.port)
|
||||
@Test
|
||||
fun `command line arg should override config file`() {
|
||||
val params = DoormanParameters("--keystorePath", testDummyPath, "--port", "1000", "--configFile", javaClass.getResource("/node.conf").path)
|
||||
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
|
||||
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.
|
||||
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 }
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user