Skip to content

Commit

Permalink
Merge branch 'pg-connection.SSL-selector' of https://github.com/jorti…
Browse files Browse the repository at this point in the history
…lles/EDA

# Conflicts:
#	eda/eda_app/src/locale/messages.ca.xlf
  • Loading branch information
jortilles committed Jan 22, 2024
2 parents 16f825c + 5b5d249 commit d677810
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 11 deletions.
12 changes: 5 additions & 7 deletions eda/eda_api/lib/module/datasource/datasource.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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: {
Expand All @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion eda/eda_api/lib/module/datasource/model/connection.model.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
11 changes: 11 additions & 0 deletions eda/eda_api/lib/services/connection/db-systems/mysql-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -54,13 +58,20 @@ export class MysqlConnection extends AbstractConnection {
password: this.config.password
};

if (this.config.ssl != '0') {
this.config.ssl= { rejectUnauthorized: false };
}

return createConnection(mySqlConn);
}

async tryConnection(): Promise<any> {
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 => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,6 +29,9 @@ export class PgConnection extends AbstractConnection {
}

async tryConnection(): Promise<any> {
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');
Expand All @@ -38,7 +44,7 @@ export class PgConnection extends AbstractConnection {
}
}

async generateDataModel(optimize: number, filter: string): Promise<any> {
async generateDataModel(optimize: number, filter: string): Promise<any> {
try {
this.client = await this.getclient();
let tableNames = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@
<p-checkbox [ngStyle]="{'border': '0ch'}" class="form-control" formControlName="allowCache"
[label]="allowCacheSTR" [binary]="true">
</p-checkbox>
<p-checkbox *ngIf="form.value.type && (form.value.type.value ==='postgres' || form.value.type.value ==='mysql' || form.value.type.value ==='sqlserver')" [ngStyle]="{'border': '0ch'}" class="form-control" formControlName="allowSSL"
[label]="allowSSLSTR" [binary]="true">
</p-checkbox>
</div>
<div class="col-12 md:col-12" style="text-align: right;">
<button type="submit" pButton icon="fa fa-save" i18n-label="@@guardarBtn" label="Guardar"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ export class DsConfigWrapperComponent implements OnInit {
public optimizeString: string = $localize`:@@OptimizeQuery:Optimizar consultas`;
public allowCacheSTR: string = $localize`:@@allowCache: Habilitar caché`;
public filterTooltip: string = $localize`:@@filterTooltip:Puedes añadir palabras separadas por comas, que se aplicarán como filtros de tipo LIKE a la hora de recuperar las tablas de tu base de datos`;
public allowSSLSTR: string = $localize`:@@allowSSL:Conexión mediante SSL`;
public optimize: boolean = true;
public allowCache: boolean = true;
public allowSSL: boolean;
private project_id: string;


Expand Down Expand Up @@ -66,13 +68,13 @@ export class DsConfigWrapperComponent implements OnInit {
warehouse: [null],
optimize: [true],
allowCache: [true],
allowSSL: [false],
filter: [null]
});

}

ngOnInit(): void {

this.styleProviderService.setDefaultBackgroundColor();

}
Expand Down Expand Up @@ -140,6 +142,7 @@ export class DsConfigWrapperComponent implements OnInit {
sid: this.form.value.sid.value,
optimize: this.form.value.optimize ? 1 : 0,
allowCache: this.form.value.allowCache ? 1 : 0,
allowSSL: this.form.value.allowSSL ? 1 : 0,
filter: this.form.value.filter
};

Expand Down
5 changes: 5 additions & 0 deletions eda/eda_app/src/locale/messages.ca.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -3981,6 +3981,11 @@ Entrar<x id="CLOSE_BOLD_TEXT" ctype="x-b" equiv-text="&lt;/b&gt;"/>
<target>Nou nom</target>
</trans-unit>

<trans-unit id="allowSSL">
<source>Conexión mediante SSL</source>
<target>Conexió mijanjant SSL</target>


</body>
</file>
</xliff>

0 comments on commit d677810

Please sign in to comment.