opensearch-project / sql-jdbc

This is the driver for JDBC connectivity to a cluster running with OpenSearch SQL support.
Apache License 2.0
14 stars 25 forks source link

[BUG] Unable to set a custom AWSCredentialsProvider instance #122

Open SamuelKinnettNC opened 7 months ago

SamuelKinnettNC commented 7 months ago

What is the bug? In the examples, the following code is given to illustrate using a custom AWSCredentialsProvider instance with the driver:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

String url = "jdbc:opensearch://https://remote-host-name";

Properties properties = new Properties();
properties.put("awsCredentialsProvider", new EnvironmentVariableCredentialsProvider());

Connection con = DriverManager.getConnection(url, properties);
Statement st = con.createStatement();

// use the connection

// close connection
con.close();

However, in practice this causes a null pointer exception in the setProperties function of the org.opensearch.jdbc.config.ConnectionConfig.Builder class because the getProperty method is used, which returns null if the property value is not a string. If a string is specified instead, a org.opensearch.jdbc.config.ConnectionPropertyException exception is thrown because it's expecting an AWSCredentialsProvider instance and not a string.

How can one reproduce the bug? Steps to reproduce the behavior:

  1. Implement the custom AWSCredentialsProvider example

What is the expected behavior? The AWSCredentialsProvider instance should be correctly passed through to the driver.

What is your host/environment?

marbhs commented 6 months ago

@joshuali925 Could you please check this bug? Should it be planned for processing soon?