Github user anmolnar commented on a diff in the pull request:
https://github.com/apache/zookeeper/pull/678#discussion_r228961395
--- Diff:
zookeeper-server/src/main/java/org/apache/zookeeper/common/X509Util.java ---
@@ -360,4 +476,26 @@ private void configureSSLServerSocket(SSLServerSocket
sslServerSocket) {
LOG.debug("Using Java8-optimized cipher suites for Java version
{}", javaVersion);
return DEFAULT_CIPHERS_JAVA8;
}
+
+ /**
+ * Detects the type of KeyStore / TrustStore file from the file
extension. If the file name ends with
+ * ".jks", returns <code>StoreFileType.JKS</code>. If the file name
ends with ".pem", returns
+ * <code>StoreFileType.PEM</code>. Otherwise, throws an IOException.
+ * @param filename the filename of the key store or trust store file.
+ * @return a StoreFileType.
+ * @throws IOException if the filename does not end with ".jks" or
".pem".
+ */
+ public static StoreFileType detectStoreFileTypeFromFileExtension(File
filename) throws IOException {
--- End diff --
nit: this can be private
nit: Apache Commons IO library has `FileNameUtils.getExtensions(String
filename)` doing pretty much the same
This file type detection logic is good. Additionally, given that you're
refactoring this to Factory pattern anyway, you could also do probing with the
concrete implementations if file type cannot be detected from extension.
---