Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX 222 - Pass client application on connect #239

Closed
wants to merge 14 commits into from
Closed
7 changes: 5 additions & 2 deletions lib/authentication/authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ exports.authenticationTypes = authenticationTypes;
* @param {String} clientName
* @param {String} clientVersion
* @param {Object} clientEnv
* @param {String} clientApplication
*
* @returns {JSON}
*/
Expand All @@ -36,7 +37,8 @@ exports.formAuthJSON = function formAuthJSON(
username,
clientName,
clientVersion,
clientEnv
clientEnv,
clientApplication,
)
{
var body =
Expand All @@ -52,7 +54,8 @@ exports.formAuthJSON = function formAuthJSON(
{
OS: clientEnv.OS,
OS_VERSION: clientEnv.OS_VERSION,
OCSP_MODE: clientEnv.OCSP_MODE
OCSP_MODE: clientEnv.OCSP_MODE,
APPLICATION: clientApplication,
}
}
};
Expand Down
6 changes: 4 additions & 2 deletions lib/connection/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ function Connection(context)
connectionConfig.username,
connectionConfig.getClientName(),
connectionConfig.getClientVersion(),
connectionConfig.getClientEnvironment());
connectionConfig.getClientEnvironment(),
connectionConfig.getClientApplication());

// Update JSON body with the authentication values
auth.updateBody(body);
Expand Down Expand Up @@ -271,7 +272,8 @@ function Connection(context)
connectionConfig.username,
connectionConfig.getClientName(),
connectionConfig.getClientVersion(),
connectionConfig.getClientEnvironment());
connectionConfig.getClientEnvironment(),
connectionConfig.getClientApplication());

// Update JSON body with the authentication values
auth.updateBody(body);
Expand Down
19 changes: 19 additions & 0 deletions lib/connection/statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,13 @@ function createContextPreExec(
ErrorCodes.ERR_CONN_EXEC_STMT_INVALID_INTERNAL);
}

// if a describeOnly option is specified, make sure it's boolean
if (Util.exists(statementOptions.describeOnly))
{
Errors.checkArgumentValid(Util.isBoolean(statementOptions.describeOnly),
ErrorCodes.ERR_CONN_EXEC_STMT_INVALID_OPTIONS);
}

// create a statement context
var statementContext = createStatementContext();

Expand All @@ -423,6 +430,12 @@ function createContextPreExec(
statementContext.internal = statementOptions.internal;
}

// if the describeOnly flag is specified, add it to the statement context
if(Util.exists(statementOptions.describeOnly))
{
statementContext.describeOnly = statementOptions.describeOnly;
}

// validate non-user-specified arguments
Errors.assertInternal(Util.isObject(services));
Errors.assertInternal(Util.isObject(connectionConfig));
Expand Down Expand Up @@ -1242,6 +1255,12 @@ function sendRequestPreExec(statementContext, onResultAvailable)
json.isInternal = statementContext.internal;
}

// include statement parameters if a value was specified
if (Util.exists(statementContext.describeOnly))
{
json.describeOnly = statementContext.describeOnly;
}

// use the snowflake service to issue the request
sendSfRequest(statementContext,
{
Expand Down
2 changes: 1 addition & 1 deletion lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ function Core(options)
{
// check that the specified value is a valid tag
Errors.checkArgumentValid(LoggerCore.isValidLogTag(logTag),
ErrorCodes.ERR_GLOGAL_CONFIGURE_INVALID_LOG_LEVEL);
ErrorCodes.ERR_GLOBAL_CONFIGURE_INVALID_LOG_LEVEL);

Logger.getInstance().configure(
{
Expand Down
2 changes: 1 addition & 1 deletion lib/services/large_result_set.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function LargeResultSetService(connectionConfig, httpClient)
// Note: 403's are retried because of a bug in S3/Blob
return Util.isRetryableHttpError(
response, true // retry HTTP 403
) || err && (err.code === "ECONNRESET" || err.code === 'ETIMEDOUT');
) || err && (err.code === "ECONNRESET" || err.code === 'ETIMEDOUT' || err.name === 'ResponseTimeoutError' || err.name === 'ConnectionTimeoutError');
}

/**
Expand Down
21 changes: 7 additions & 14 deletions lib/services/sf.js
Original file line number Diff line number Diff line change
Expand Up @@ -1085,23 +1085,16 @@ StateConnecting.prototype.continue = function ()
CLIENT_APP_VERSION: this.connectionConfig.getClientVersion(),
};

// if we have some information about the client environment, add it as well
var clientEnvironment = this.connectionConfig.getClientEnvironment();
if (Util.isObject(clientEnvironment))
{
clientInfo.CLIENT_ENVIRONMENT = clientEnvironment;
}

// If we have some information about the client environment, add it as well
var clientEnvironment = this.connectionConfig.getClientEnvironment() || {};
var clientApplication = this.connectionConfig.getClientApplication();
if (Util.isString(clientApplication))
{
if (Util.isString(clientApplication)) {
clientEnvironment["APPLICATION"] = clientApplication;
}

var sessionParameters =
{
SESSION_PARAMETERS: {}
};
if (Object.keys(clientEnvironment).length > 0) {
clientInfo.CLIENT_ENVIRONMENT = clientEnvironment;
}
var sessionParameters = { SESSION_PARAMETERS: {} };

if (Util.exists(this.connectionConfig.getClientSessionKeepAlive()))
{
Expand Down