diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java index e93c4859d8..ff1c4759cb 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java @@ -146,14 +146,6 @@ public class PantheonCommand implements DefaultCommandValues, Runnable { // CLI options defined by user at runtime. // Options parsing is done with CLI library Picocli https://picocli.info/ - @Option( - names = {"--node-private-key-file"}, - paramLabel = MANDATORY_PATH_FORMAT_HELP, - description = - "the path to the node's private key file (default: a file named \"key\" in the Pantheon data folder)" - ) - private final File nodePrivateKeyFile = null; - // Completely disables p2p within Pantheon. @Option( names = {"--p2p-enabled"}, @@ -633,7 +625,7 @@ public class PantheonCommand implements DefaultCommandValues, Runnable { .miningParameters( new MiningParameters(coinbase, minTransactionGasPrice, extraData, isMiningEnabled)) .devMode(NetworkName.DEV.equals(getNetwork())) - .nodePrivateKeyFile(getNodePrivateKeyFile()) + .nodePrivateKeyFile(nodePrivateKeyFile()) .metricsSystem(metricsSystem) .privacyParameters(orionConfiguration()) .build(); @@ -644,12 +636,6 @@ public class PantheonCommand implements DefaultCommandValues, Runnable { } } - private File getNodePrivateKeyFile() { - return nodePrivateKeyFile != null - ? nodePrivateKeyFile - : KeyPairUtil.getDefaultKeyFile(dataDir()); - } - private JsonRpcConfiguration jsonRpcConfiguration() { CommandLineUtils.checkOptionDependencies( @@ -942,6 +928,17 @@ public class PantheonCommand implements DefaultCommandValues, Runnable { } } + private File nodePrivateKeyFile() { + File nodePrivateKeyFile = null; + if (isFullInstantiation()) { + nodePrivateKeyFile = standaloneCommands.nodePrivateKeyFile; + } + + return nodePrivateKeyFile != null + ? nodePrivateKeyFile + : KeyPairUtil.getDefaultKeyFile(dataDir()); + } + private boolean isFullInstantiation() { return !isDocker; } diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/StandaloneCommand.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/StandaloneCommand.java index cd7dc14070..83d3543515 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/StandaloneCommand.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/StandaloneCommand.java @@ -47,4 +47,12 @@ class StandaloneCommand implements DefaultCommandValues { "The path to genesis file. Setting this option makes --network option ignored and requires --network-id to be set." ) final File genesisFile = null; + + @CommandLine.Option( + names = {"--node-private-key-file"}, + paramLabel = MANDATORY_PATH_FORMAT_HELP, + description = + "the path to the node's private key file (default: a file named \"key\" in the Pantheon data folder)" + ) + final File nodePrivateKeyFile = null; } diff --git a/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java b/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java index 845f2fb8d2..e56c638cb3 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java @@ -416,6 +416,33 @@ public class PantheonCommandTest extends CommandTestAbstract { assertThat(commandErrorOutput.toString()).isEmpty(); } + @Test + public void nodekeyOptionDisabledUnderDocker() { + System.setProperty("pantheon.docker", "true"); + + assumeFalse(isFullInstantiation()); + + final File file = new File("./specific/key"); + + parseCommand("--node-private-key-file", file.getPath()); + + assertThat(commandErrorOutput.toString()) + .startsWith("Unknown options: --node-private-key-file, ."); + assertThat(commandOutput.toString()).isEmpty(); + } + + @Test + public void nodekeyDefaultedUnderDocker() { + System.setProperty("pantheon.docker", "true"); + + assumeFalse(isFullInstantiation()); + + parseCommand(); + + verify(mockControllerBuilder).nodePrivateKeyFile(fileArgumentCaptor.capture()); + assertThat(fileArgumentCaptor.getValue()).isEqualTo(new File("/var/lib/pantheon/key")); + } + @Test public void dataDirOptionMustBeUsed() throws Exception { assumeTrue(isFullInstantiation());