diff --git a/eda/eda_api/lib/module/datasource/datasource.controller.ts b/eda/eda_api/lib/module/datasource/datasource.controller.ts index b13673249..f92e2fb82 100644 --- a/eda/eda_api/lib/module/datasource/datasource.controller.ts +++ b/eda/eda_api/lib/module/datasource/datasource.controller.ts @@ -321,9 +321,8 @@ export class DataSourceController { try { const cn = req.qs.type !== 'bigquery' ? new ConnectionModel(req.qs.user, req.qs.host, req.qs.database, req.qs.password, req.qs.port, req.qs.type, - req.body.poolLimit, req.qs.schema, req.qs.sid, req.qs.warehouse) + req.body.poolLimit, req.qs.schema, req.qs.sid, req.qs.warehouse, req.qs.allowSSL) : new BigQueryConfig(req.qs.type, req.qs.database, req.qs.project_id); - const manager = await ManagerConnectionService.testConnection(cn); await manager.tryConnection(); return res.status(200).json({ ok: true }); @@ -357,7 +356,6 @@ export class DataSourceController { } static async GenerateDataModel(req: Request, res: Response, next: NextFunction) { - if (req.body.type === 'bigquery') { return DataSourceController.GenerateDataModelBigQuery(req, res, next); @@ -368,7 +366,6 @@ export class DataSourceController { static async GenerateDataModelBigQuery(req: Request, res: Response, next: NextFunction) { try { - const cn = new BigQueryConfig(req.body.type, req.body.database, req.body.project_id); const manager = await ManagerConnectionService.testConnection(cn); const tables = await manager.generateDataModel(req.body.optimize, req.body.filter); @@ -421,12 +418,12 @@ export class DataSourceController { static async GenerateDataModelSql(req: Request, res: Response, next: NextFunction) { try { const cn = new ConnectionModel(req.body.user, req.body.host, req.body.database, - req.body.password, req.body.port, req.body.type, req.body.schema, req.body.poolLimit, req.body.sid, req.qs.warehouse); + req.body.password, req.body.port, req.body.type, req.body.schema, req.body.poolLimit, req.body.sid, req.qs.warehouse, req.qs.allowSSL); const manager = await ManagerConnectionService.testConnection(cn); const tables = await manager.generateDataModel(req.body.optimize, req.body.filter, req.body.name); const CC = req.body.allowCache === 1 ? cache_config.DEFAULT_CACHE_CONFIG : cache_config.DEFAULT_NO_CACHE_CONFIG; - + const datasource: IDataSource = new DataSource({ ds: { connection: { @@ -440,7 +437,8 @@ export class DataSourceController { password: EnCrypterService.encrypt(req.body.password || 'no'), poolLimit: req.body.poolLimit, sid: req.body.sid, - warehouse: req.body.warehouse + warehouse: req.body.warehouse, + ssl: req.qs.ssl }, metadata: { model_name: req.body.name, diff --git a/eda/eda_api/lib/module/datasource/model/connection.model.ts b/eda/eda_api/lib/module/datasource/model/connection.model.ts index 21cf946cb..33838d463 100644 --- a/eda/eda_api/lib/module/datasource/model/connection.model.ts +++ b/eda/eda_api/lib/module/datasource/model/connection.model.ts @@ -1,4 +1,4 @@ -function Connection(user, host, database, password, port, type, schema, poolLimit, sid, warehouse) { +function Connection(user, host, database, password, port, type, schema, poolLimit, sid, warehouse, ssl?) { this.user = user; this.host = host; this.database = database; @@ -10,6 +10,7 @@ function Connection(user, host, database, password, port, type, schema, poolLimi this.poolLimit=poolLimit; this.sid = sid; this.warehouse = warehouse; + this.ssl = ssl; } export default Connection; diff --git a/eda/eda_api/lib/services/connection/db-systems/mysql-connection.ts b/eda/eda_api/lib/services/connection/db-systems/mysql-connection.ts index a83cb30a1..70241ca30 100644 --- a/eda/eda_api/lib/services/connection/db-systems/mysql-connection.ts +++ b/eda/eda_api/lib/services/connection/db-systems/mysql-connection.ts @@ -37,6 +37,10 @@ export class MysqlConnection extends AbstractConnection { keepAliveInitialDelay: 0 }; + if (this.config.ssl != '0') { + mySqlConn.ssl= { rejectUnauthorized: false }; + } + poolManager.createPool(this.config.database, mySqlConn); this.pool = poolManager.getPool(this.config.database); @@ -54,6 +58,10 @@ export class MysqlConnection extends AbstractConnection { password: this.config.password }; + if (this.config.ssl != '0') { + this.config.ssl= { rejectUnauthorized: false }; + } + return createConnection(mySqlConn); } @@ -61,6 +69,9 @@ export class MysqlConnection extends AbstractConnection { try { return new Promise((resolve, reject) => { const mySqlConn ={ "host": this.config.host, "port": this.config.port, "database": this.config.database, "user": this.config.user, "password": this.config.password }; + if (this.config.ssl != '0') { + this.config.ssl= { rejectUnauthorized: false }; + } this.client = createConnection(mySqlConn); console.log('\x1b[32m%s\x1b[0m', 'Connecting to MySQL database...\n'); this.client.connect((err:Error , connection: SqlConnection): void => { diff --git a/eda/eda_api/lib/services/connection/db-systems/pg-connection.ts b/eda/eda_api/lib/services/connection/db-systems/pg-connection.ts index e461a7262..77996b9bf 100644 --- a/eda/eda_api/lib/services/connection/db-systems/pg-connection.ts +++ b/eda/eda_api/lib/services/connection/db-systems/pg-connection.ts @@ -17,6 +17,9 @@ export class PgConnection extends AbstractConnection { private AggTypes: AggregationTypes; async getclient() { + if (this.config.ssl) { + this.config.ssl= { rejectUnauthorized: false }; + } try { const connection = new PgClient(this.config); return connection; @@ -26,6 +29,9 @@ export class PgConnection extends AbstractConnection { } async tryConnection(): Promise { + if (this.config.ssl) { + this.config.ssl= { rejectUnauthorized: false }; + } try { this.client = await this.getclient(); console.log('\x1b[32m%s\x1b[0m', 'Connecting to PostgreSQL database...\n'); @@ -38,7 +44,7 @@ export class PgConnection extends AbstractConnection { } } - async generateDataModel(optimize: number, filter: string): Promise { + async generateDataModel(optimize: number, filter: string): Promise { try { this.client = await this.getclient(); let tableNames = []; diff --git a/eda/eda_api/lib/services/connection/db-systems/slqserver-connection.ts b/eda/eda_api/lib/services/connection/db-systems/slqserver-connection.ts index 9a1a2d907..2477e305a 100644 --- a/eda/eda_api/lib/services/connection/db-systems/slqserver-connection.ts +++ b/eda/eda_api/lib/services/connection/db-systems/slqserver-connection.ts @@ -21,7 +21,7 @@ export class SQLserverConnection extends AbstractConnection { database: this.config.database, options: { enableArithAbort: true, - encrypt: false // antes estava a true. Robson reportó que en docker no funcionava bien. + encrypt: this.config.ssl=='0'?false:true } } diff --git a/eda/eda_app/src/app/module/pages/data-sources/dsconfig-wrapper.component.html b/eda/eda_app/src/app/module/pages/data-sources/dsconfig-wrapper.component.html index d56778873..5c16b0194 100644 --- a/eda/eda_app/src/app/module/pages/data-sources/dsconfig-wrapper.component.html +++ b/eda/eda_app/src/app/module/pages/data-sources/dsconfig-wrapper.component.html @@ -157,6 +157,9 @@ + +