ENT-2653: Minor command line tools changes (#1577)

* ENT-2653: Correcting "country" typo.

* ENT-2653: Introduce common constant for command line tools and use it.
This commit is contained in:
Viktor Kolomeyko 2018-11-20 15:01:46 +00:00 committed by GitHub
parent a3a9be6594
commit 8ef4de9eaf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 22 additions and 9 deletions

View File

@ -3,6 +3,7 @@ package net.corda.bridge
import net.corda.bridge.services.api.FirewallConfiguration
import net.corda.bridge.services.config.BridgeConfigHelper
import net.corda.bridge.services.config.parseAsFirewallConfiguration
import net.corda.cliutils.CommonCliConstants.BASE_DIR
import net.corda.core.internal.div
import net.corda.core.internal.exists
import net.corda.core.utilities.contextLogger
@ -32,7 +33,7 @@ class FirewallCmdLineOptions {
}
@Option(
names = ["-b", "--base-directory"],
names = ["-b", BASE_DIR],
description = ["The firewall working directory where all the files are kept."]
)
var baseDirectory: Path = Paths.get(".").toAbsolutePath().normalize()

View File

@ -22,7 +22,7 @@ class FirewallStartup: CordaCliWrapper("corda-firewall", "The Corda Firewall app
companion object {
// lazy init the logging, because the logging levels aren't configured until we have parsed some options.
private val log by lazy { contextLogger() }
val LOGS_DIRECTORY_NAME = "logs"
const val LOGS_DIRECTORY_NAME = "logs"
}
@Mixin

View File

@ -86,7 +86,7 @@ Command-line options
* ``-p``, ``--password=<password>``: Default password for all generated keystore and private keys. Default: changeit
* ``-o``, ``--organization=<organization>``: X500Name's organization attribute. Default: Corda
* ``-l``, ``--locality=<locality>``: X500Name's locality attribute. Default: London
* ``-c``, ``--county=<country>``: X500Name's country attribute. Default: GB
* ``-c``, ``--country=<country>``: X500Name's country attribute. Default: GB
* ``-b``, ``--base-directory=<baseDirectory>``: The node working directory where all the files are kept.
* ``-h``, ``--help``: Show this help message and exit.
* ``-V``, ``--version``: Print version information and exit.

View File

@ -186,6 +186,13 @@ abstract class CordaCliWrapper(alias: String, description: String) : CliWrapperB
fun printHelp() = cmd.usage(System.out)
}
/**
* Useful commonly used constants applicable to many CLI tools
*/
object CommonCliConstants {
const val BASE_DIR = "--base-directory"
}
/**
* Converter from String to slf4j logging Level.
*/

View File

@ -1,6 +1,7 @@
package com.r3.ha.utilities
import net.corda.cliutils.CliWrapperBase
import net.corda.cliutils.CommonCliConstants.BASE_DIR
import net.corda.cliutils.ExitCodes
import net.corda.core.crypto.SecureHash
import net.corda.core.internal.div
@ -16,7 +17,7 @@ class BridgeSSLKeyTool : CliWrapperBase("import-ssl-key", "Key copying tool for
lateinit var nodeKeystore: Array<Path>
@Option(names = ["--node-keystore-passwords"], arity = "1..*", paramLabel = "PASSWORDS", description = ["The password(s) of the node SSL keystore(s)"], required = true)
lateinit var nodeKeystorePasswords: Array<String>
@Option(names = ["-b", "--base-directory"], paramLabel = "FOLDER", description = ["The working directory where all the files are kept."])
@Option(names = ["-b", BASE_DIR], paramLabel = "FOLDER", description = ["The working directory where all the files are kept."])
var baseDirectory: Path = Paths.get(".").toAbsolutePath().normalize()
@Option(names = ["-k", "--bridge-keystore"], paramLabel = "FILES", description = ["The path to the bridge SSL keystore."])
private var _bridgeKeystore: Path? = null

View File

@ -1,6 +1,7 @@
package com.r3.ha.utilities
import net.corda.cliutils.CliWrapperBase
import net.corda.cliutils.CommonCliConstants.BASE_DIR
import net.corda.cliutils.ExitCodes
import net.corda.core.crypto.Crypto
import net.corda.core.internal.div
@ -19,7 +20,7 @@ class InternalKeystoreGenerator : CliWrapperBase("generate-internal-ssl-keystore
private const val DEFAULT_PASSWORD = "changeit"
}
@Option(names = ["-b", "--base-directory"], description = ["The node working directory where all the files are kept."])
@Option(names = ["-b", BASE_DIR], description = ["The node working directory where all the files are kept."])
var baseDirectory: Path = Paths.get(".").toAbsolutePath().normalize()
// TODO: options to generate keys for different HA deployment mode?
@ -31,7 +32,7 @@ class InternalKeystoreGenerator : CliWrapperBase("generate-internal-ssl-keystore
var organizationUnit: String? = null
@Option(names = ["-l", "--locality"], description = ["X500Name's locality attribute."], defaultValue = "London")
lateinit var locality: String
@Option(names = ["-c", "--county"], description = ["X500Name's country attribute."], defaultValue = "GB")
@Option(names = ["-c", "--country"], description = ["X500Name's country attribute."], defaultValue = "GB")
lateinit var country: String
override fun runProgram(): Int {

View File

@ -1,6 +1,7 @@
package com.r3.ha.utilities
import com.typesafe.config.ConfigValueFactory
import net.corda.cliutils.CommonCliConstants.BASE_DIR
import net.corda.cliutils.CordaCliWrapper
import net.corda.cliutils.CordaVersionProvider
import net.corda.cliutils.ExitCodes
@ -26,7 +27,7 @@ class RegistrationTool : CordaCliWrapper("node-registration", "Corda registratio
CordaVersionProvider.vendor)
}
@Option(names = ["-b", "--base-directory"], paramLabel = "FOLDER", description = ["The node working directory where all the files are kept."])
@Option(names = ["-b", BASE_DIR], paramLabel = "FOLDER", description = ["The node working directory where all the files are kept."])
var baseDirectory: Path = Paths.get(".").toAbsolutePath().normalize()
@Option(names = ["--config-files", "-f"], arity = "1..*", paramLabel = "FILE", description = ["The path to the config file"], required = true)
lateinit var configFiles: List<Path>

View File

@ -1,5 +1,6 @@
package com.r3.ha.utilities
import net.corda.cliutils.CommonCliConstants.BASE_DIR
import net.corda.core.internal.div
import net.corda.core.internal.exists
import net.corda.nodeapi.internal.crypto.X509KeyStore
@ -22,7 +23,7 @@ class InternalKeystoreGeneratorTest {
@Test
fun `generate keystores correctly`() {
val workingDirectory = tempFolder.root.toPath()
CommandLine.populateCommand(generator, "--base-directory", workingDirectory.toString())
CommandLine.populateCommand(generator, BASE_DIR, workingDirectory.toString())
Assertions.assertThat(generator.baseDirectory).isEqualTo(workingDirectory)
generator.runProgram()

View File

@ -1,5 +1,6 @@
package com.r3.ha.utilities
import net.corda.cliutils.CommonCliConstants.BASE_DIR
import net.corda.core.internal.copyTo
import net.corda.core.internal.div
import net.corda.core.internal.exists
@ -37,7 +38,7 @@ class RegistrationToolTest {
RegistrationServer(NetworkHostAndPort("localhost", 10000)).use {
it.start()
CommandLine.populateCommand(registrationTool, "--base-directory", workingDirectory.toString(),
CommandLine.populateCommand(registrationTool, BASE_DIR, workingDirectory.toString(),
"--network-root-truststore", trustStorePath.toString(),
"--network-root-truststore-password", "password",
"--config-files", (workingDirectory / "nodeA.conf").toString(), (workingDirectory / "nodeB.conf").toString(), (workingDirectory / "nodeC.conf").toString())