Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Commit

Permalink
Made private key option docker aware (#684)
Browse files Browse the repository at this point in the history
  • Loading branch information
Errorific authored Jan 29, 2019
1 parent 39b0aec commit 4abf13d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,6 @@ public static class RpcApisConversionException extends Exception {
// 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"},
Expand Down Expand Up @@ -633,7 +625,7 @@ PantheonController<?> buildController() {
.miningParameters(
new MiningParameters(coinbase, minTransactionGasPrice, extraData, isMiningEnabled))
.devMode(NetworkName.DEV.equals(getNetwork()))
.nodePrivateKeyFile(getNodePrivateKeyFile())
.nodePrivateKeyFile(nodePrivateKeyFile())
.metricsSystem(metricsSystem)
.privacyParameters(orionConfiguration())
.build();
Expand All @@ -644,12 +636,6 @@ PantheonController<?> buildController() {
}
}

private File getNodePrivateKeyFile() {
return nodePrivateKeyFile != null
? nodePrivateKeyFile
: KeyPairUtil.getDefaultKeyFile(dataDir());
}

private JsonRpcConfiguration jsonRpcConfiguration() {

CommandLineUtils.checkOptionDependencies(
Expand Down Expand Up @@ -942,6 +928,17 @@ private Path dataDir() {
}
}

private File nodePrivateKeyFile() {
File nodePrivateKeyFile = null;
if (isFullInstantiation()) {
nodePrivateKeyFile = standaloneCommands.nodePrivateKeyFile;
}

return nodePrivateKeyFile != null
? nodePrivateKeyFile
: KeyPairUtil.getDefaultKeyFile(dataDir());
}

private boolean isFullInstantiation() {
return !isDocker;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,33 @@ public void nodekeyOptionMustBeUsed() throws Exception {
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());
Expand Down

0 comments on commit 4abf13d

Please sign in to comment.