|
|
@ -2,11 +2,14 @@ import SqlClientFactory from '../../db/sql-client/lib/SqlClientFactory'; |
|
|
|
import { XKnex } from '../../db/sql-data-mapper'; |
|
|
|
import { XKnex } from '../../db/sql-data-mapper'; |
|
|
|
import { NcConfig } from '../../../interface/config'; |
|
|
|
import { NcConfig } from '../../../interface/config'; |
|
|
|
import fs from 'fs'; |
|
|
|
import fs from 'fs'; |
|
|
|
|
|
|
|
import { promisify } from 'util'; |
|
|
|
import { Knex } from 'knex'; |
|
|
|
import { Knex } from 'knex'; |
|
|
|
|
|
|
|
|
|
|
|
import NcMetaIO from '../../meta/NcMetaIO'; |
|
|
|
import NcMetaIO from '../../meta/NcMetaIO'; |
|
|
|
import { defaultConnectionConfig } from '../NcConfigFactory'; |
|
|
|
import { defaultConnectionConfig } from '../NcConfigFactory'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const readFileAsync = promisify(fs.readFile); |
|
|
|
|
|
|
|
|
|
|
|
export default class NcConnectionMgr { |
|
|
|
export default class NcConnectionMgr { |
|
|
|
private static connectionRefs: { |
|
|
|
private static connectionRefs: { |
|
|
|
[projectId: string]: { |
|
|
|
[projectId: string]: { |
|
|
@ -43,7 +46,7 @@ export default class NcConnectionMgr { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static get({ |
|
|
|
public static async get({ |
|
|
|
dbAlias = 'db', |
|
|
|
dbAlias = 'db', |
|
|
|
env = '_noco', |
|
|
|
env = '_noco', |
|
|
|
config, |
|
|
|
config, |
|
|
@ -53,7 +56,7 @@ export default class NcConnectionMgr { |
|
|
|
env: string; |
|
|
|
env: string; |
|
|
|
config: NcConfig; |
|
|
|
config: NcConfig; |
|
|
|
projectId: string; |
|
|
|
projectId: string; |
|
|
|
}): XKnex { |
|
|
|
}): Promise<XKnex> { |
|
|
|
if (this.connectionRefs?.[projectId]?.[env]?.[dbAlias]) { |
|
|
|
if (this.connectionRefs?.[projectId]?.[env]?.[dbAlias]) { |
|
|
|
return this.connectionRefs?.[projectId]?.[env]?.[dbAlias]; |
|
|
|
return this.connectionRefs?.[projectId]?.[env]?.[dbAlias]; |
|
|
|
} |
|
|
|
} |
|
|
@ -73,25 +76,25 @@ export default class NcConnectionMgr { |
|
|
|
connectionConfig.connection.ssl.caFilePath && |
|
|
|
connectionConfig.connection.ssl.caFilePath && |
|
|
|
!connectionConfig.connection.ssl.ca |
|
|
|
!connectionConfig.connection.ssl.ca |
|
|
|
) { |
|
|
|
) { |
|
|
|
connectionConfig.connection.ssl.ca = fs |
|
|
|
connectionConfig.connection.ssl.ca = await readFileAsync( |
|
|
|
.readFileSync(connectionConfig.connection.ssl.caFilePath) |
|
|
|
connectionConfig.connection.ssl.caFilePath |
|
|
|
.toString(); |
|
|
|
).toString(); |
|
|
|
} |
|
|
|
} |
|
|
|
if ( |
|
|
|
if ( |
|
|
|
connectionConfig.connection.ssl.keyFilePath && |
|
|
|
connectionConfig.connection.ssl.keyFilePath && |
|
|
|
!connectionConfig.connection.ssl.key |
|
|
|
!connectionConfig.connection.ssl.key |
|
|
|
) { |
|
|
|
) { |
|
|
|
connectionConfig.connection.ssl.key = fs |
|
|
|
connectionConfig.connection.ssl.key = await readFileAsync( |
|
|
|
.readFileSync(connectionConfig.connection.ssl.keyFilePath) |
|
|
|
connectionConfig.connection.ssl.keyFilePath |
|
|
|
.toString(); |
|
|
|
).toString(); |
|
|
|
} |
|
|
|
} |
|
|
|
if ( |
|
|
|
if ( |
|
|
|
connectionConfig.connection.ssl.certFilePath && |
|
|
|
connectionConfig.connection.ssl.certFilePath && |
|
|
|
!connectionConfig.connection.ssl.cert |
|
|
|
!connectionConfig.connection.ssl.cert |
|
|
|
) { |
|
|
|
) { |
|
|
|
connectionConfig.connection.ssl.cert = fs |
|
|
|
connectionConfig.connection.ssl.cert = await readFileAsync( |
|
|
|
.readFileSync(connectionConfig.connection.ssl.certFilePath) |
|
|
|
connectionConfig.connection.ssl.certFilePath |
|
|
|
.toString(); |
|
|
|
).toString(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|