Skip to content

Commit

Permalink
chore: fix connection string builder
Browse files Browse the repository at this point in the history
  • Loading branch information
karenc-bq committed Jul 3, 2024
1 parent 920ec5a commit 0e38dd6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
3 changes: 3 additions & 0 deletions driver/connection_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ CONNECTION_HANDLER::CONNECTION_HANDLER(DBC* dbc) : dbc{dbc} {}
CONNECTION_HANDLER::~CONNECTION_HANDLER() = default;

SQLRETURN CONNECTION_HANDLER::do_connect(DBC* dbc_ptr, DataSource* ds, bool failover_enabled, bool is_monitor_connection) {
MYLOG_DBC_TRACE(dbc_ptr, "[CONNECTION HANDLER2] authmode=%s, authhost=%", ds->opt_AUTH_MODE, ds->opt_AUTH_HOST);
return dbc_ptr->connect(ds, failover_enabled, is_monitor_connection);
}

Expand All @@ -75,6 +76,8 @@ CONNECTION_PROXY* CONNECTION_HANDLER::connect(std::shared_ptr<HOST_INFO> host_in

CONNECTION_PROXY* new_connection = nullptr;
CLEAR_DBC_ERROR(dbc_clone);
MYLOG_DBC_TRACE(dbc, "[CONNECTION HANDLER] authmode=%s, authhost=%", ds_to_use->opt_AUTH_MODE, ds_to_use->opt_AUTH_HOST);

const SQLRETURN rc = do_connect(dbc_clone, ds_to_use, ds_to_use->opt_ENABLE_CLUSTER_FAILOVER, is_monitor_connection);

if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) {
Expand Down
8 changes: 5 additions & 3 deletions driver/iam_proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ void IAM_PROXY::clear_token_cache() {
bool IAM_PROXY::invoke_func_with_generated_token(std::function<bool(const char*)> func) {

// Use user provided auth host if present, otherwise, use server host
const char *AUTH_HOST = ds->opt_AUTH_HOST ? (const char *)ds->opt_AUTH_HOST
const char *auth_host = ds->opt_AUTH_HOST ? (const char *)ds->opt_AUTH_HOST
: (const char *)ds->opt_SERVER;

// Go with default region if region is not provided.
Expand All @@ -164,14 +164,16 @@ bool IAM_PROXY::invoke_func_with_generated_token(std::function<bool(const char*)
iam_port = ds->opt_PORT;
}

std::string auth_token = this->get_auth_token(AUTH_HOST, region, iam_port,
std::string auth_token = this->get_auth_token(auth_host, region, iam_port,
(const char*)ds->opt_UID, ds->opt_AUTH_EXPIRATION);

MYLOG_DBC_TRACE(dbc, "[IAM_PLUGIN] auth_host=%s", auth_host);
MYLOG_DBC_TRACE(dbc, "[IAM_PLUGIN] auth_token=%s", auth_token.c_str());
bool connect_result = func(auth_token.c_str());
if (!connect_result) {
if (using_cached_token) {
// Retry func with a fresh token
auth_token = this->get_auth_token(AUTH_HOST, region, iam_port, (const char*)ds->opt_UID,
auth_token = this->get_auth_token(auth_host, region, iam_port, (const char*)ds->opt_UID,
ds->opt_AUTH_EXPIRATION, true);
if (func(auth_token.c_str())) {
return true;
Expand Down
14 changes: 7 additions & 7 deletions integration/connection_string_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class ConnectionString {
length += sprintf(conn_in + length, "LOG_QUERY=%d;", m_log_query ? 1 : 0);
}
if (is_set_failover_mode) {
length += sprintf(conn_in + length, "failover_mode=%s;", m_failover_mode.c_str());
length += sprintf(conn_in + length, "FAILOVER_MODE=%s;", m_failover_mode.c_str());
}
if (is_set_multi_statements) {
length += sprintf(conn_in + length, "MULTI_STATEMENTS=%d;", m_multi_statements ? 1 : 0);
Expand Down Expand Up @@ -122,22 +122,22 @@ class ConnectionString {
length += sprintf(conn_in + length, "WRITETIMEOUT=%d;", m_write_timeout);
}
if (is_set_auth_mode) {
length += sprintf(conn_in + length, "AUTHENTICATION_MODE=%s;", m_auth_mode.c_str());
length += sprintf(conn_in + length, "AUTH_MODE=%s;", m_auth_mode.c_str());
}
if (is_set_auth_region) {
length += sprintf(conn_in + length, "AWS_REGION=%s;", m_auth_region.c_str());
length += sprintf(conn_in + length, "AUTH_REGION=%s;", m_auth_region.c_str());
}
if (is_set_auth_host) {
length += sprintf(conn_in + length, "IAM_HOST=%s;", m_auth_host.c_str());
length += sprintf(conn_in + length, "AUTH_HOST=%s;", m_auth_host.c_str());
}
if (is_set_auth_port) {
length += sprintf(conn_in + length, "IAM_PORT=%d;", m_auth_port);
length += sprintf(conn_in + length, "AUTH_PORT=%d;", m_auth_port);
}
if (is_set_auth_expiration) {
length += sprintf(conn_in + length, "IAM_EXPIRATION_TIME=%d;", m_auth_expiration);
length += sprintf(conn_in + length, "AUTH_EXPIRATION=%d;", m_auth_expiration);
}
if (is_set_secret_id) {
length += sprintf(conn_in + length, "SECRET_ID=%s;", m_secret_id.c_str());
length += sprintf(conn_in + length, "AUTH_SECRET_ID=%s;", m_secret_id.c_str());
}
snprintf(conn_in + length, sizeof(conn_in) - length, "\0");

Expand Down

0 comments on commit 0e38dd6

Please sign in to comment.