From 0e38dd65801714c659ed8a27509a5c38ccdfae03 Mon Sep 17 00:00:00 2001 From: Karen Chen Date: Tue, 2 Jul 2024 18:17:54 -0700 Subject: [PATCH] chore: fix connection string builder --- driver/connection_handler.cc | 3 +++ driver/iam_proxy.cc | 8 +++++--- integration/connection_string_builder.h | 14 +++++++------- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/driver/connection_handler.cc b/driver/connection_handler.cc index 85e92bfcc..262e6bdd9 100644 --- a/driver/connection_handler.cc +++ b/driver/connection_handler.cc @@ -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); } @@ -75,6 +76,8 @@ CONNECTION_PROXY* CONNECTION_HANDLER::connect(std::shared_ptr 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) { diff --git a/driver/iam_proxy.cc b/driver/iam_proxy.cc index b270e0ac6..92091cefa 100644 --- a/driver/iam_proxy.cc +++ b/driver/iam_proxy.cc @@ -151,7 +151,7 @@ void IAM_PROXY::clear_token_cache() { bool IAM_PROXY::invoke_func_with_generated_token(std::function 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. @@ -164,14 +164,16 @@ bool IAM_PROXY::invoke_func_with_generated_token(std::functionopt_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; diff --git a/integration/connection_string_builder.h b/integration/connection_string_builder.h index 9c94bc53d..801942a35 100644 --- a/integration/connection_string_builder.h +++ b/integration/connection_string_builder.h @@ -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); @@ -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");