Made private key option docker aware (#684)

Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>
pull/2/head
Chris Mckay 6 years ago committed by GitHub
parent 214ddcc60a
commit 157b42ed19
  1. 27
      pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java
  2. 8
      pantheon/src/main/java/tech/pegasys/pantheon/cli/StandaloneCommand.java
  3. 27
      pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.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;
}

@ -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;
}

@ -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());

Loading…
Cancel
Save