From 4c2fce2c807ff97b696899244a7f6fad8266a05f Mon Sep 17 00:00:00 2001 From: Charmander <~@charmander.me> Date: Sat, 31 Oct 2020 15:06:36 -0700 Subject: [PATCH] [wip] Add ssl options to create-test-tables script --- packages/pg/script/create-test-tables.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/packages/pg/script/create-test-tables.js b/packages/pg/script/create-test-tables.js index c7b2ff9e0..93d0d4231 100644 --- a/packages/pg/script/create-test-tables.js +++ b/packages/pg/script/create-test-tables.js @@ -1,4 +1,5 @@ 'use strict' +var fs = require('fs') var args = require('../test/cli') var pg = require('../lib') @@ -31,13 +32,31 @@ var people = [ { name: 'Zanzabar', age: 260 }, ] -var con = new pg.Client({ +var config = { host: args.host, port: args.port, user: args.user, password: args.password, database: args.database, -}) +} + +if (process.env.PGSSLMODE) { + config.ssl = {} + + if (process.env.PGSSLROOTCERT) { + config.ssl.ca = fs.readFileSync(process.env.PGSSLROOTCERT) + } + + if (process.env.PGSSLCERT) { + config.ssl.cert = fs.readFileSync(process.env.PGSSLCERT) + } + + if (process.env.PGSSLKEY) { + config.ssl.key = fs.readFileSync(process.env.PGSSLKEY) + } +} + +var con = new pg.Client(config) con.connect((err) => { if (err) {