|
|
@ -20,6 +20,7 @@ const { |
|
|
|
|
|
|
|
|
|
|
|
const driverClientMapping = { |
|
|
|
const driverClientMapping = { |
|
|
|
mysql: 'mysql2', |
|
|
|
mysql: 'mysql2', |
|
|
|
|
|
|
|
mariadb: 'mysql2', |
|
|
|
postgres: 'pg', |
|
|
|
postgres: 'pg', |
|
|
|
postgresql: 'pg', |
|
|
|
postgresql: 'pg', |
|
|
|
sqlite: 'sqlite3', |
|
|
|
sqlite: 'sqlite3', |
|
|
@ -59,23 +60,23 @@ const knownQueryParams = [ |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
parameter: 'keyFilePath', |
|
|
|
parameter: 'keyFilePath', |
|
|
|
aliases: [] |
|
|
|
aliases: [], |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
parameter: 'certFilePath', |
|
|
|
parameter: 'certFilePath', |
|
|
|
aliases: [] |
|
|
|
aliases: [], |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
parameter: 'caFilePath', |
|
|
|
parameter: 'caFilePath', |
|
|
|
aliases: [] |
|
|
|
aliases: [], |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
parameter: 'ssl', |
|
|
|
parameter: 'ssl', |
|
|
|
aliases: [] |
|
|
|
aliases: [], |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
parameter: 'options', |
|
|
|
parameter: 'options', |
|
|
|
aliases: ['opt', 'opts'] |
|
|
|
aliases: ['opt', 'opts'], |
|
|
|
}, |
|
|
|
}, |
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
@ -195,9 +196,11 @@ export default class NcConfigFactory implements NcConfig { |
|
|
|
}, |
|
|
|
}, |
|
|
|
} as any; |
|
|
|
} as any; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
const parsedQuery = {} |
|
|
|
const parsedQuery = {}; |
|
|
|
for (const [key, value] of url.searchParams.entries()) { |
|
|
|
for (const [key, value] of url.searchParams.entries()) { |
|
|
|
const fnd = knownQueryParams.find((param) => param.parameter === key || param.aliases.includes(key)) |
|
|
|
const fnd = knownQueryParams.find( |
|
|
|
|
|
|
|
(param) => param.parameter === key || param.aliases.includes(key) |
|
|
|
|
|
|
|
); |
|
|
|
if (fnd) { |
|
|
|
if (fnd) { |
|
|
|
parsedQuery[fnd.parameter] = value; |
|
|
|
parsedQuery[fnd.parameter] = value; |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -209,7 +212,8 @@ export default class NcConfigFactory implements NcConfig { |
|
|
|
client: url.protocol.replace(':', ''), |
|
|
|
client: url.protocol.replace(':', ''), |
|
|
|
connection: { |
|
|
|
connection: { |
|
|
|
...defaultConnectionConfig, |
|
|
|
...defaultConnectionConfig, |
|
|
|
...parsedQuery |
|
|
|
...parsedQuery, |
|
|
|
|
|
|
|
host: url.hostname, |
|
|
|
}, |
|
|
|
}, |
|
|
|
// pool: {
|
|
|
|
// pool: {
|
|
|
|
// min: 1,
|
|
|
|
// min: 1,
|
|
|
@ -303,9 +307,11 @@ export default class NcConfigFactory implements NcConfig { |
|
|
|
: {}), |
|
|
|
: {}), |
|
|
|
}; |
|
|
|
}; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
const parsedQuery = {} |
|
|
|
const parsedQuery = {}; |
|
|
|
for (const [key, value] of url.searchParams.entries()) { |
|
|
|
for (const [key, value] of url.searchParams.entries()) { |
|
|
|
const fnd = knownQueryParams.find((param) => param.parameter === key || param.aliases.includes(key)) |
|
|
|
const fnd = knownQueryParams.find( |
|
|
|
|
|
|
|
(param) => param.parameter === key || param.aliases.includes(key) |
|
|
|
|
|
|
|
); |
|
|
|
if (fnd) { |
|
|
|
if (fnd) { |
|
|
|
parsedQuery[fnd.parameter] = value; |
|
|
|
parsedQuery[fnd.parameter] = value; |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -317,7 +323,8 @@ export default class NcConfigFactory implements NcConfig { |
|
|
|
client: url.protocol.replace(':', ''), |
|
|
|
client: url.protocol.replace(':', ''), |
|
|
|
connection: { |
|
|
|
connection: { |
|
|
|
...defaultConnectionConfig, |
|
|
|
...defaultConnectionConfig, |
|
|
|
...parsedQuery |
|
|
|
...parsedQuery, |
|
|
|
|
|
|
|
host: url.hostname, |
|
|
|
}, |
|
|
|
}, |
|
|
|
acquireConnectionTimeout: 600000, |
|
|
|
acquireConnectionTimeout: 600000, |
|
|
|
...(url.searchParams.has('search_path') |
|
|
|
...(url.searchParams.has('search_path') |
|
|
@ -636,7 +643,7 @@ export default class NcConfigFactory implements NcConfig { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static extractXcUrlFromJdbc(url: string, rtConfig: boolean = false) { |
|
|
|
public static extractXcUrlFromJdbc(url: string, rtConfig = false) { |
|
|
|
// drop the jdbc prefix
|
|
|
|
// drop the jdbc prefix
|
|
|
|
if (url.startsWith('jdbc:')) { |
|
|
|
if (url.startsWith('jdbc:')) { |
|
|
|
url = url.substring(5); |
|
|
|
url = url.substring(5); |
|
|
@ -644,9 +651,19 @@ export default class NcConfigFactory implements NcConfig { |
|
|
|
|
|
|
|
|
|
|
|
const config = parseDbUrl(url); |
|
|
|
const config = parseDbUrl(url); |
|
|
|
|
|
|
|
|
|
|
|
const parsedConfig: { driver?: string, host?: string, port?: string, database?: string, user?:string, password?: string, ssl?: string } = {} |
|
|
|
const parsedConfig: { |
|
|
|
|
|
|
|
driver?: string; |
|
|
|
|
|
|
|
host?: string; |
|
|
|
|
|
|
|
port?: string; |
|
|
|
|
|
|
|
database?: string; |
|
|
|
|
|
|
|
user?: string; |
|
|
|
|
|
|
|
password?: string; |
|
|
|
|
|
|
|
ssl?: string; |
|
|
|
|
|
|
|
} = {}; |
|
|
|
for (const [key, value] of Object.entries(config)) { |
|
|
|
for (const [key, value] of Object.entries(config)) { |
|
|
|
const fnd = knownQueryParams.find((param) => param.parameter === key || param.aliases.includes(key)) |
|
|
|
const fnd = knownQueryParams.find( |
|
|
|
|
|
|
|
(param) => param.parameter === key || param.aliases.includes(key) |
|
|
|
|
|
|
|
); |
|
|
|
if (fnd) { |
|
|
|
if (fnd) { |
|
|
|
parsedConfig[fnd.parameter] = value; |
|
|
|
parsedConfig[fnd.parameter] = value; |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -654,28 +671,42 @@ export default class NcConfigFactory implements NcConfig { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!parsedConfig?.port) parsedConfig.port = defaultClientPortMapping[driverClientMapping[parsedConfig.driver] || parsedConfig.driver]; |
|
|
|
if (!parsedConfig?.port) |
|
|
|
|
|
|
|
parsedConfig.port = |
|
|
|
|
|
|
|
defaultClientPortMapping[ |
|
|
|
|
|
|
|
driverClientMapping[parsedConfig.driver] || parsedConfig.driver |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
if (rtConfig) { |
|
|
|
if (rtConfig) { |
|
|
|
const { driver, ...connectionConfig } = parsedConfig; |
|
|
|
const { driver, ...connectionConfig } = parsedConfig; |
|
|
|
|
|
|
|
|
|
|
|
const client = driverClientMapping[driver] || driver; |
|
|
|
const client = driverClientMapping[driver] || driver; |
|
|
|
|
|
|
|
|
|
|
|
const avoidSSL = ['localhost', '127.0.0.1', 'host.docker.internal', '172.17. 0.1'] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (client === 'pg' && !connectionConfig?.ssl && !avoidSSL.includes(connectionConfig.host)) { |
|
|
|
const avoidSSL = [ |
|
|
|
|
|
|
|
'localhost', |
|
|
|
|
|
|
|
'127.0.0.1', |
|
|
|
|
|
|
|
'host.docker.internal', |
|
|
|
|
|
|
|
'172.17.0.1', |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( |
|
|
|
|
|
|
|
client === 'pg' && |
|
|
|
|
|
|
|
!connectionConfig?.ssl && |
|
|
|
|
|
|
|
!avoidSSL.includes(connectionConfig.host) |
|
|
|
|
|
|
|
) { |
|
|
|
connectionConfig.ssl = 'true'; |
|
|
|
connectionConfig.ssl = 'true'; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
return { |
|
|
|
client: client, |
|
|
|
client: client, |
|
|
|
connection: { |
|
|
|
connection: { |
|
|
|
...connectionConfig |
|
|
|
...connectionConfig, |
|
|
|
} |
|
|
|
}, |
|
|
|
} as any; |
|
|
|
} as any; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const { driver, host, port, database, user, password, ...extra } = parsedConfig; |
|
|
|
const { driver, host, port, database, user, password, ...extra } = |
|
|
|
|
|
|
|
parsedConfig; |
|
|
|
|
|
|
|
|
|
|
|
const extraParams = []; |
|
|
|
const extraParams = []; |
|
|
|
|
|
|
|
|
|
|
@ -683,7 +714,11 @@ export default class NcConfigFactory implements NcConfig { |
|
|
|
extraParams.push(`${key}=${value}`); |
|
|
|
extraParams.push(`${key}=${value}`); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const res = `${driverClientMapping[driver] || driver}://${host}${port ? `:${port}` : ''}?${user ? `u=${user}&` : ''}${password ? `p=${password}&` : ''}${database ? `d=${database}&` : ''}${extraParams.join('&')}`; |
|
|
|
const res = `${driverClientMapping[driver] || driver}://${host}${ |
|
|
|
|
|
|
|
port ? `:${port}` : '' |
|
|
|
|
|
|
|
}?${user ? `u=${user}&` : ''}${password ? `p=${password}&` : ''}${ |
|
|
|
|
|
|
|
database ? `d=${database}&` : '' |
|
|
|
|
|
|
|
}${extraParams.join('&')}`;
|
|
|
|
|
|
|
|
|
|
|
|
return res; |
|
|
|
return res; |
|
|
|
} |
|
|
|
} |
|
|
|