diff --git a/nifi-toolkit/nifi-toolkit-tls/src/main/java/org/apache/nifi/toolkit/tls/manager/writer/NifiPropertiesTlsClientConfigWriter.java b/nifi-toolkit/nifi-toolkit-tls/src/main/java/org/apache/nifi/toolkit/tls/manager/writer/NifiPropertiesTlsClientConfigWriter.java index 5ee08f5b9a..e1b03da246 100644 --- a/nifi-toolkit/nifi-toolkit-tls/src/main/java/org/apache/nifi/toolkit/tls/manager/writer/NifiPropertiesTlsClientConfigWriter.java +++ b/nifi-toolkit/nifi-toolkit-tls/src/main/java/org/apache/nifi/toolkit/tls/manager/writer/NifiPropertiesTlsClientConfigWriter.java @@ -35,9 +35,9 @@ public class NifiPropertiesTlsClientConfigWriter implements ConfigurationWriter< private final OutputStreamFactory outputStreamFactory; private final File file; private final String hostname; - private final String httpsPort; + private final int httpsPort; - public NifiPropertiesTlsClientConfigWriter(NiFiPropertiesWriterFactory niFiPropertiesWriterFactory, OutputStreamFactory outputStreamFactory, File file, String hostname, String httpsPort) { + public NifiPropertiesTlsClientConfigWriter(NiFiPropertiesWriterFactory niFiPropertiesWriterFactory, OutputStreamFactory outputStreamFactory, File file, String hostname, int httpsPort) { this.niFiPropertiesWriterFactory = niFiPropertiesWriterFactory; this.outputStreamFactory = outputStreamFactory; this.file = file; @@ -63,14 +63,12 @@ public class NifiPropertiesTlsClientConfigWriter implements ConfigurationWriter< niFiPropertiesWriter.setPropertyValue(NiFiProperties.SECURITY_TRUSTSTORE, parentPath.relativize(Paths.get(tlsClientConfig.getTrustStore())).toString()); niFiPropertiesWriter.setPropertyValue(NiFiProperties.SECURITY_TRUSTSTORE_TYPE, tlsClientConfig.getTrustStoreType()); niFiPropertiesWriter.setPropertyValue(NiFiProperties.SECURITY_TRUSTSTORE_PASSWD, tlsClientConfig.getTrustStorePassword()); - if (!StringUtils.isEmpty(httpsPort)) { - if (!StringUtils.isEmpty(hostname)) { - niFiPropertiesWriter.setPropertyValue(NiFiProperties.WEB_HTTPS_HOST, hostname); - } - niFiPropertiesWriter.setPropertyValue(NiFiProperties.WEB_HTTPS_PORT, httpsPort); - niFiPropertiesWriter.setPropertyValue(NiFiProperties.WEB_HTTP_HOST, ""); - niFiPropertiesWriter.setPropertyValue(NiFiProperties.WEB_HTTP_PORT, ""); - niFiPropertiesWriter.setPropertyValue(NiFiProperties.SITE_TO_SITE_SECURE, "true"); + if (!StringUtils.isEmpty(hostname)) { + niFiPropertiesWriter.setPropertyValue(NiFiProperties.WEB_HTTPS_HOST, hostname); } + niFiPropertiesWriter.setPropertyValue(NiFiProperties.WEB_HTTPS_PORT, Integer.toString(httpsPort)); + niFiPropertiesWriter.setPropertyValue(NiFiProperties.WEB_HTTP_HOST, ""); + niFiPropertiesWriter.setPropertyValue(NiFiProperties.WEB_HTTP_PORT, ""); + niFiPropertiesWriter.setPropertyValue(NiFiProperties.SITE_TO_SITE_SECURE, "true"); } } diff --git a/nifi-toolkit/nifi-toolkit-tls/src/main/java/org/apache/nifi/toolkit/tls/standalone/TlsToolkitStandalone.java b/nifi-toolkit/nifi-toolkit-tls/src/main/java/org/apache/nifi/toolkit/tls/standalone/TlsToolkitStandalone.java index cef1bc3962..0136e64a52 100644 --- a/nifi-toolkit/nifi-toolkit-tls/src/main/java/org/apache/nifi/toolkit/tls/standalone/TlsToolkitStandalone.java +++ b/nifi-toolkit/nifi-toolkit-tls/src/main/java/org/apache/nifi/toolkit/tls/standalone/TlsToolkitStandalone.java @@ -58,7 +58,7 @@ public class TlsToolkitStandalone { } public void createNifiKeystoresAndTrustStores(File baseDir, TlsConfig tlsConfig, NiFiPropertiesWriterFactory niFiPropertiesWriterFactory, List hostnames, List keyStorePasswords, - List keyPasswords, List trustStorePasswords, String httpsPort) throws GeneralSecurityException, IOException { + List keyPasswords, List trustStorePasswords, int httpsPort) throws GeneralSecurityException, IOException { String signingAlgorithm = tlsConfig.getSigningAlgorithm(); int days = tlsConfig.getDays(); String keyPairAlgorithm = tlsConfig.getKeyPairAlgorithm(); @@ -127,10 +127,13 @@ public class TlsToolkitStandalone { tlsClientManager.addClientConfigurationWriter(new NifiPropertiesTlsClientConfigWriter(niFiPropertiesWriterFactory, outputStreamFactory, new File(hostDir, "nifi.properties"), hostname, httpsPort)); tlsClientManager.write(outputStreamFactory); + if (logger.isInfoEnabled()) { + logger.info("Successfully generated TLS configuration for " + hostname + ":" + httpsPort + " in " + hostDir); + } } if (logger.isInfoEnabled()) { - logger.info("Successfully generated TLS configuration"); + logger.info("Successfully generated TLS configuration for all hosts"); } } } diff --git a/nifi-toolkit/nifi-toolkit-tls/src/main/java/org/apache/nifi/toolkit/tls/standalone/TlsToolkitStandaloneCommandLine.java b/nifi-toolkit/nifi-toolkit-tls/src/main/java/org/apache/nifi/toolkit/tls/standalone/TlsToolkitStandaloneCommandLine.java index 7faabde31f..697148fcf8 100644 --- a/nifi-toolkit/nifi-toolkit-tls/src/main/java/org/apache/nifi/toolkit/tls/standalone/TlsToolkitStandaloneCommandLine.java +++ b/nifi-toolkit/nifi-toolkit-tls/src/main/java/org/apache/nifi/toolkit/tls/standalone/TlsToolkitStandaloneCommandLine.java @@ -26,10 +26,13 @@ import org.apache.nifi.toolkit.tls.properties.NiFiPropertiesWriterFactory; import org.apache.nifi.toolkit.tls.util.PasswordUtil; import org.apache.nifi.toolkit.tls.util.TlsHelper; import org.apache.nifi.util.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.File; import java.io.FileInputStream; import java.io.IOException; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -46,14 +49,17 @@ public class TlsToolkitStandaloneCommandLine extends BaseCommandLine { public static final String HOSTNAMES_ARG = "hostnames"; public static final String HTTPS_PORT_ARG = "httpsPort"; - public static final String DEFAULT_OUTPUT_DIRECTORY = new File(".").getPath(); + public static final String DEFAULT_OUTPUT_DIRECTORY = "../" + Paths.get(".").toAbsolutePath().normalize().getFileName().toString(); + public static final int DEFAULT_HTTPS_PORT = 10443; public static final String DESCRIPTION = "Creates certificates and config files for nifi cluster."; + private final Logger logger = LoggerFactory.getLogger(TlsToolkitStandaloneCommandLine.class); + private final PasswordUtil passwordUtil; private File baseDir; private List hostnames; - private String httpsPort; + private int httpsPort; private NiFiPropertiesWriterFactory niFiPropertiesWriterFactory; private List keyStorePasswords; private List keyPasswords; @@ -68,8 +74,8 @@ public class TlsToolkitStandaloneCommandLine extends BaseCommandLine { this.passwordUtil = passwordUtil; addOptionWithArg("o", OUTPUT_DIRECTORY_ARG, "The directory to output keystores, truststore, config files.", DEFAULT_OUTPUT_DIRECTORY); addOptionWithArg("n", HOSTNAMES_ARG, "Comma separated list of hostnames.", TlsConfig.DEFAULT_HOSTNAME); - addOptionWithArg("p", HTTPS_PORT_ARG, "Https port to use.", ""); - addOptionWithArg("f", NIFI_PROPERTIES_FILE_ARG, "Base nifi.properties file to update.", ""); + addOptionWithArg("p", HTTPS_PORT_ARG, "Https port to use.", DEFAULT_HTTPS_PORT); + addOptionWithArg("f", NIFI_PROPERTIES_FILE_ARG, "Base nifi.properties file to update. (Embedded file identical to the one in a default NiFi install will be used if not specified.)"); addOptionWithArg("S", KEY_STORE_PASSWORD_ARG, "Keystore password to use. Must either be one value or one for each host. (autogenerate if not specified)"); addOptionWithArg("K", KEY_PASSWORD_ARG, "Key password to use. Must either be one value or one for each host. (autogenerate if not specified)"); addOptionWithArg("P", TRUST_STORE_PASSWORD_ARG, "Keystore password to use. Must either be one value or one for each host. (autogenerate if not specified)"); @@ -100,7 +106,7 @@ public class TlsToolkitStandaloneCommandLine extends BaseCommandLine { String outputDirectory = commandLine.getOptionValue(OUTPUT_DIRECTORY_ARG, DEFAULT_OUTPUT_DIRECTORY); baseDir = new File(outputDirectory); hostnames = Arrays.stream(commandLine.getOptionValue(HOSTNAMES_ARG, TlsConfig.DEFAULT_HOSTNAME).split(",")).map(String::trim).collect(Collectors.toList()); - httpsPort = commandLine.getOptionValue(HTTPS_PORT_ARG, ""); + httpsPort = getIntValue(commandLine, HTTPS_PORT_ARG, DEFAULT_HTTPS_PORT); int numHosts = hostnames.size(); keyStorePasswords = Collections.unmodifiableList(getPasswords(KEY_STORE_PASSWORD_ARG, commandLine, numHosts)); @@ -110,8 +116,10 @@ public class TlsToolkitStandaloneCommandLine extends BaseCommandLine { String nifiPropertiesFile = commandLine.getOptionValue(NIFI_PROPERTIES_FILE_ARG, ""); try { if (StringUtils.isEmpty(nifiPropertiesFile)) { + logger.info("No " + NIFI_PROPERTIES_FILE_ARG + " specified, using embedded one."); niFiPropertiesWriterFactory = new NiFiPropertiesWriterFactory(); } else { + logger.info("Using " + nifiPropertiesFile + " as template."); niFiPropertiesWriterFactory = new NiFiPropertiesWriterFactory(new FileInputStream(nifiPropertiesFile)); } } catch (IOException e) { @@ -148,7 +156,7 @@ public class TlsToolkitStandaloneCommandLine extends BaseCommandLine { return hostnames; } - public String getHttpsPort() { + public int getHttpsPort() { return httpsPort; } diff --git a/nifi-toolkit/nifi-toolkit-tls/src/test/java/org/apache/nifi/toolkit/tls/standalone/TlsToolkitStandaloneCommandLineTest.java b/nifi-toolkit/nifi-toolkit-tls/src/test/java/org/apache/nifi/toolkit/tls/standalone/TlsToolkitStandaloneCommandLineTest.java index 2152d45929..ed0da06788 100644 --- a/nifi-toolkit/nifi-toolkit-tls/src/test/java/org/apache/nifi/toolkit/tls/standalone/TlsToolkitStandaloneCommandLineTest.java +++ b/nifi-toolkit/nifi-toolkit-tls/src/test/java/org/apache/nifi/toolkit/tls/standalone/TlsToolkitStandaloneCommandLineTest.java @@ -149,8 +149,8 @@ public class TlsToolkitStandaloneCommandLineTest { @Test public void testHttpsPort() throws CommandLineParseException { - String testPort = "8998"; - tlsToolkitStandaloneCommandLine.parse("-p", testPort); + int testPort = 8998; + tlsToolkitStandaloneCommandLine.parse("-p", Integer.toString(testPort)); assertEquals(testPort, tlsToolkitStandaloneCommandLine.getHttpsPort()); }