-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Snow 1487602 connection toml configuration (#859)
* SNOW-1487602 - read connection configuration from toml file * SNOW-1487602- TOML file connection configuration - code review fixes
- Loading branch information
1 parent
1ed013a
commit 03d557d
Showing
7 changed files
with
198 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright (c) 2015-2024 Snowflake Computing Inc. All rights reserved. | ||
*/ | ||
|
||
const toml = require('toml'); | ||
const os = require('os'); | ||
const fs = require('fs'); | ||
const { validateOnlyUserReadWritePermission } = require('../file_transfer_agent/file_util'); | ||
|
||
function defaultIfNotSet(value, defaultValue) { | ||
if (value === null || typeof value === 'undefined' || value === '') { | ||
return defaultValue; | ||
} else { | ||
return value; | ||
} | ||
} | ||
|
||
function loadConnectionConfiguration() { | ||
const path = defaultIfNotSet(process.env.SNOWFLAKE_HOME, os.homedir() + '/.snowflake/'); | ||
const filePath = path + 'connections.toml'; | ||
validateOnlyUserReadWritePermission(filePath); | ||
const str = fs.readFileSync(filePath, { encoding: 'utf8' }); | ||
const parsingResult = toml.parse(str); | ||
const configurationName = defaultIfNotSet(process.env.SNOWFLAKE_DEFAULT_CONNECTION_NAME, 'default'); | ||
if (parsingResult[configurationName] !== undefined) { | ||
return parsingResult[configurationName]; | ||
} else { | ||
throw new Error(`Connection configuration with name ${configurationName} does not exist`); | ||
} | ||
} | ||
|
||
exports.loadConnectionConfiguration = loadConnectionConfiguration; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
[default] | ||
account = 'snowdriverswarsaw.us-west-2.aws' | ||
user = 'test_user' | ||
password = 'test_pass' | ||
warehouse = 'testw' | ||
database = 'test_db' | ||
schema = 'test_nodejs' | ||
protocol = 'https' | ||
port = '443' | ||
|
||
[aws-oauth] | ||
account = 'snowdriverswarsaw.us-west-2.aws' | ||
user = 'test_user' | ||
password = 'test_pass' | ||
warehouse = 'testw' | ||
database = 'test_db' | ||
schema = 'test_nodejs' | ||
protocol = 'https' | ||
port = '443' | ||
authenticator = 'oauth' | ||
testNot = 'problematicParameter' | ||
token = 'token_value' | ||
|
||
[aws-oauth-file] | ||
account = 'snowdriverswarsaw.us-west-2.aws' | ||
user = 'test_user' | ||
password = 'test_pass' | ||
warehouse = 'testw' | ||
database = 'test_db' | ||
schema = 'test_nodejs' | ||
protocol = 'https' | ||
port = '443' | ||
authenticator = 'oauth' | ||
testNot = 'problematicParameter' | ||
token_file_path = '/Users/test/.snowflake/token' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters