@Test public void providingCliArgsOverridesTomlFileConfig() throws Exception { Path sampleFile = Paths.get(getClass().getResource("/sample.conf").toURI()); String data = Files.readAllLines(sampleFile).stream().collect(Collectors.joining(System.lineSeparator())); Path configFile = Files.createTempFile("noOptions", ".txt"); Files.write(configFile, data.getBytes()); Path workdir = Paths.get("override"); if (Files.exists(workdir)) { Files.walk(workdir).sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete); } Files.createDirectory(workdir); Files.createFile(workdir.resolve("new.pub")); Files.createFile(workdir.resolve("new.key")); Path alwaysSendToFile = Files.createFile(workdir.resolve("alwayssendto")); Files.write( alwaysSendToFile, ("/+UuD63zItL1EbjxkKUljMgG8Z1w0AJ8pNOR4iq2yQc=\n" + "jWKqelS4XjJ67JBbuKE7x9CVGFJ706wRYy/ev/OCOzk=") .getBytes()); String[] args = { "--tomlfile", configFile.toString(), "--url", "http: "--port", "1111", "--workdir", "override", "--socket", "cli.ipc", "--othernodes", "http: "--publickeys", "new.pub", "--privatekeys", "new.key", "--alwayssendto", "alwayssendto", "--passwords", "pw.txt", "--storage", "jdbc:test", "--ipwhitelist", "--tls", "off", "--tlsservercert", "over-server-cert.pem", "--tlsserverchain", "serverchain.file", "--tlsserverkey", "over-server-key.pem", "--tlsservertrust", "whitelist", "--tlsknownclients", "over-known-clients", "--tlsclientcert", "over-client-cert.pem", "--tlsclientchain", "clientchain.file", "--tlsclientkey", "over-client-key.pem", "--tlsclienttrust", "tofu", "--tlsknownservers", "over-known-servers" }; commandLine.execute(args); final CliResult result = commandLine.getExecutionResult(); assertThat(result).isNotNull(); assertThat(result.getConfig()).isPresent(); final Config config = result.getConfig().get(); final ServerConfig p2pServer = config.getP2PServerConfig(); final SslConfig sslConfig = p2pServer.getSslConfig(); assertThat(p2pServer.getServerAddress()).isEqualTo("http: assertThat(p2pServer.getBindingAddress()).isEqualTo("http: assertThat(this.getUnixSocketServerAddress(config)) .isEqualTo("unix:" + Paths.get("override/cli.ipc").toAbsolutePath()); assertThat(config.getPeers()).hasSize(1).extracting("url").containsExactlyInAnyOrder("http: assertThat(config.getKeys().getKeyData()) .hasSize(1) .flatExtracting("publicKeyPath", "privateKeyPath") .containsExactlyInAnyOrder(Paths.get("override/new.pub"), Paths.get("override/new.key")); assertThat(config.getAlwaysSendTo()) .hasSize(2) .containsExactlyInAnyOrder( "/+UuD63zItL1EbjxkKUljMgG8Z1w0AJ8pNOR4iq2yQc=", "jWKqelS4XjJ67JBbuKE7x9CVGFJ706wRYy/ev/OCOzk="); assertThat(config.getKeys().getPasswordFile().toString()).isEqualTo("override/pw.txt"); assertThat(config.getJdbcConfig().getUrl()).isEqualTo("jdbc:test"); assertThat(config.isUseWhiteList()).isTrue(); assertThat(sslConfig.getTls()).isEqualByComparingTo(SslAuthenticationMode.OFF); assertThat(sslConfig.getServerTlsCertificatePath().toString()).isEqualTo("override/over-server-cert.pem"); assertThat(sslConfig.getServerTrustCertificates()).hasSize(1); assertThat(sslConfig.getServerTrustCertificates().get(0).toString()).isEqualTo("override/serverchain.file"); assertThat(sslConfig.getServerTlsKeyPath().toString()).isEqualTo("override/over-server-key.pem"); assertThat(sslConfig.getServerTrustMode()).isEqualByComparingTo(SslTrustMode.WHITELIST); assertThat(sslConfig.getKnownClientsFile().toString()).isEqualTo("override/over-known-clients"); assertThat(sslConfig.getClientTlsCertificatePath().toString()).isEqualTo("override/over-client-cert.pem"); assertThat(sslConfig.getClientTrustCertificates()).hasSize(1); assertThat(sslConfig.getClientTrustCertificates().get(0).toString()).isEqualTo("override/clientchain.file"); assertThat(sslConfig.getClientTlsKeyPath().toString()).isEqualTo("override/over-client-key.pem"); assertThat(sslConfig.getClientTrustMode()).isEqualByComparingTo(SslTrustMode.TOFU); assertThat(sslConfig.getKnownServersFile().toString()).isEqualTo("override/over-known-servers"); Files.walk(workdir).sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete); }
@Override public CliResult execute(String... args) throws Exception { final ConfigBuilder configBuilder = Optional.ofNullable(tomlfile) .map(fileDelegate::newInputStream) .map(stream -> this.configFactory.create(stream, null)) .orElse(ConfigBuilder.create()); final KeyDataBuilder keyDataBuilder = Optional.ofNullable(tomlfile) .map(fileDelegate::newInputStream) .map(configFactory::createKeyDataBuilder) .orElse(KeyDataBuilder.create()); ConfigBuilder adjustedConfig = applyOverrides(configBuilder, keyDataBuilder); Config config = adjustedConfig.build(); return writeToOutputFile(config, outputPath); }
LegacyCliAdapter implements CliAdapter, Callable<CliResult> { @Override public CliResult execute(String... args) throws Exception { final ConfigBuilder configBuilder = Optional.ofNullable(tomlfile) .map(fileDelegate::newInputStream) .map(stream -> this.configFactory.create(stream, null)) .orElse(ConfigBuilder.create()); final KeyDataBuilder keyDataBuilder = Optional.ofNullable(tomlfile) .map(fileDelegate::newInputStream) .map(configFactory::createKeyDataBuilder) .orElse(KeyDataBuilder.create()); ConfigBuilder adjustedConfig = applyOverrides(configBuilder, keyDataBuilder); Config config = adjustedConfig.build(); return writeToOutputFile(config, outputPath); } }
LegacyCliAdapter implements CliAdapter, Callable<CliResult> { @Override public CliResult execute(String... args) throws Exception { final ConfigBuilder configBuilder = Optional.ofNullable(tomlfile) .map(fileDelegate::newInputStream) .map(stream -> this.configFactory.create(stream, null)) .orElse(ConfigBuilder.create()); final KeyDataBuilder keyDataBuilder = Optional.ofNullable(tomlfile) .map(fileDelegate::newInputStream) .map(configFactory::createKeyDataBuilder) .orElse(KeyDataBuilder.create()); ConfigBuilder adjustedConfig = applyOverrides(configBuilder, keyDataBuilder); Config config = adjustedConfig.build(); return writeToOutputFile(config, outputPath); } LegacyCliAdapter(); }
LegacyCliAdapter implements CliAdapter, Callable<CliResult> { @Override public CliResult execute(String... args) throws Exception { final ConfigBuilder configBuilder = Optional.ofNullable(tomlfile) .map(fileDelegate::newInputStream) .map(stream -> this.configFactory.create(stream, null)) .orElse(ConfigBuilder.create()); final KeyDataBuilder keyDataBuilder = Optional.ofNullable(tomlfile) .map(fileDelegate::newInputStream) .map(configFactory::createKeyDataBuilder) .orElse(KeyDataBuilder.create()); ConfigBuilder adjustedConfig = applyOverrides(configBuilder, keyDataBuilder); Config config = adjustedConfig.build(); return writeToOutputFile(config, outputPath); } LegacyCliAdapter(); @Override CliType getType(); @Override CliResult call(); @Override CliResult execute(String... args); void setOverrides(final LegacyOverridesMixin overrides); }
LegacyCliAdapter implements CliAdapter, Callable<CliResult> { @Override public CliResult execute(String... args) throws Exception { final ConfigBuilder configBuilder = Optional.ofNullable(tomlfile) .map(fileDelegate::newInputStream) .map(stream -> this.configFactory.create(stream, null)) .orElse(ConfigBuilder.create()); final KeyDataBuilder keyDataBuilder = Optional.ofNullable(tomlfile) .map(fileDelegate::newInputStream) .map(configFactory::createKeyDataBuilder) .orElse(KeyDataBuilder.create()); ConfigBuilder adjustedConfig = applyOverrides(configBuilder, keyDataBuilder); Config config = adjustedConfig.build(); return writeToOutputFile(config, outputPath); } LegacyCliAdapter(); @Override CliType getType(); @Override CliResult call(); @Override CliResult execute(String... args); void setOverrides(final LegacyOverridesMixin overrides);  }