From 3b35d2d47a033a9929de2bad3fd62372016d3bd8 Mon Sep 17 00:00:00 2001 From: Chris Mckay Date: Thu, 21 Feb 2019 08:03:03 +1000 Subject: [PATCH] [MINOR] permission config file location and option under docker (#925) Signed-off-by: Adrian Sutton --- .../pantheon/cli/DefaultCommandValues.java | 1 + .../pegasys/pantheon/cli/PantheonCommand.java | 28 ++++++++++++------- .../pantheon/cli/StandaloneCommand.java | 6 ++++ .../pantheon/cli/PantheonCommandTest.java | 13 +++++++++ 4 files changed, 38 insertions(+), 10 deletions(-) diff --git a/pantheon/src/main/java/tech/pegasys/pantheon/cli/DefaultCommandValues.java b/pantheon/src/main/java/tech/pegasys/pantheon/cli/DefaultCommandValues.java index cf9df00f65..a605093a6d 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/DefaultCommandValues.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/DefaultCommandValues.java @@ -48,6 +48,7 @@ interface DefaultCommandValues { String DOCKER_RPC_WS_AUTHENTICATION_CREDENTIALS_FILE_LOCATION = "/etc/pantheon/rpc_ws_auth_config.toml"; String DOCKER_PRIVACY_PUBLIC_KEY_FILE = "/etc/pantheon/privacy_public_key"; + String DOCKER_PERMISSIONS_CONFIG_FILE_LOCATION = "/etc/pantheon/permissions_config.toml"; String PERMISSIONING_CONFIG_LOCATION = "permissions_config.toml"; String MANDATORY_HOST_FORMAT_HELP = ""; String MANDATORY_PORT_FORMAT_HELP = ""; 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 898d50a377..c1b99b8962 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/PantheonCommand.java @@ -440,12 +440,6 @@ public class PantheonCommand implements DefaultCommandValues, Runnable { description = "Enable account level permissions (default: ${DEFAULT-VALUE})") private final Boolean permissionsAccountsEnabled = false; - @Option( - names = {"--permissions-config-file"}, - description = - "Permissions config TOML file (default: a file named \"permissions_config.toml\" in the Pantheon data folder)") - private String permissionsConfigFile = null; - @Option( names = {"--privacy-enabled"}, description = "Enable private transactions (default: ${DEFAULT-VALUE})") @@ -550,10 +544,10 @@ public class PantheonCommand implements DefaultCommandValues, Runnable { + "or specify the beneficiary of mining (via --miner-coinbase
)"); } - if (permissionsConfigFile != null) { + if (permissionsConfigFile() != null) { if (!permissionsAccountsEnabled && !permissionsNodesEnabled) { logger.warn( - "Permissions config file set {} but no permissions enabled", permissionsConfigFile); + "Permissions config file set {} but no permissions enabled", permissionsConfigFile()); } } @@ -622,8 +616,8 @@ public class PantheonCommand implements DefaultCommandValues, Runnable { private String getPermissionsConfigFile() { - return permissionsConfigFile != null - ? permissionsConfigFile + return permissionsConfigFile() != null + ? permissionsConfigFile() : dataDir().toAbsolutePath() + System.getProperty("file.separator") + DefaultCommandValues.PERMISSIONING_CONFIG_LOCATION; @@ -1008,6 +1002,20 @@ public class PantheonCommand implements DefaultCommandValues, Runnable { return filename; } + private String permissionsConfigFile() { + String filename = null; + if (isFullInstantiation()) { + filename = standaloneCommands.permissionsConfigFile; + } else if (isDocker) { + final File file = new File(DOCKER_PERMISSIONS_CONFIG_FILE_LOCATION); + if (file.exists()) { + filename = file.getAbsolutePath(); + } + } + + return filename; + } + 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 b1154cf143..affbe41583 100644 --- a/pantheon/src/main/java/tech/pegasys/pantheon/cli/StandaloneCommand.java +++ b/pantheon/src/main/java/tech/pegasys/pantheon/cli/StandaloneCommand.java @@ -72,4 +72,10 @@ class StandaloneCommand implements DefaultCommandValues { names = {"--privacy-public-key-file"}, description = "The enclave's public key file") final File privacyPublicKeyFile = null; + + @CommandLine.Option( + names = {"--permissions-config-file"}, + description = + "Permissions config TOML file (default: a file named \"permissions_config.toml\" in the Pantheon data folder)") + String permissionsConfigFile = 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 7949572c3a..c7400b5a27 100644 --- a/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java +++ b/pantheon/src/test/java/tech/pegasys/pantheon/cli/PantheonCommandTest.java @@ -1989,4 +1989,17 @@ public class PantheonCommandTest extends CommandTestAbstract { .startsWith("Unknown options: --rpc-ws-authentication-credentials-file, ."); assertThat(commandOutput.toString()).isEmpty(); } + + @Test + public void permissionsConfigFileOptionDisabledUnderDocker() { + System.setProperty("pantheon.docker", "true"); + + assumeFalse(isFullInstantiation()); + + final Path path = Paths.get("."); + parseCommand("--permissions-config-file", path.toString()); + assertThat(commandErrorOutput.toString()) + .startsWith("Unknown options: --permissions-config-file, ."); + assertThat(commandOutput.toString()).isEmpty(); + } }