Skip to content

Commit

Permalink
refactor: ssl to getSSL method
Browse files Browse the repository at this point in the history
  • Loading branch information
chr33s committed Sep 21, 2023
1 parent db251bf commit c348165
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ describe('MySQLSessionStorage', () => {

it(`can successfully connect with a url string and ssl param`, async () => {
const _dbURL = new URL(dbURL);
_dbURL.searchParams.append('ssl', 'false');
_dbURL.searchParams.append('ssl', '{"rejectUnauthorized":true}');
const storage = new MySQLSessionStorage(_dbURL.toString());
await storage.ready;
const session = new Session({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ export class MySqlConnection implements RdbmsConnection {
return decodeURIComponent(this.dbUrl.pathname.slice(1));
}

public getSSL(): string | mysql.SslOptions | undefined {
const ssl = this.dbUrl.searchParams.get('ssl');
if (!ssl) {
return undefined;
}
return JSON.parse(ssl);
}

async hasTable(tablename: string): Promise<boolean> {
await this.ready;

Expand Down Expand Up @@ -103,7 +111,7 @@ export class MySqlConnection implements RdbmsConnection {
password: decodeURIComponent(this.dbUrl.password),
database: this.getDatabase(),
port: Number(this.dbUrl.port),
ssl: (this.dbUrl.searchParams.get('ssl') !== 'false').toString(),
ssl: this.getSSL(),
});
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pg from 'pg';
import type {ConnectionOptions} from '@types/pg';
import {RdbmsConnection} from '@shopify/shopify-app-session-storage';

export class PostgresConnection implements RdbmsConnection {
Expand Down Expand Up @@ -63,6 +64,14 @@ export class PostgresConnection implements RdbmsConnection {
return decodeURIComponent(this.dbUrl.pathname.slice(1));
}

public getSSL(): boolean | ConnectionOptions | undefined {
const ssl = this.dbUrl.searchParams.get('ssl');
if (!ssl) {
return undefined;
}
return JSON.parse(ssl);
}

async hasTable(tablename: string): Promise<boolean> {
await this.ready;
const query = `
Expand All @@ -89,7 +98,7 @@ export class PostgresConnection implements RdbmsConnection {
password: decodeURIComponent(this.dbUrl.password),
database: this.getDatabase(),
port: Number(this.dbUrl.port),
ssl: this.dbUrl.searchParams.get('ssl') !== 'false',
ssl: this.getSSL(),
});
}
}

0 comments on commit c348165

Please sign in to comment.