-
Notifications
You must be signed in to change notification settings - Fork 135
/
Copy pathconnection_config.js
1102 lines (960 loc) · 32.9 KB
/
connection_config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2015-2024 Snowflake Computing Inc. All rights reserved.
*/
const os = require('os');
const url = require('url');
const Util = require('../util');
const Errors = require('../errors');
const path = require('path');
const fs = require('fs');
const ErrorCodes = Errors.codes;
const NativeTypes = require('./result/data_types').NativeTypes;
const GlobalConfig = require('../global_config');
const authenticationTypes = require('../authentication/authentication').authenticationTypes;
const levenshtein = require('fastest-levenshtein');
const RowMode = require('./../constants/row_mode');
const DataTypes = require('./result/data_types');
const Logger = require('../logger');
const { validateOnlyUserReadWritePermission } = require('../file_transfer_agent/file_util');
const WAIT_FOR_BROWSER_ACTION_TIMEOUT = 120000;
const DEFAULT_PARAMS =
[
'account',
'application',
'region',
'host',
'accessUrl',
'username',
'password',
'authenticator',
'proxyHost',
'proxyPort',
'serviceName',
'privateKey',
'privateKeyPath',
'privateKeyPass',
'token',
'warehouse',
'database',
'schema',
'role',
'rowMode',
'streamResult',
'fetchAsString',
'clientSessionKeepAlive',
'clientSessionKeepAliveHeartbeatFrequency',
'jsTreatIntegerAsBigInt',
'sessionToken',
'masterToken',
'sessionTokenExpirationTime',
'masterTokenExpirationTime',
'agentClass',
'validateDefaultParameters',
'arrayBindingThreshold',
'gcsUseDownscopedCredential',
'forceStageBindError',
'includeRetryReason',
'disableQueryContextCache',
'retryTimeout',
'clientRequestMFAToken',
'clientStoreTemporaryCredential',
'disableConsoleLogin',
'forceGCPUseDownscopedCredential',
'representNullAsStringNull',
'disableSamlURLCheck',
'credentialCacheDir',
];
function consolidateHostAndAccount(options) {
let dotPos = -1;
let realAccount = undefined;
let realRegion = undefined;
if (Util.exists(options.region)) {
Errors.checkArgumentValid(Util.isCorrectSubdomain(options.region), ErrorCodes.ERR_CONN_CREATE_INVALID_REGION_REGEX);
realRegion = options.region;
}
if (Util.exists(options.account)) {
Errors.checkArgumentValid(Util.isString(options.account), ErrorCodes.ERR_CONN_CREATE_INVALID_ACCOUNT);
Errors.checkArgumentValid(Util.isCorrectSubdomain(options.account), ErrorCodes.ERR_CONN_CREATE_INVALID_ACCOUNT_REGEX);
dotPos = options.account.indexOf('.');
realAccount = options.account;
if (dotPos > 0) {
realRegion = realAccount.substring(dotPos + 1);
realAccount = realAccount.substring(0, dotPos);
}
if (!Util.exists(options.host)) {
options.host = Util.constructHostname(realRegion, realAccount);
}
}
const protocol = options.protocol || 'https';
const port = Util.exists(options.port) ? Util.format(':%s', options.port) : '';
if (!Util.isString(options.accessUrl) || !Util.exists(options.accessUrl)) {
if (options.region === 'us-west-2') {
options.region = '';
}
if (Util.exists(options.host)) {
options.accessUrl = Util.format('%s://%s%s', protocol, options.host, port);
} else if (Util.exists(options.account)) {
if (dotPos < 0 && Util.isString(options.region) && options.region.length > 0) {
options.accessUrl = Util.format('%s://%s.%s.snowflakecomputing.com%s', protocol, options.account, options.region, port);
} else {
options.accessUrl = Util.format('%s://%s.snowflakecomputing.com%s', protocol, options.account, port);
}
}
}
if (!Util.exists(options.account)) {
try {
const parsedUrl = url.parse(options.accessUrl);
Errors.checkArgumentValid(Util.exists(parsedUrl.hostname), ErrorCodes.ERR_CONN_CREATE_INVALID_ACCESS_URL);
if (!Util.exists(options.host)) {
options.host = parsedUrl.hostname;
}
const dotPos = parsedUrl.hostname.indexOf('.');
if (dotPos > 0) {
realAccount = parsedUrl.hostname.substring(0, dotPos);
}
} catch (e) {
Errors.checkArgumentValid(
false, ErrorCodes.ERR_CONN_CREATE_MISSING_ACCOUNT);
}
}
if (Util.exists(realAccount) && options.accessUrl.endsWith('global.snowflakecomputing.com')) {
const dashPos = realAccount.indexOf('-');
if (dashPos > 0) {
// global URL
realAccount = realAccount.substring(0, dashPos);
}
}
options.account = realAccount;
options.region = realRegion;
// check for missing accessURL
Errors.checkArgumentExists(Util.exists(options.accessUrl), ErrorCodes.ERR_CONN_CREATE_MISSING_ACCESS_URL);
}
/**
* A Connection configuration object that should be available to all stateful
* objects in the driver.
*
* @param {Object} options
* @param {Boolean} [validateCredentials]
* @param {Boolean} [qaMode]
* @param {Object} [clientInfo]
*
* @constructor
*/
function ConnectionConfig(options, validateCredentials, qaMode, clientInfo) {
// if no value is specified for the validate credentials flag, default to true
if (!Util.exists(validateCredentials)) {
validateCredentials = true;
}
// check for missing options
Errors.checkArgumentExists(Util.exists(options),
ErrorCodes.ERR_CONN_CREATE_MISSING_OPTIONS);
// check for invalid options
Errors.checkArgumentValid(Util.isObject(options),
ErrorCodes.ERR_CONN_CREATE_INVALID_OPTIONS);
// only validate credentials if necessary
if (validateCredentials) {
// username is not required for oauth and external browser authenticators
if (!Util.exists(options.authenticator) ||
(options.authenticator.toUpperCase() !== authenticationTypes.OAUTH_AUTHENTICATOR &&
options.authenticator.toUpperCase() !== authenticationTypes.EXTERNAL_BROWSER_AUTHENTICATOR)) {
// check for missing username
Errors.checkArgumentExists(Util.exists(options.username),
ErrorCodes.ERR_CONN_CREATE_MISSING_USERNAME);
}
if (Util.exists(options.username)) {
// check for invalid username
Errors.checkArgumentValid(Util.isString(options.username),
ErrorCodes.ERR_CONN_CREATE_INVALID_USERNAME);
}
// password is only required for default authenticator
if (!Util.exists(options.authenticator) ||
options.authenticator === authenticationTypes.DEFAULT_AUTHENTICATOR) {
// check for missing password
Errors.checkArgumentExists(Util.exists(options.password),
ErrorCodes.ERR_CONN_CREATE_MISSING_PASSWORD);
// check for invalid password
Errors.checkArgumentValid(Util.isString(options.password),
ErrorCodes.ERR_CONN_CREATE_INVALID_PASSWORD);
}
consolidateHostAndAccount(options);
}
// check for missing accessUrl
Errors.checkArgumentExists(Util.exists(options.accessUrl),
ErrorCodes.ERR_CONN_CREATE_MISSING_ACCESS_URL);
// check for invalid accessUrl
Errors.checkArgumentValid(Util.isString(options.accessUrl),
ErrorCodes.ERR_CONN_CREATE_INVALID_ACCESS_URL);
const proxyHost = options.proxyHost;
const proxyPort = options.proxyPort;
const proxyUser = options.proxyUser;
const proxyPassword = options.proxyPassword;
const proxyProtocol = options.proxyProtocol || 'http';
const noProxy = options.noProxy;
// if we're running in node and some proxy information is specified
let proxy;
if (Util.isNode() && (Util.exists(proxyHost) || Util.exists(proxyPort))) {
// check for missing proxyHost
Errors.checkArgumentExists(Util.exists(proxyHost),
ErrorCodes.ERR_CONN_CREATE_MISSING_PROXY_HOST);
// check for invalid proxyHost
Errors.checkArgumentValid(Util.isString(proxyHost),
ErrorCodes.ERR_CONN_CREATE_INVALID_PROXY_HOST);
// check for missing proxyPort
Errors.checkArgumentExists(Util.exists(proxyPort),
ErrorCodes.ERR_CONN_CREATE_MISSING_PROXY_PORT);
// check for invalid proxyPort
Errors.checkArgumentValid(Util.isNumber(proxyPort),
ErrorCodes.ERR_CONN_CREATE_INVALID_PROXY_PORT);
if (Util.exists(noProxy)) {
// check for invalid noProxy
Errors.checkArgumentValid(Util.isString(noProxy),
ErrorCodes.ERR_CONN_CREATE_INVALID_NO_PROXY);
}
if (Util.exists(proxyUser) || Util.exists(proxyPassword)) {
// check for missing proxyUser
Errors.checkArgumentExists(Util.exists(proxyUser),
ErrorCodes.ERR_CONN_CREATE_MISSING_PROXY_USER);
// check for invalid proxyUser
Errors.checkArgumentValid(Util.isString(proxyUser),
ErrorCodes.ERR_CONN_CREATE_INVALID_PROXY_USER);
// check for missing proxyPassword
Errors.checkArgumentExists(Util.exists(proxyPassword),
ErrorCodes.ERR_CONN_CREATE_MISSING_PROXY_PASS);
// check for invalid proxyPassword
Errors.checkArgumentValid(Util.isString(proxyPassword),
ErrorCodes.ERR_CONN_CREATE_INVALID_PROXY_PASS);
proxy =
{
host: proxyHost,
port: proxyPort,
user: proxyUser,
password: proxyPassword,
protocol: proxyProtocol,
noProxy: noProxy
};
} else {
proxy =
{
host: proxyHost,
port: proxyPort,
protocol: proxyProtocol,
noProxy: noProxy
};
}
}
const serviceName = options.serviceName;
let authenticator = options.authenticator;
// if no value is specified for authenticator, default to Snowflake
if (!Util.exists(authenticator)) {
authenticator = authenticationTypes.DEFAULT_AUTHENTICATOR;
} else {
authenticator = authenticator.toUpperCase();
}
let browserActionTimeout = options.browserActionTimeout;
if (Util.exists(options.browserActionTimeout)) {
Errors.checkArgumentValid(Util.number.isPositiveInteger(browserActionTimeout),
ErrorCodes.ERR_CONN_CREATE_INVALID_BROWSER_TIMEOUT);
} else {
browserActionTimeout = WAIT_FOR_BROWSER_ACTION_TIMEOUT;
}
const privateKey = options.privateKey;
if (Util.exists(options.privateKey)) {
Errors.checkArgumentValid((Util.isString(privateKey) && Util.isPrivateKey(privateKey)),
ErrorCodes.ERR_CONN_CREATE_INVALID_PRIVATE_KEY);
}
const privateKeyPath = options.privateKeyPath;
if (Util.exists(options.privateKeyPath)) {
Errors.checkArgumentValid(Util.isString(privateKeyPath),
ErrorCodes.ERR_CONN_CREATE_INVALID_PRIVATE_KEY_PATH);
}
const privateKeyPass = options.privateKeyPass;
if (Util.exists(options.privateKeyPass)) {
Errors.checkArgumentValid(Util.isString(privateKeyPass),
ErrorCodes.ERR_CONN_CREATE_INVALID_PRIVATE_KEY_PASS);
}
let token = options.token;
if (Util.exists(options.token)) {
Errors.checkArgumentValid(Util.isString(token),
ErrorCodes.ERR_CONN_CREATE_INVALID_OAUTH_TOKEN);
}
if (authenticator === authenticationTypes.OAUTH_AUTHENTICATOR && !Util.string.isNotNullOrEmpty(token)) {
const tokenFilePath = options.token_file_path ? options.token_file_path : '/snowflake/session/token';
if (Util.exists(tokenFilePath)) {
validateOnlyUserReadWritePermission(tokenFilePath);
token = fs.readFileSync(tokenFilePath, 'utf-8').trim();
Errors.checkArgumentValid(Util.isString(token),
ErrorCodes.ERR_CONN_CREATE_INVALID_OAUTH_TOKEN);
}
}
const warehouse = options.warehouse;
const database = options.database;
const schema = options.schema;
const role = options.role;
// check for invalid warehouse
if (Util.exists(warehouse)) {
Errors.checkArgumentValid(Util.isString(warehouse),
ErrorCodes.ERR_CONN_CREATE_INVALID_WAREHOUSE);
}
// check for invalid database
if (Util.exists(database)) {
Errors.checkArgumentValid(Util.isString(database),
ErrorCodes.ERR_CONN_CREATE_INVALID_DATABASE);
}
// check for invalid schema
if (Util.exists(schema)) {
Errors.checkArgumentValid(Util.isString(schema),
ErrorCodes.ERR_CONN_CREATE_INVALID_SCHEMA);
}
// check for invalid role
if (Util.exists(role)) {
Errors.checkArgumentValid(Util.isString(role),
ErrorCodes.ERR_CONN_CREATE_INVALID_ROLE);
}
// check for invalid streamResult
const streamResult = options.streamResult;
if (Util.exists(streamResult)) {
Errors.checkArgumentValid(Util.isBoolean(streamResult),
ErrorCodes.ERR_CONN_CREATE_INVALID_STREAM_RESULT);
}
// check for invalid fetchAsString
const fetchAsString = options.fetchAsString;
if (Util.exists(fetchAsString)) {
// check that the value is an array
Errors.checkArgumentValid(Util.isArray(fetchAsString),
ErrorCodes.ERR_CONN_CREATE_INVALID_FETCH_AS_STRING);
// check that all the array elements are valid
const invalidValueIndex = NativeTypes.findInvalidValue(fetchAsString);
Errors.checkArgumentValid(invalidValueIndex === -1,
ErrorCodes.ERR_CONN_CREATE_INVALID_FETCH_AS_STRING_VALUES,
JSON.stringify(fetchAsString[invalidValueIndex]));
}
// Row mode is optional, can be undefined
const rowMode = options.rowMode;
if (Util.exists(rowMode)) {
RowMode.checkRowModeValid(rowMode);
}
// check for invalid clientSessionKeepAlive
const clientSessionKeepAlive = options.clientSessionKeepAlive;
if (Util.exists(clientSessionKeepAlive)) {
Errors.checkArgumentValid(Util.isBoolean(clientSessionKeepAlive),
ErrorCodes.ERR_CONN_CREATE_INVALID_KEEP_ALIVE);
}
// check for invalid clientSessionKeepAliveHeartbeatFrequency
let clientSessionKeepAliveHeartbeatFrequency = options.clientSessionKeepAliveHeartbeatFrequency;
if (Util.exists(clientSessionKeepAliveHeartbeatFrequency)) {
Errors.checkArgumentValid(Util.isNumber(clientSessionKeepAliveHeartbeatFrequency),
ErrorCodes.ERR_CONN_CREATE_INVALID_KEEP_ALIVE_HEARTBEAT_FREQ);
clientSessionKeepAliveHeartbeatFrequency =
Util.validateClientSessionKeepAliveHeartbeatFrequency(clientSessionKeepAliveHeartbeatFrequency, 14400);
}
const jsTreatIntegerAsBigInt = options.jsTreatIntegerAsBigInt;
if (Util.exists(jsTreatIntegerAsBigInt)) {
Errors.checkArgumentValid(Util.isBoolean(jsTreatIntegerAsBigInt),
ErrorCodes.ERR_CONN_CREATE_INVALID_TREAT_INTEGER_AS_BIGINT);
}
const gcsUseDownscopedCredential = options.gcsUseDownscopedCredential;
if (Util.exists(gcsUseDownscopedCredential)) {
Errors.checkArgumentValid(Util.isBoolean(gcsUseDownscopedCredential),
ErrorCodes.ERR_CONN_CREATE_INVALID_GCS_USE_DOWNSCOPED_CREDENTIAL);
}
const clientConfigFile = options.clientConfigFile;
if (Util.exists(clientConfigFile)) {
Errors.checkArgumentValid(Util.isString(clientConfigFile), ErrorCodes.ERR_CONN_CREATE_INVALID_CLIENT_CONFIG_FILE);
}
// remember if we're in qa mode
this._qaMode = qaMode;
// if a client-info argument is specified, validate it
const clientType = 'JavaScript';
let clientName;
let clientVersion;
let clientEnvironment;
if (Util.exists(clientInfo)) {
Errors.assertInternal(Util.isObject(clientInfo));
Errors.assertInternal(Util.isString(clientInfo.version));
Errors.assertInternal(Util.isObject(clientInfo.environment));
clientName = clientInfo.name;
clientVersion = clientInfo.version;
clientEnvironment = clientInfo.environment;
clientEnvironment.OS = os.platform();
clientEnvironment.OS_VERSION = os.release();
clientEnvironment.OCSP_MODE = GlobalConfig.getOcspMode();
}
const clientApplication = options.application;
if (Util.exists(clientApplication)) {
Errors.checkArgumentValid(Util.isString(clientApplication),
ErrorCodes.ERR_CONN_CREATE_INVALID_APPLICATION);
const APPLICATION_PATTERN = new RegExp(String.raw`^[A-Za-z]([A-Za-z0-9.\-_]){1,50}$`,
'gi');
Errors.checkArgumentValid(APPLICATION_PATTERN.test(clientApplication),
ErrorCodes.ERR_CONN_CREATE_INVALID_APPLICATION);
}
let validateDefaultParameters = false;
if (Util.exists(options.validateDefaultParameters)) {
// check for invalid validateDefaultParameters
Errors.checkArgumentValid(Util.isBoolean(options.validateDefaultParameters),
ErrorCodes.ERR_CONN_CREATE_INVALID_VALIDATE_DEFAULT_PARAMETERS);
validateDefaultParameters = options.validateDefaultParameters;
}
let bindThreshold = null;
if (Util.exists(options.arrayBindingThreshold)) {
// check for invalid arrayBindingThreshold
Errors.checkArgumentValid(Util.isNumber(options.arrayBindingThreshold),
ErrorCodes.ERR_CONN_CREATE_INVALID_ARRAY_BINDING_THRESHOLD);
bindThreshold = options.arrayBindingThreshold;
}
let forceStageBindError = null;
if (Util.exists(options.forceStageBindError)) {
// check for invalid forceStageBindError
Errors.checkArgumentValid(Util.isNumber(options.forceStageBindError),
ErrorCodes.ERR_CONN_CREATE_INVALID_FORCE_STAGE_BIND_ERROR);
forceStageBindError = options.forceStageBindError;
}
let disableQueryContextCache = false;
if (Util.exists(options.disableQueryContextCache)) {
Errors.checkArgumentValid(Util.isBoolean(options.disableQueryContextCache),
ErrorCodes.ERR_CONN_CREATE_INVALID_DISABLED_QUERY_CONTEXT_CACHE);
disableQueryContextCache = options.disableQueryContextCache;
}
let retryTimeout = 300;
if (Util.exists(options.retryTimeout)) {
Errors.checkArgumentValid(Util.isNumber(options.retryTimeout),
ErrorCodes.ERR_CONN_CREATE_INVALID_MAX_RETRY_TIMEOUT);
retryTimeout = options.retryTimeout !== 0 ? Math.max(retryTimeout, options.retryTimeout) : 0;
}
if (validateDefaultParameters) {
for (const [key] of Object.entries(options)) {
if (!DEFAULT_PARAMS.includes(key)) {
const result = levenshtein.closest(key, DEFAULT_PARAMS);
Logger.getInstance().error(`'${key}' is an unknown connection parameter. Did you mean '${result}'?`);
}
}
}
let includeRetryReason = true;
if (Util.exists(options.includeRetryReason)) {
Errors.checkArgumentValid(Util.isBoolean(options.includeRetryReason),
ErrorCodes.ERR_CONN_CREATE_INVALID_INCLUDE_RETRY_REASON);
includeRetryReason = options.includeRetryReason;
}
let clientRequestMFAToken = false;
if (Util.exists(options.clientRequestMFAToken)) {
Errors.checkArgumentValid(Util.isBoolean(options.clientRequestMFAToken),
ErrorCodes.ERR_CONN_CREATE_INVALID_CLIENT_REQUEST_MFA_TOKEN);
clientRequestMFAToken = options.clientRequestMFAToken;
}
let disableConsoleLogin = true;
if (Util.exists(options.disableConsoleLogin)) {
Errors.checkArgumentValid(Util.isBoolean(options.disableConsoleLogin),
ErrorCodes.ERR_CONN_CREATE_INVALID_DISABLE_CONSOLE_LOGIN);
disableConsoleLogin = options.disableConsoleLogin;
}
if (Util.exists(options.forceGCPUseDownscopedCredential)) {
Errors.checkArgumentValid(Util.isBoolean(options.forceGCPUseDownscopedCredential),
ErrorCodes.ERR_CONN_CREATE_INVALID_FORCE_GCP_USE_DOWNSCOPED_CREDENTIAL);
process.env.SNOWFLAKE_FORCE_GCP_USE_DOWNSCOPED_CREDENTIAL = options.forceGCPUseDownscopedCredential;
} else {
process.env.SNOWFLAKE_FORCE_GCP_USE_DOWNSCOPED_CREDENTIAL = false;
}
if (Util.exists(options.representNullAsStringNull)) {
Errors.checkArgumentValid(Util.isBoolean(options.representNullAsStringNull),
ErrorCodes.ERR_CONN_CREATE_INVALID_REPRESENT_NULL_AS_STRING_NULL);
DataTypes.setIsRepresentNullAsStringNull(options.representNullAsStringNull);
}
let disableSamlURLCheck = false;
if (Util.exists(options.disableSamlURLCheck)) {
Errors.checkArgumentValid(Util.isBoolean(options.disableSamlURLCheck),
ErrorCodes.ERR_CONN_CREATE_INVALID_DISABLE_SAML_URL_CHECK);
disableSamlURLCheck = options.disableSamlURLCheck;
}
let clientStoreTemporaryCredential = false;
if (Util.exists(options.clientStoreTemporaryCredential)) {
Errors.checkArgumentValid(Util.isBoolean(options.clientStoreTemporaryCredential),
ErrorCodes.ERR_CONN_CREATE_INVALID_CLIENT_STORE_TEMPORARY_CREDENTIAL);
clientStoreTemporaryCredential = options.clientStoreTemporaryCredential;
}
let credentialCacheDir = null;
if (Util.exists(options.credentialCacheDir)) {
const absolutePath = path.resolve(options.credentialCacheDir);
Errors.checkArgumentValid(Util.validatePath(absolutePath),
ErrorCodes.ERR_CONN_CREATE_INVALID_CREDENTIAL_CACHE_DIR);
credentialCacheDir = absolutePath;
}
/**
* Returns an object that contains information about the proxy hostname, port,
* etc. for when http requests are made.
*
* @returns {Object}
*/
this.getProxy = function () {
return proxy;
};
/**
* Returns the warehouse to automatically use once a connection has been
* established.
*
* @returns {String}
*/
this.getWarehouse = function () {
return warehouse;
};
/**
* Returns the database to automatically use once a connection has been
* established.
*
* @returns {String}
*/
this.getDatabase = function () {
return database;
};
/**
* Returns the schema to automatically use once a connection has been
* established.
*
* @returns {String}
*/
this.getSchema = function () {
return schema;
};
/**
* Returns the role to automatically use once a connection has been
* established.
*
* @returns {String}
*/
this.getRole = function () {
return role;
};
/**
* Returns the service name.
*
* @returns {String}
*/
this.getServiceName = function () {
return serviceName;
};
/**
* Returns the authenticator to use for establishing a connection.
*
* @returns {String}
*/
this.getAuthenticator = function () {
return authenticator;
};
/**
* Returns the timeout in millis used for authentication by external browser.
*
* @returns {String}
*/
this.getBrowserActionTimeout = function () {
return browserActionTimeout;
};
/**
* Returns the private key string.
*
* @returns {String}
*/
this.getPrivateKey = function () {
return privateKey;
};
/**
* Returns the private key file location.
*
* @returns {String}
*/
this.getPrivateKeyPath = function () {
return privateKeyPath;
};
/**
* Returns the private key passphrase.
*
* @returns {String}
*/
this.getPrivateKeyPass = function () {
return privateKeyPass;
};
/**
* Returns the OAuth token.
*
* @returns {String}
*/
this.getToken = function () {
return token;
};
/**
* Returns the streamResult flag.
*
* @returns {boolean}
*/
this.getStreamResult = function () {
return streamResult;
};
/**
* Returns the fetchAsString array.
*
* @returns {String[]}
*/
this.getFetchAsString = function () {
return fetchAsString;
};
/**
* Returns the rowMode string value ('array', 'object' or 'object_with_renamed_duplicated_columns'). Could be null or undefined.
*
* @returns {String}
*/
this.getRowMode = function () {
return rowMode;
};
/**
* Returns the client type.
*
* @returns {String}
*/
this.getClientType = function () {
return clientType;
};
/**
* Returns the client name.
*
* @returns {String}
*/
this.getClientName = function () {
return clientName;
};
/**
* Returns the client version.
*
* @returns {String}
*/
this.getClientVersion = function () {
return clientVersion;
};
/**
* Returns the client application.
*
* @returns {String}
*/
this.getClientApplication = function () {
return clientApplication;
};
/**
* Returns a JSON object containing version information for all the various
* components of the runtime, e.g. node, v8, openssl, etc.
*
* @returns {Object}
*/
this.getClientEnvironment = function () {
return clientEnvironment;
};
/**
* Returns the client session keep alive setting.
*
* @returns {String}
*/
this.getClientSessionKeepAlive = function () {
return clientSessionKeepAlive;
};
/**
* Returns the client session keep alive heartbeat frequency setting.
*
* @returns {String}
*/
this.getClientSessionKeepAliveHeartbeatFrequency = function () {
return clientSessionKeepAliveHeartbeatFrequency;
};
/**
* Returns the client treat integer as setting
*
* @returns {String}
*/
this.getJsTreatIntegerAsBigInt = function () {
return jsTreatIntegerAsBigInt;
};
/**
* Returns the setting for the GCS_USE_DOWNSCOPED_CREDENTIAL session parameter
*
* @returns {String}
*/
this.getGcsUseDownscopedCredential = function () {
return gcsUseDownscopedCredential;
};
/**
* Returns the bind threshold
*
* @returns {string}
*/
this.getbindThreshold = function () {
return bindThreshold;
};
/**
* Returns the force stage bind error
*
* @returns {string}
*/
this.getForceStageBindError = function () {
return forceStageBindError;
};
/**
* Returns whether the Retry reason is included or not in the retry url
*
* @returns {Boolean}
*/
this.getIncludeRetryReason = function () {
return includeRetryReason;
};
/**
* Returns whether the Query Context Cache is enabled or not by the configuration
*
* @returns {Boolean}
*/
this.getDisableQueryContextCache = function () {
return disableQueryContextCache;
};
/**
* Returns the client config file
*
* @returns {String}
*/
this.getClientConfigFile = function () {
return clientConfigFile;
};
/**
* Returns the max login timeout
*
* @returns {Number}
*/
this.getRetryTimeout = function () {
return retryTimeout;
};
this.getDisableConsoleLogin = function () {
return disableConsoleLogin;
};
/**
* Returns whether the SAML URL check is enabled or not.
*
* @returns {Boolean}
*/
this.getDisableSamlURLCheck = function () {
return disableSamlURLCheck;
};
this.getCredentialCacheDir = function () {
return credentialCacheDir;
};
this.getClientRequestMFAToken = function () {
return clientRequestMFAToken;
};
/**
* Returns whether the auth token saves on the local machine or not.
*
* @returns {Boolean}
*/
this.getClientStoreTemporaryCredential = function () {
return clientStoreTemporaryCredential;
};
// save config options
this.username = options.username;
this.password = options.password;
this.accessUrl = options.accessUrl;
this.region = options.region;
this.account = options.account;
this.host = options.host;
this.sessionToken = options.sessionToken;
this.masterToken = options.masterToken;
this.masterTokenExpirationTime = options.masterTokenExpirationTime;
this.sessionTokenExpirationTime = options.sessionTokenExpirationTime;
this.clientConfigFile = options.clientConfigFile;
// create the parameters array
const parameters = createParameters();
// create a map in which the keys are the parameter names and the values are
// the corresponding parameters
const mapParameters = {};
let index, length, parameter;
for (index = 0, length = parameters.length; index < length; index++) {
parameter = parameters[index];
mapParameters[parameter.name] = parameter;
// initialize the value to the default
parameter.value = parameter.defaultValue;
}
// for each property in the options object that matches a known parameter name
let propertyName, propertyValue;
for (propertyName in options) {
if (Object.prototype.hasOwnProperty.call(options, propertyName) &&
Object.prototype.hasOwnProperty.call(mapParameters, propertyName)) {
// if the parameter matching the property is external and the specified
// value is valid for the parameter, update the parameter value
propertyValue = options[propertyName];
parameter = mapParameters[propertyName];
if (parameter.external && parameter.validate(propertyValue)) {
parameter.value = propertyValue;
}
}
}
// save the parameters map
this._mapParameters = mapParameters;
// custom agent class, test only
this.agentClass = options.agentClass;
}
/**
* Determines if qa-mode is on.
*
* @returns {Boolean}
*/
ConnectionConfig.prototype.isQaMode = function () {
return this._qaMode;
};
/**
* Clears all credential-related information.
*/
ConnectionConfig.prototype.clearCredentials = function () {
// clear the password
this.password = null;
// TODO: clear passcode and other credential-related information as well
};
const PARAM_TIMEOUT = 'timeout';
const PARAM_RESULT_PREFETCH = 'resultPrefetch';
const PARAM_RESULT_STREAM_INTERRUPTS = 'resultStreamInterrupts';
const PARAM_RESULT_CHUNK_CACHE_SIZE = 'resultChunkCacheSize';
const PARAM_RESULT_PROCESSING_BATCH_SIZE = 'resultProcessingBatchSize';
const PARAM_RESULT_PROCESSING_BATCH_DURATION = 'resultProcessingBatchDuration';
const PARAM_ROW_STREAM_HIGH_WATER_MARK = 'rowStreamHighWaterMark';
const PARAM_RETRY_LARGE_RESULT_SET_MAX_NUM_RETRIES = 'largeResultSetRetryMaxNumRetries';
const PARAM_RETRY_LARGE_RESULT_SET_MAX_SLEEP_TIME = 'largeResultSetRetryMaxSleepTime';
const PARAM_RETRY_SF_MAX_LOGIN_RETRIES = 'sfRetryMaxLoginRetries';
const PARAM_RETRY_SF_MAX_NUM_RETRIES = 'sfRetryMaxNumRetries';
const PARAM_RETRY_SF_STARTING_SLEEP_TIME = 'sfRetryStartingSleepTime';
const PARAM_RETRY_SF_MAX_SLEEP_TIME = 'sfRetryMaxSleepTime';
/**
* Creates the list of known parameters. If a parameter is marked as external,
* its value can be overridden by adding the appropriate name-value mapping to
* the ConnectionConfig options.
*
* @returns {Object[]}
*/
function createParameters() {
const isNonNegativeInteger = Util.number.isNonNegativeInteger.bind(Util.number);
const isPositiveInteger = Util.number.isPositiveInteger.bind(Util.number);
const isNonNegativeNumber = Util.number.isNonNegative.bind(Util.number);
return [
{
name: PARAM_TIMEOUT,
defaultValue: 90 * 1000,
external: true,
validate: isPositiveInteger
},
{
name: PARAM_RESULT_PREFETCH,
defaultValue: 2,
external: true,
validate: isPositiveInteger
},
{
name: PARAM_RESULT_STREAM_INTERRUPTS,
defaultValue: 3,
validate: isPositiveInteger
},
// for now we set chunk cache size to 1, which is same as
// disabling the chunk cache. Otherwise, cache will explode
// memory when fetching large result set
{
name: PARAM_RESULT_CHUNK_CACHE_SIZE,
defaultValue: 1,
validate: isPositiveInteger
},
{
name: PARAM_RESULT_PROCESSING_BATCH_SIZE,
defaultValue: 1000,
validate: isPositiveInteger
},
{
name: PARAM_RESULT_PROCESSING_BATCH_DURATION,
defaultValue: 100,
validate: isPositiveInteger
},
{
name: PARAM_ROW_STREAM_HIGH_WATER_MARK,
defaultValue: 10,