Skip to content

Commit

Permalink
fix: apply spotless
Browse files Browse the repository at this point in the history
  • Loading branch information
kenkoooo committed Jan 31, 2024
1 parent 4f36249 commit 7721df7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/embulk/output/SnowflakeOutputPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.sql.SQLException;
import java.sql.Types;
import java.util.*;

import net.snowflake.client.jdbc.internal.org.bouncycastle.operator.OperatorCreationException;
import net.snowflake.client.jdbc.internal.org.bouncycastle.pkcs.PKCSException;
import org.embulk.config.ConfigDiff;
Expand Down Expand Up @@ -109,7 +108,8 @@ protected JdbcOutputConnector getConnector(PluginTask task, boolean retryableMet
props.setProperty("password", t.getPassword());
} else if (!t.getPrivateKey().isEmpty()) {
try {
props.put("privateKey", PrivateKeyReader.get(t.getPrivateKey(), t.getPrivateKeyPassphrase()));
props.put(
"privateKey", PrivateKeyReader.get(t.getPrivateKey(), t.getPrivateKeyPassphrase()));
} catch (IOException | OperatorCreationException | PKCSException e) {
// Since this method is not allowed to throw any checked exception,
// wrap it with ConfigException, which is unchecked.
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/org/embulk/output/snowflake/PrivateKeyReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
// ref:
// https://docs.snowflake.com/en/developer-guide/jdbc/jdbc-configure#privatekey-property-in-connection-properties
public class PrivateKeyReader {
public static PrivateKey get(String pemString, String passphrase) throws IOException, OperatorCreationException, PKCSException {
public static PrivateKey get(String pemString, String passphrase)
throws IOException, OperatorCreationException, PKCSException {
Security.addProvider(new BouncyCastleProvider());
PEMParser pemParser = new PEMParser(new StringReader(pemString));
Object pemObject = pemParser.readObject();
Expand All @@ -26,16 +27,18 @@ public static PrivateKey get(String pemString, String passphrase) throws IOExcep
PrivateKeyInfo privateKeyInfo;
if (pemObject instanceof PKCS8EncryptedPrivateKeyInfo) {
// Handle the case where the private key is encrypted.
PKCS8EncryptedPrivateKeyInfo encryptedPrivateKeyInfo = (PKCS8EncryptedPrivateKeyInfo) pemObject;
InputDecryptorProvider pkcs8Prov = new JceOpenSSLPKCS8DecryptorProviderBuilder().build(passphrase.toCharArray());
PKCS8EncryptedPrivateKeyInfo encryptedPrivateKeyInfo =
(PKCS8EncryptedPrivateKeyInfo) pemObject;
InputDecryptorProvider pkcs8Prov =
new JceOpenSSLPKCS8DecryptorProviderBuilder().build(passphrase.toCharArray());
privateKeyInfo = encryptedPrivateKeyInfo.decryptPrivateKeyInfo(pkcs8Prov);
} else if (pemObject instanceof PrivateKeyInfo) {
privateKeyInfo = (PrivateKeyInfo) pemObject;
} else {
throw new IllegalArgumentException("Provided PEM does not contain a valid Private Key");
}
JcaPEMKeyConverter converter =
new JcaPEMKeyConverter().setProvider(BouncyCastleProvider.PROVIDER_NAME);
new JcaPEMKeyConverter().setProvider(BouncyCastleProvider.PROVIDER_NAME);
return converter.getPrivateKey(privateKeyInfo);
}
}

0 comments on commit 7721df7

Please sign in to comment.