29
29
const { lookup} = require ( 'dns' ) . promises ;
30
30
const errors = require ( "../../errors.js" ) ;
31
31
32
- String . prototype . format = function ( ) {
33
- var args = arguments ;
34
- return this . replace ( / { ( [ 0 - 9 ] + ) } / g, function ( match , index ) {
35
- // check if the argument is there
36
- return typeof args [ index ] == 'undefined' ? match : args [ index ] ;
37
- } ) ;
38
- } ;
39
-
40
- // String formats for creating the TNS URL.
41
- const DESCRIPTION_FORMAT = "(DESCRIPTION={0}{1}{2}{3})" ;
42
- const DESCRIPTION_FORMAT_LB = "(DESCRIPTION=(LOAD_BALANCE=ON){0}{1}{2}{3})" ;
43
- const ADDRESS_LIST_FORMAT = "(ADDRESS_LIST={0})" ;
44
- const ADDRESS_LIST_FORMAT_LB = "(ADDRESS_LIST=(LOAD_BALANCE=ON){0})" ;
45
- const ADDRESS_FORMAT = "(ADDRESS=(PROTOCOL={0})(HOST={1})(PORT={2}){3})" ;
46
- const HTTPS_PROXY_FORMAT = "(HTTPS_PROXY={0})" ;
47
- const HTTPS_PROXY_PORT_FORMAT = "(HTTPS_PROXY_PORT={0})" ;
48
- const CONNECT_DATA_FORMAT = "(CONNECT_DATA={0}{1}{2}{3}{4}{5}{6})" ;
49
- const SERVICE_NAME_FORMAT = "(SERVICE_NAME={0})" ;
50
- const SERVER_MODE_FORMAT = "(SERVER={0})" ;
51
- const INSTANCE_NAME_FORMAT = "(INSTANCE_NAME={0})" ;
52
- const SERVICE_TAG_FORMAT = "(SERVICE_TAG={0})" ;
53
- const POOL_CONNECTION_CLASS_FORMAT = "(POOL_CONNECTION_CLASS={0})" ;
54
- const POOL_PURITY_FORMAT = "(POOL_PURITY={0})" ;
55
- const CONNECTION_ID_PREFIX_FORMAT = "(CONNECTION_ID_PREFIX={0})" ;
56
- const SECURITY_FORMAT = "(SECURITY={0})" ;
57
- const SERVER_DN_MATCH_FORMAT = "(SSL_SERVER_DN_MATCH={0})" ;
58
- const SERVER_DN_FORMAT = "(SSL_SERVER_CERT_DN={0})" ;
59
- const MY_WALLET_DIR_FORMAT = "(MY_WALLET_DIRECTORY={0})" ;
60
- const ENCRYPTION_CLIENT_FORMAT = "(ENCRYPTION_CLIENT={0})" ;
61
- const ENCRYPTION_TYPES_CLIENT_FORMAT = "(ENCRYPTION_TYPES_CLIENT={0})" ;
62
- const CRYPTO_CHECKSUM_CLIENT_FORMAT = "(CRYPTO_CHECKSUM_CLIENT={0})" ;
63
- const CRYPTO_CHECKSUM_TYPES_CLIENT_FORMAT = "(CRYPTO_CHECKSUM_TYPES_CLIENT={0})" ;
64
- const KEY_VALUE_FORMAT = "({0}={1})" ;
65
-
66
-
67
32
// The host information pattern of the EZConnect URL format.
68
33
/*
69
34
Used (?=) for lookahead and \\k<hostnames> for the backreference.Lookahead
@@ -183,24 +148,23 @@ class EZConnectResolver {
183
148
}
184
149
185
150
// Try to get the proxy information from URL properties
186
- let proxyHost = this . urlProps . get ( "HTTPS_PROXY" ) ;
187
- let proxyPort = this . urlProps . get ( "HTTPS_PROXY_PORT" ) ;
188
- let addressInfo =
151
+ const proxyHost = this . urlProps . get ( "HTTPS_PROXY" ) ;
152
+ const proxyPort = this . urlProps . get ( "HTTPS_PROXY_PORT" ) ;
153
+ const addressInfo =
189
154
await this . buildAddressList ( hostInfo , protocol , proxyHost , proxyPort ) ;
190
155
191
156
let connectionIdPrefix =
192
157
this . urlProps . get ( "CONNECTION_ID_PREFIX" ) ;
193
158
// Build the available information in TNS format.
194
- if ( this . lb ) {
195
- return DESCRIPTION_FORMAT_LB . format ( this . buildDescriptionParams ( ) , addressInfo ,
196
- this . buildConnectData ( serviceName , serverMode , instanceName ,
197
- connectionIdPrefix ) , this . buildSecurityInfo ( protocol ) ) ;
198
- } else {
199
- return DESCRIPTION_FORMAT . format ( this . buildDescriptionParams ( ) , addressInfo ,
200
- this . buildConnectData ( serviceName , serverMode , instanceName ,
201
- connectionIdPrefix ) , this . buildSecurityInfo ( protocol ) ) ;
202
- }
203
-
159
+ const parts = [ ] ;
160
+ if ( this . lb )
161
+ parts . push ( "(LOAD_BALANCE=ON)" ) ;
162
+ parts . push ( this . buildDescriptionParams ( ) ) ;
163
+ parts . push ( addressInfo ) ;
164
+ parts . push ( this . buildConnectData ( serviceName , serverMode , instanceName ,
165
+ connectionIdPrefix ) ) ;
166
+ parts . push ( this . buildSecurityInfo ( protocol ) ) ;
167
+ return `(DESCRIPTION=${ parts . join ( '' ) } )` ;
204
168
}
205
169
206
170
/**
@@ -211,23 +175,31 @@ class EZConnectResolver {
211
175
* @param connectionIdPrefix prefix which will be appended to the connection id [optional].
212
176
* @return CONNECT_DATA as string
213
177
*/
214
- buildConnectData ( serviceName ,
215
- serverMode ,
216
- instanceName ,
217
- connectionIdPrefix ) {
218
-
219
- let poolConnectionClass = this . urlProps . get ( "POOL_CONNECTION_CLASS" ) ;
220
- let poolPurity = this . urlProps . get ( "POOL_PURITY" ) ;
221
- let serviceTag = this . urlProps . get ( "SERVICE_TAG" ) ;
222
-
223
- return CONNECT_DATA_FORMAT . format ( SERVICE_NAME_FORMAT . format ( serviceName == null ? '' : serviceName ) ,
224
- serverMode == null ? '' : SERVER_MODE_FORMAT . format ( serverMode ) ,
225
- instanceName == null ? '' : INSTANCE_NAME_FORMAT . format ( instanceName ) ,
226
- poolConnectionClass == null ? '' : POOL_CONNECTION_CLASS_FORMAT . format ( poolConnectionClass ) ,
227
- poolPurity == null ? '' : POOL_PURITY_FORMAT . format ( POOL_PURITY_FORMAT ) ,
228
- serviceTag == null ? '' : SERVICE_TAG_FORMAT . format ( serviceTag ) ,
229
- connectionIdPrefix == null ? '' : CONNECTION_ID_PREFIX_FORMAT . format ( connectionIdPrefix ) ) ;
178
+ buildConnectData ( serviceName , serverMode , instanceName , connectionIdPrefix ) {
179
+ const poolConnectionClass = this . urlProps . get ( "POOL_CONNECTION_CLASS" ) ;
180
+ const poolPurity = this . urlProps . get ( "POOL_PURITY" ) ;
181
+ const serviceTag = this . urlProps . get ( "SERVICE_TAG" ) ;
182
+
183
+ const parts = [ ] ;
184
+ if ( serviceName )
185
+ parts . push ( `(SERVICE_NAME=${ serviceName } )` ) ;
186
+ else
187
+ parts . push ( '(SERVICE_NAME=)' ) ;
188
+ if ( serverMode )
189
+ parts . push ( `(SERVER=${ serverMode } )` ) ;
190
+ if ( instanceName )
191
+ parts . push ( `(INSTANCE_NAME=${ instanceName } )` ) ;
192
+ if ( poolConnectionClass )
193
+ parts . push ( `(POOL_CONNECTION_CLASS=${ poolConnectionClass } )` ) ;
194
+ if ( poolPurity )
195
+ parts . push ( `(POOL_PURITY=${ poolPurity } )` ) ;
196
+ if ( serviceTag )
197
+ parts . push ( `(SERVICE_TAG=${ serviceTag } )` ) ;
198
+ if ( connectionIdPrefix )
199
+ parts . push ( `(CONNECTION_ID_PREFIX=${ connectionIdPrefix } )` ) ;
200
+ return `(CONNECT_DATA=${ parts . join ( "" ) } )` ;
230
201
}
202
+
231
203
/**
232
204
* Builds the address information of the DESCRIPTION node with the given
233
205
* information.
@@ -245,8 +217,7 @@ class EZConnectResolver {
245
217
let builder = new Array ( ) ;
246
218
let proxyInfo = '' ;
247
219
if ( proxyHost != null && proxyPort != null ) {
248
- // Builds the proxy information if it is available
249
- proxyInfo = HTTPS_PROXY_FORMAT . format ( proxyHost ) + HTTPS_PROXY_PORT_FORMAT . format ( proxyPort ) ;
220
+ proxyInfo = `(HTTPS_PROXY=${ proxyHost } )(HTTPS_PROXY_PORT=${ proxyPort } )` ;
250
221
}
251
222
252
223
if ( protocol == null ) protocol = 'TCP' ;
@@ -269,13 +240,14 @@ class EZConnectResolver {
269
240
}
270
241
}
271
242
naddr += addressNodeCount ;
272
- if ( addressLists . length > 1 && addressNodeCount > 1 ) {
273
- builder . push ( ADDRESS_LIST_FORMAT_LB . format ( addressListBuilder . join ( '' ) ) ) ;
274
- } else if ( addressLists . length > 1 ) {
275
- builder . push ( ADDRESS_LIST_FORMAT . format ( addressListBuilder . join ( '' ) ) ) ;
276
- } else {
277
- builder . push ( addressListBuilder . join ( '' ) ) ;
278
- }
243
+ const parts = [ ] ;
244
+ if ( addressLists . length > 1 && addressNodeCount > 1 )
245
+ parts . push ( '(LOAD_BALANCE=ON)' ) ;
246
+ parts . push ( addressListBuilder . join ( '' ) ) ;
247
+ if ( addressLists . length > 1 )
248
+ builder . push ( `(ADDRESS_LIST=${ parts . join ( '' ) } )` ) ;
249
+ else
250
+ builder . push ( parts . join ( '' ) ) ;
279
251
}
280
252
if ( naddr == 1 ) {
281
253
shost = shost . trim ( ) ;
@@ -309,15 +281,12 @@ class EZConnectResolver {
309
281
* @param proxyInfo
310
282
* @return addressInfo
311
283
*/
312
- getAddrStr ( hostName , port ,
313
- protocol , proxyInfo ) {
284
+ getAddrStr ( hostName , port , protocol , proxyInfo ) {
314
285
let host = hostName . trim ( ) ;
315
286
// If it is IPV6 format address then remove the enclosing '[' and ']'
316
287
if ( host . startsWith ( "[" ) && host . endsWith ( "]" ) )
317
288
host = host . substring ( 1 , host . length - 1 ) ;
318
-
319
- return ADDRESS_FORMAT . format ( protocol , host , port , proxyInfo ) ;
320
-
289
+ return `(ADDRESS=(PROTOCOL=${ protocol } )(HOST=${ host } )(PORT=${ port } )${ proxyInfo } )` ;
321
290
}
322
291
/**
323
292
* Builds the parameters for the DESCRIPTION node using the parsed properties
@@ -330,7 +299,7 @@ class EZConnectResolver {
330
299
let builder = new Array ( ) ;
331
300
this . urlProps . forEach ( function ( v , k ) {
332
301
if ( DESCRIPTION_PARAMS . includes ( k ) ) // Add only if it is a DESCRIPTION node parameter
333
- builder . push ( KEY_VALUE_FORMAT . format ( k , v ) ) ;
302
+ builder . push ( `( ${ k } = ${ v } )` ) ;
334
303
} ) ;
335
304
return builder . join ( '' ) ;
336
305
}
@@ -341,41 +310,22 @@ class EZConnectResolver {
341
310
* @return security node of the description as string.
342
311
*/
343
312
buildSecurityInfo ( protocol ) {
344
- let securityInfo = new Array ( ) ;
313
+ const securityInfo = new Array ( ) ;
345
314
if ( protocol != null && protocol . toLowerCase ( ) == "tcps" ) {
346
315
// In EZConnect format if the DN match is not specified the enable it
347
316
// by default for TCPS protocol.
348
- let serverDNMatch = this . urlProps . get ( "SSL_SERVER_DN_MATCH" ) ;
349
- let serverCertDN = this . urlProps . get ( "SSL_SERVER_CERT_DN" ) ;
350
- let walletDir = this . urlProps . get ( "MY_WALLET_DIRECTORY" ) ;
351
- if ( serverDNMatch != null && ( serverDNMatch == "false" || serverDNMatch == "off" || serverDNMatch == "no" ) ) {
352
- securityInfo . push ( SERVER_DN_MATCH_FORMAT . format ( serverDNMatch ) ) ;
353
- } else {
354
- securityInfo . push ( SERVER_DN_MATCH_FORMAT . format ( 'TRUE' ) ) ;
355
- }
317
+ const serverDNMatch = this . urlProps . get ( "SSL_SERVER_DN_MATCH" ) || 'TRUE' ;
318
+ const serverCertDN = this . urlProps . get ( "SSL_SERVER_CERT_DN" ) ;
319
+ const walletDir = this . urlProps . get ( "MY_WALLET_DIRECTORY" ) ;
320
+ securityInfo . push ( `(SSL_SERVER_DN_MATCH=${ serverDNMatch } )` ) ;
356
321
if ( serverCertDN != null )
357
- securityInfo . push ( SERVER_DN_FORMAT . format ( serverCertDN ) ) ;
358
-
322
+ securityInfo . push ( `(SSL_SERVER_CERT_DN=${ serverCertDN } })` ) ;
359
323
if ( walletDir != null )
360
- securityInfo . push ( MY_WALLET_DIR_FORMAT . format ( walletDir ) ) ;
361
-
362
- } else {
363
- let encryptionClient = this . urlProps . get ( "ENCRYPTION_CLIENT" ) ;
364
- let encryptionClientTypes = this . urlProps . get ( "ENCRYPTION_TYPES_CLIENT" ) ;
365
- let checksumClient = this . urlProps . get ( "CRYPTO_CHECKSUM_CLIENT" ) ;
366
- let checksumClientTypes = this . urlProps . get ( "CRYPTO_CHECKSUM_TYPES_CLIENT" ) ;
367
- if ( encryptionClient != null )
368
- securityInfo . push ( ENCRYPTION_CLIENT_FORMAT . format ( encryptionClient ) ) ;
369
- if ( encryptionClientTypes != null )
370
- securityInfo . push ( ENCRYPTION_TYPES_CLIENT_FORMAT . format ( encryptionClientTypes ) ) ;
371
- if ( checksumClient != null )
372
- securityInfo . push ( CRYPTO_CHECKSUM_CLIENT_FORMAT . format ( checksumClient ) ) ;
373
- if ( checksumClientTypes != null )
374
- securityInfo . push ( CRYPTO_CHECKSUM_TYPES_CLIENT_FORMAT . format ( checksumClientTypes ) ) ;
375
-
324
+ securityInfo . push ( `(MY_WALLET_DIRECTORY=${ walletDir } )` ) ;
376
325
}
377
- return ( securityInfo . length == 0 ) ?
378
- '' : SECURITY_FORMAT . format ( securityInfo . join ( '' ) ) ;
326
+ if ( securityInfo . length === 0 )
327
+ return '' ;
328
+ return `(SECURITY=${ securityInfo . join ( '' ) } )` ;
379
329
}
380
330
381
331
/**
@@ -529,10 +479,6 @@ class EZConnectResolver {
529
479
aliasMap . set ( "ssl_server_cert_dn" , "SSL_SERVER_CERT_DN" ) ;
530
480
aliasMap . set ( "ssl_server_dn_match" , "SSL_SERVER_DN_MATCH" ) ;
531
481
aliasMap . set ( "wallet_location" , "MY_WALLET_DIRECTORY" ) ;
532
- aliasMap . set ( "encryption_client" , "ENCRYPTION_CLIENT" ) ;
533
- aliasMap . set ( "encryption_types_client" , "ENCRYPTION_TYPES_CLIENT" ) ;
534
- aliasMap . set ( "crypto_checksum_client" , "CRYPTO_CHECKSUM_CLIENT" ) ;
535
- aliasMap . set ( "crypto_checksum_types_client" , "CRYPTO_CHECKSUM_TYPES_CLIENT" ) ;
536
482
aliasMap . set ( "pool_connection_class" , "POOL_CONNECTION_CLASS" ) ;
537
483
aliasMap . set ( "pool_purity" , "POOL_PURITY" ) ;
538
484
aliasMap . set ( "service_tag" , "SERVICE_TAG" ) ;
0 commit comments