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

Commit

Permalink
[MINOR] permission config file location and option under docker (#925)
Browse files Browse the repository at this point in the history
  • Loading branch information
Errorific authored Feb 20, 2019
1 parent ff6f7ee commit 28ea0a2
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<HOST>";
String MANDATORY_PORT_FORMAT_HELP = "<PORT>";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,12 +440,6 @@ private Long configureRefreshDelay(final Long refreshDelay) {
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})")
Expand Down Expand Up @@ -550,10 +544,10 @@ public void run() {
+ "or specify the beneficiary of mining (via --miner-coinbase <Address>)");
}

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

Expand Down Expand Up @@ -622,8 +616,8 @@ PantheonController<?> buildController() {

private String getPermissionsConfigFile() {

return permissionsConfigFile != null
? permissionsConfigFile
return permissionsConfigFile() != null
? permissionsConfigFile()
: dataDir().toAbsolutePath()
+ System.getProperty("file.separator")
+ DefaultCommandValues.PERMISSIONING_CONFIG_LOCATION;
Expand Down Expand Up @@ -1008,6 +1002,20 @@ private String rpcWsAuthenticationCredentialsFile() {
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -1989,4 +1989,17 @@ public void rpcWsAuthCredentialsFileOptionDisabledUnderDocker() {
.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();
}
}

0 comments on commit 28ea0a2

Please sign in to comment.