mirror of
https://github.com/corda/corda.git
synced 2024-12-29 09:18:58 +00:00
Merged in pat-stop-using-reference-conf-in-doorman (pull request #26)
Stop using reference.conf from corda node in doorman Approved-by: Shams Asari
This commit is contained in:
commit
b0f0def35d
@ -2,17 +2,18 @@ package com.r3.corda.doorman
|
|||||||
|
|
||||||
import com.r3.corda.doorman.OptionParserHelper.toConfigWithOptions
|
import com.r3.corda.doorman.OptionParserHelper.toConfigWithOptions
|
||||||
import com.typesafe.config.Config
|
import com.typesafe.config.Config
|
||||||
|
import com.typesafe.config.ConfigFactory
|
||||||
|
import com.typesafe.config.ConfigParseOptions
|
||||||
import net.corda.core.div
|
import net.corda.core.div
|
||||||
import net.corda.node.services.config.ConfigHelper
|
|
||||||
import net.corda.node.services.config.getOrElse
|
import net.corda.node.services.config.getOrElse
|
||||||
import net.corda.node.services.config.getValue
|
import net.corda.node.services.config.getValue
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
import java.nio.file.Paths
|
|
||||||
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().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("keygen", "Generate CA keypair and certificate using provide Root CA key.").withOptionalArg()
|
accepts("keygen", "Generate CA keypair and certificate using provide Root CA key.").withOptionalArg()
|
||||||
accepts("rootKeygen", "Generate Root CA keypair and certificate.").withOptionalArg()
|
accepts("rootKeygen", "Generate Root CA keypair and certificate.").withOptionalArg()
|
||||||
accepts("keystorePath", "CA keystore filepath, default to [basedir]/certificates/caKeystore.jks.").withRequiredArg().describedAs("filepath")
|
accepts("keystorePath", "CA keystore filepath, default to [basedir]/certificates/caKeystore.jks.").withRequiredArg().describedAs("filepath")
|
||||||
@ -24,8 +25,9 @@ class DoormanParameters(args: Array<String>) {
|
|||||||
accepts("host", "Doorman web service host override").withRequiredArg().describedAs("hostname")
|
accepts("host", "Doorman web service host override").withRequiredArg().describedAs("hostname")
|
||||||
accepts("port", "Doorman web service port override").withRequiredArg().ofType(Int::class.java).describedAs("port number")
|
accepts("port", "Doorman web service port override").withRequiredArg().ofType(Int::class.java).describedAs("port number")
|
||||||
}
|
}
|
||||||
private val basedir by argConfig.getOrElse { Paths.get(".") }
|
private val basedir: Path by argConfig
|
||||||
private val config = argConfig.withFallback(ConfigHelper.loadConfig(basedir, allowMissingConfig = true))
|
private val configFile by argConfig.getOrElse { basedir / "node.conf" }
|
||||||
|
private val config = argConfig.withFallback(ConfigFactory.parseFile(configFile.toFile(), ConfigParseOptions.defaults().setAllowMissing(true))).resolve()
|
||||||
val keystorePath: Path by config.getOrElse { basedir / "certificates" / "caKeystore.jks" }
|
val keystorePath: Path by config.getOrElse { basedir / "certificates" / "caKeystore.jks" }
|
||||||
val rootStorePath: Path by config.getOrElse { basedir / "certificates" / "rootCAKeystore.jks" }
|
val rootStorePath: Path by config.getOrElse { basedir / "certificates" / "rootCAKeystore.jks" }
|
||||||
val keystorePassword: String? by config.getOrElse { null }
|
val keystorePassword: String? by config.getOrElse { null }
|
||||||
|
@ -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)
|
||||||
|
@ -1,24 +1,37 @@
|
|||||||
package com.r3.corda.doorman
|
package com.r3.corda.doorman
|
||||||
|
|
||||||
|
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.assertTrue
|
import kotlin.test.assertFailsWith
|
||||||
|
|
||||||
class DoormanParametersTest {
|
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 params = DoormanParameters(arrayOf("--keygen", "--keystorePath", testDummyPath))
|
assertEquals(DoormanParameters.Mode.CA_KEYGEN, DoormanParameters("--keygen").mode)
|
||||||
assertEquals(DoormanParameters.Mode.CA_KEYGEN, params.mode)
|
assertEquals(DoormanParameters.Mode.ROOT_KEYGEN, DoormanParameters("--rootKeygen").mode)
|
||||||
assertEquals(testDummyPath, params.keystorePath.toString())
|
assertEquals(DoormanParameters.Mode.DOORMAN, DoormanParameters().mode)
|
||||||
assertEquals(0, 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
|
||||||
|
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("--keygen", "--keystorePath", testDummyPath, "--configFile", javaClass.getResource("/node_fail.conf").path)
|
||||||
|
assertFailsWith<ConfigException.Missing> { params.dataSourceProperties }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
13
doorman/src/test/resources/node.conf
Normal file
13
doorman/src/test/resources/node.conf
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
keystorePath = "/opt/doorman/certificates/caKeystore.jks"
|
||||||
|
keyStorePassword = "password"
|
||||||
|
caPrivateKeyPassword = "password"
|
||||||
|
host = "localhost"
|
||||||
|
port = 8080
|
||||||
|
h2port = 0
|
||||||
|
|
||||||
|
dataSourceProperties {
|
||||||
|
"dataSourceClassName" = org.h2.jdbcx.JdbcDataSource
|
||||||
|
"dataSource.url" = "jdbc:h2:file:"${basedir}"/persistence;DB_CLOSE_ON_EXIT=FALSE;LOCK_TIMEOUT=10000;WRITE_DELAY=0;AUTO_SERVER_PORT="${h2port}
|
||||||
|
"dataSource.user" = sa
|
||||||
|
"dataSource.password" = ""
|
||||||
|
}
|
6
doorman/src/test/resources/node_fail.conf
Normal file
6
doorman/src/test/resources/node_fail.conf
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
keystorePath = "/opt/doorman/certificates/caKeystore.jks"
|
||||||
|
keyStorePassword = "password"
|
||||||
|
caPrivateKeyPassword = "password"
|
||||||
|
host = "localhost"
|
||||||
|
port = 8080
|
||||||
|
h2port = 0
|
Loading…
Reference in New Issue
Block a user