55import java .sql .Types ;
66import java .util .*;
77import org .embulk .config .ConfigDiff ;
8+ import org .embulk .config .ConfigException ;
89import org .embulk .config .TaskSource ;
910import org .embulk .output .jdbc .*;
1011import org .embulk .output .snowflake .SnowflakeCopyBatchInsert ;
1112import org .embulk .output .snowflake .SnowflakeOutputConnection ;
1213import org .embulk .output .snowflake .SnowflakeOutputConnector ;
1314import org .embulk .output .snowflake .StageIdentifier ;
1415import org .embulk .output .snowflake .StageIdentifierHolder ;
16+ import org .embulk .output .snowflake .PrivateKeyReader ;
1517import org .embulk .spi .Column ;
1618import org .embulk .spi .ColumnVisitor ;
1719import org .embulk .spi .OutputPlugin ;
@@ -38,6 +40,10 @@ public interface SnowflakePluginTask extends PluginTask {
3840 @ ConfigDefault ("\" \" " )
3941 public String getPassword ();
4042
43+ @ Config ("privateKey" )
44+ @ ConfigDefault ("\" \" " )
45+ String getPrivateKey ();
46+
4147 @ Config ("database" )
4248 public String getDatabase ();
4349
@@ -92,7 +98,17 @@ protected JdbcOutputConnector getConnector(PluginTask task, boolean retryableMet
9298 Properties props = new Properties ();
9399
94100 props .setProperty ("user" , t .getUser ());
95- props .setProperty ("password" , t .getPassword ());
101+ if (!t .getPassword ().isEmpty ()) {
102+ props .setProperty ("password" , t .getPassword ());
103+ } else if (!t .getPrivateKey ().isEmpty ()) {
104+ try {
105+ props .put ("privateKey" , PrivateKeyReader .get (t .getPrivateKey ()));
106+ } catch (IOException e ) {
107+ // Because the source of newConnection definition does not assume IOException, change it to ConfigException.
108+ throw new ConfigException (e );
109+ }
110+ }
111+
96112 props .setProperty ("warehouse" , t .getWarehouse ());
97113 props .setProperty ("db" , t .getDatabase ());
98114 props .setProperty ("schema" , t .getSchema ());
@@ -170,11 +186,14 @@ protected BatchInsert newBatchInsert(PluginTask task, Optional<MergeConfig> merg
170186 @ Override
171187 protected void logConnectionProperties (String url , Properties props ) {
172188 Properties maskedProps = new Properties ();
173- for (String key : props .stringPropertyNames ()) {
189+ for (Object keyObj : props .keySet ()) {
190+ String key = (String ) keyObj ;
174191 if (key .equals ("password" )) {
175192 maskedProps .setProperty (key , "***" );
176193 } else if (key .equals ("proxyPassword" )) {
177194 maskedProps .setProperty (key , "***" );
195+ } else if (key .equals ("privateKey" )) {
196+ maskedProps .setProperty (key , "***" );
178197 } else {
179198 maskedProps .setProperty (key , props .getProperty (key ));
180199 }
0 commit comments