Skip to content

Commit

Permalink
Merge pull request #67 from trocco-io/fix-lint
Browse files Browse the repository at this point in the history
fix lint
  • Loading branch information
katamotokosuke authored Nov 21, 2023
2 parents a0b186f + 431b203 commit 3816031
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
5 changes: 3 additions & 2 deletions src/main/java/org/embulk/output/SnowflakeOutputPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
import org.embulk.config.ConfigException;
import org.embulk.config.TaskSource;
import org.embulk.output.jdbc.*;
import org.embulk.output.snowflake.PrivateKeyReader;
import org.embulk.output.snowflake.SnowflakeCopyBatchInsert;
import org.embulk.output.snowflake.SnowflakeOutputConnection;
import org.embulk.output.snowflake.SnowflakeOutputConnector;
import org.embulk.output.snowflake.StageIdentifier;
import org.embulk.output.snowflake.StageIdentifierHolder;
import org.embulk.output.snowflake.PrivateKeyReader;
import org.embulk.spi.Column;
import org.embulk.spi.ColumnVisitor;
import org.embulk.spi.OutputPlugin;
Expand Down Expand Up @@ -104,7 +104,8 @@ protected JdbcOutputConnector getConnector(PluginTask task, boolean retryableMet
try {
props.put("privateKey", PrivateKeyReader.get(t.getPrivateKey()));
} catch (IOException e) {
// Because the source of newConnection definition does not assume IOException, change it to ConfigException.
// Because the source of newConnection definition does not assume IOException, change it to
// ConfigException.
throw new ConfigException(e);
}
}
Expand Down
43 changes: 21 additions & 22 deletions src/main/java/org/embulk/output/snowflake/PrivateKeyReader.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
package org.embulk.output.snowflake;

import net.snowflake.client.jdbc.internal.org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
import net.snowflake.client.jdbc.internal.org.bouncycastle.jce.provider.BouncyCastleProvider;
import net.snowflake.client.jdbc.internal.org.bouncycastle.openssl.PEMParser;
import net.snowflake.client.jdbc.internal.org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter;

import java.io.IOException;
import java.io.StringReader;
import java.security.PrivateKey;
import java.security.Security;
import net.snowflake.client.jdbc.internal.org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
import net.snowflake.client.jdbc.internal.org.bouncycastle.jce.provider.BouncyCastleProvider;
import net.snowflake.client.jdbc.internal.org.bouncycastle.openssl.PEMParser;
import net.snowflake.client.jdbc.internal.org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter;

// 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) throws IOException {
Security.addProvider(new BouncyCastleProvider());
PEMParser pemParser = new PEMParser(new StringReader(pemString));
Object pemObject = pemParser.readObject();
pemParser.close();
// 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) throws IOException {
Security.addProvider(new BouncyCastleProvider());
PEMParser pemParser = new PEMParser(new StringReader(pemString));
Object pemObject = pemParser.readObject();
pemParser.close();

PrivateKeyInfo privateKeyInfo;
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);
return converter.getPrivateKey(privateKeyInfo);
PrivateKeyInfo privateKeyInfo;
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);
return converter.getPrivateKey(privateKeyInfo);
}
}

0 comments on commit 3816031

Please sign in to comment.