Skip to content

Commit

Permalink
Update to first determine if serverless via URL, then default to usin…
Browse files Browse the repository at this point in the history
…g _boolean_ configuration value (which defaults to false).

Signed-off-by: currantw <taylor.curran@improving.com>
  • Loading branch information
currantw committed Nov 19, 2024
1 parent 4e55ffe commit 8e2f718
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 31 deletions.
12 changes: 6 additions & 6 deletions docs/user/configuration_options.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@

#### Advanced Options

| Option | Description | Type | Acceptable Values | Default |
|------------------------|------------------------------------------------------------------------------------------------------------------------------------------|---------|---------------------------------|-------------|
| `UseSSL` | Whether to establish the connection over SSL/TLS | boolean | `0` or `1` | `0` (false) |
| `HostnameVerification` | Whether certificate hostname verification should be performed for an SSL/TLS connection. | boolean | `0` or `1` | `1` (true) |
| `ResponseTimeout` | The maximum time to wait for responses from the `Host`, in seconds. | integer | | `10` |
| Option | Description | Type | Acceptable Values | Default |
|------------------------|--------------------------------------------------------------------------------------------------------------------------------|---------|---------------------------------|-------------|
| `UseSSL` | Whether to establish the connection over SSL/TLS | boolean | `0` or `1` | `0` (false) |
| `HostnameVerification` | Whether certificate hostname verification should be performed for an SSL/TLS connection. | boolean | `0` or `1` | `1` (true) |
| `ResponseTimeout` | The maximum time to wait for responses from the `Host`, in seconds. | integer | | `10` |
| `FetchSize` | The page size for all cursor requests. The default value (-1) uses server-defined page size. Set FetchSize to 0 for non-cursor behavior. | integer | `-1`, `0` or any positive value | `-1` |
| `ServerlessOverride` | Whether the connection is to an OpenSearch Serverless cluster. If not specified, it is determined by parsing the server URL. | boolean | `0` or `1` | |
| `ServerlessOverride` | Whether the connection is to an OpenSearch Serverless cluster. Only used if it cannot be determined by parsing the server URL. | boolean | `0` or `1` | `0` (false) |

#### Logging Options

Expand Down
6 changes: 3 additions & 3 deletions src/UnitTests/UTConn/test_conn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ const std::string invalid_port = "920";
const std::string invalid_user = "amin";
const std::string invalid_pw = "amin";
const std::string invalid_region = "bad-region";
runtime_options valid_opt_val = {{valid_host, valid_port, "1", "0", ""},
runtime_options valid_opt_val = {{valid_host, valid_port, "1", "0", false},
{"BASIC", valid_user, valid_pw, valid_region, valid_tunnel_host},
{use_ssl, false, "", "", "", ""}};
runtime_options invalid_opt_val = {
{invalid_host, invalid_port, "1", "0", ""},
{invalid_host, invalid_port, "1", "0", false},
{"BASIC", invalid_user, invalid_pw, valid_region, valid_tunnel_host},
{use_ssl, false, "", "", "", ""}};
runtime_options missing_opt_val = {{"", "", "1", "0", ""},
runtime_options missing_opt_val = {{"", "", "1", "0", false},
{"BASIC", "", invalid_pw, valid_region, valid_tunnel_host},
{use_ssl, false, "", "", "", ""}};

Expand Down
16 changes: 8 additions & 8 deletions src/sqlodbc/dlg_specific.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void makeConnectString(char *connect_string, const ConnInfo *ci, UWORD len) {
INI_AUTH_MODE "=%s;"
INI_REGION "=%s;"
INI_TUNNEL_HOST "=%s;"
INI_SERVERLESS_OVERRIDE "=%s"
INI_SERVERLESS_OVERRIDE "=%d"
INI_SSL_USE "=%d;"
INI_SSL_HOST_VERIFY "=%d;"
INI_LOG_LEVEL "=%d;"
Expand All @@ -67,7 +67,7 @@ void makeConnectString(char *connect_string, const ConnInfo *ci, UWORD len) {
ci->authtype,
ci->region,
ci->tunnel_host,
ci->is_aoss_serverless,
(int)ci->is_aoss_serverless,
(int)ci->use_ssl,
(int)ci->verify_server,
(int)ci->drivers.loglevel,
Expand Down Expand Up @@ -136,7 +136,7 @@ BOOL copyConnAttributes(ConnInfo *ci, const char *attribute,
else if (stricmp(attribute, INI_TUNNEL_HOST) == 0)
STRCPY_FIXED(ci->tunnel_host, value);
else if (stricmp(attribute, INI_SERVERLESS_OVERRIDE) == 0)
STRCPY_FIXED(ci->is_aoss_serverless, value);
ci->is_aoss_serverless = (char)atoi(value);
else if (stricmp(attribute, INI_SSL_USE) == 0)
ci->use_ssl = (char)atoi(value);
else if (stricmp(attribute, INI_SSL_HOST_VERIFY) == 0)
Expand Down Expand Up @@ -175,7 +175,7 @@ static void getCiDefaults(ConnInfo *ci) {
strncpy(ci->username, DEFAULT_USERNAME, MEDIUM_REGISTRY_LEN);
strncpy(ci->region, DEFAULT_REGION, MEDIUM_REGISTRY_LEN);
strncpy(ci->tunnel_host, DEFAULT_TUNNEL_HOST, MEDIUM_REGISTRY_LEN);
strncpy(ci->is_aoss_serverless, DEFAULT_IS_AOSS_SERVERLESS, SMALL_REGISTRY_LEN);
ci->is_aoss_serverless = DEFAULT_IS_AOSS_SERVERLESS;
ci->use_ssl = DEFAULT_USE_SSL;
ci->verify_server = DEFAULT_VERIFY_SERVER;
strcpy(ci->drivers.output_dir, "C:\\");
Expand Down Expand Up @@ -287,7 +287,7 @@ void getDSNinfo(ConnInfo *ci, const char *configDrvrname) {
if (SQLGetPrivateProfileString(DSN, INI_SERVERLESS_OVERRIDE, NULL_STRING, temp,
sizeof(temp), ODBC_INI)
> 0)
STRCPY_FIXED(ci->is_aoss_serverless, temp);
ci->is_aoss_serverless = (char)atoi(temp);
if (SQLGetPrivateProfileString(DSN, INI_SSL_USE, NULL_STRING, temp,
sizeof(temp), ODBC_INI)
> 0)
Expand Down Expand Up @@ -343,7 +343,7 @@ void writeDSNinfo(const ConnInfo *ci) {
SQLWritePrivateProfileString(DSN, INI_AUTH_MODE, ci->authtype, ODBC_INI);
SQLWritePrivateProfileString(DSN, INI_REGION, ci->region, ODBC_INI);
SQLWritePrivateProfileString(DSN, INI_TUNNEL_HOST, ci->tunnel_host, ODBC_INI);
SQLWritePrivateProfileString(DSN, INI_SERVERLESS_OVERRIDE, ci->is_aoss_serverless, ODBC_INI);
ITOA_FIXED(temp, ci->is_aoss_serverless);
ITOA_FIXED(temp, ci->use_ssl);
SQLWritePrivateProfileString(DSN, INI_SSL_USE, temp, ODBC_INI);
ITOA_FIXED(temp, ci->verify_server);
Expand Down Expand Up @@ -495,7 +495,7 @@ void CC_conninfo_init(ConnInfo *conninfo, UInt4 option) {
strncpy(conninfo->username, DEFAULT_USERNAME, MEDIUM_REGISTRY_LEN);
strncpy(conninfo->region, DEFAULT_REGION, MEDIUM_REGISTRY_LEN);
strncpy(conninfo->tunnel_host, DEFAULT_TUNNEL_HOST, MEDIUM_REGISTRY_LEN);
strncpy(conninfo->is_aoss_serverless, DEFAULT_IS_AOSS_SERVERLESS, SMALL_REGISTRY_LEN);
conninfo->is_aoss_serverless = DEFAULT_IS_AOSS_SERVERLESS;
conninfo->use_ssl = DEFAULT_USE_SSL;
conninfo->verify_server = DEFAULT_VERIFY_SERVER;

Expand Down Expand Up @@ -537,7 +537,7 @@ void CC_copy_conninfo(ConnInfo *ci, const ConnInfo *sci) {
CORR_STRCPY(authtype);
CORR_STRCPY(region);
CORR_STRCPY(tunnel_host);
CORR_STRCPY(is_aoss_serverless);
CORR_VALCPY(is_aoss_serverless);
NAME_TO_NAME(ci->password, sci->password);
CORR_VALCPY(use_ssl);
CORR_VALCPY(verify_server);
Expand Down
2 changes: 1 addition & 1 deletion src/sqlodbc/dlg_specific.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ extern "C" {
#define DEFAULT_DESC ""
#define DEFAULT_DSN ""
#define DEFAULT_VERIFY_SERVER 1
#define DEFAULT_IS_AOSS_SERVERLESS ""
#define DEFAULT_IS_AOSS_SERVERLESS 0

#define AUTHTYPE_NONE "NONE"
#define AUTHTYPE_BASIC "BASIC"
Expand Down
14 changes: 6 additions & 8 deletions src/sqlodbc/opensearch_communication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1105,13 +1105,11 @@ void OpenSearchCommunication::SetSqlEndpoint() {
*/
void OpenSearchCommunication::SetIsAossServerless() {

// If it is not specified in the DSN configuration,
// determine whether this is connected to a serverless
// cluster by parsing the server URL.
const std::string& is_aoss_serverless_config_value = m_rt_opts.conn.is_aoss_serverless;

// Try to determine whether this connects to Serverless by parsing the
// server URL, otherwise use the configuration option, which defaults
// to false if not provided.
is_aoss_serverless =
is_aoss_serverless_config_value.empty()
? (m_rt_opts.conn.server.find("aoss.amazonaws.com") != std::string::npos)
: std::stoi(is_aoss_serverless_config_value);
( m_rt_opts.conn.server.find("aoss.amazonaws.com") != std::string::npos )
? true
: m_rt_opts.conn.is_aoss_serverless;
}
6 changes: 3 additions & 3 deletions src/sqlodbc/opensearch_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ int LIBOPENSEARCH_connect(ConnectionClass *self) {
}
rt_opts.conn.port.assign(self->connInfo.port);
rt_opts.conn.timeout.assign(self->connInfo.response_timeout);
rt_opts.conn.is_aoss_serverless.assign(self->connInfo.is_aoss_serverless);
rt_opts.conn.is_aoss_serverless = (self->connInfo.is_aoss_serverless == '1');

// Authentication
rt_opts.auth.auth_type.assign(self->connInfo.authtype);
Expand All @@ -127,8 +127,8 @@ int LIBOPENSEARCH_connect(ConnectionClass *self) {
rt_opts.auth.tunnel_host.assign(self->connInfo.tunnel_host);

// Encryption
rt_opts.crypt.verify_server = (self->connInfo.verify_server == 1);
rt_opts.crypt.use_ssl = (self->connInfo.use_ssl == 1);
rt_opts.crypt.verify_server = (self->connInfo.verify_server == '1');
rt_opts.crypt.use_ssl = (self->connInfo.use_ssl == '1');

void *opensearchconn = OpenSearchConnectDBParams(rt_opts, FALSE, OPTION_COUNT);
if (opensearchconn == NULL) {
Expand Down
2 changes: 1 addition & 1 deletion src/sqlodbc/opensearch_odbc.h
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ typedef struct {
char port[SMALL_REGISTRY_LEN];
char response_timeout[SMALL_REGISTRY_LEN];
char fetch_size[SMALL_REGISTRY_LEN];
char is_aoss_serverless[SMALL_REGISTRY_LEN];
char is_aoss_serverless;

// Authentication
char authtype[MEDIUM_REGISTRY_LEN];
Expand Down
2 changes: 1 addition & 1 deletion src/sqlodbc/opensearch_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ typedef struct connection_options {
std::string port;
std::string timeout;
std::string fetch_size;
std::string is_aoss_serverless;
bool is_aoss_serverless;
} connection_options;

typedef struct runtime_options {
Expand Down

0 comments on commit 8e2f718

Please sign in to comment.