From 0b987b326144fb8aa0b2334e34b6b74c044501ec Mon Sep 17 00:00:00 2001 From: Taka Goto Date: Tue, 11 Sep 2018 13:17:21 -0500 Subject: [PATCH] config parser parses user name and passoword for database --- postgraphile/package.json | 2 +- postgraphile/spec/config/parse.spec.ts | 6 ++++-- postgraphile/src/config/parse.ts | 4 +++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/postgraphile/package.json b/postgraphile/package.json index 16339225..8f2f1b15 100644 --- a/postgraphile/package.json +++ b/postgraphile/package.json @@ -5,7 +5,7 @@ "scripts": { "build": "rm -rf ./build/dist && webpack --config=./webpack.config.js", "lint": "tslint --project ./tsconfig.json --config ./tslint.json", - "postinstall": "mkdir node_modules/@graphile && cp -R ./vendor/postgraphile-supporter/ ./node_modules/@graphile/plugin-supporter/", + "postinstall": "rm -rf node_modules/@graphile && mkdir node_modules/@graphile && cp -R ./vendor/postgraphile-supporter/ ./node_modules/@graphile/plugin-supporter/", "start": "npm run build && node ./build/dist/vulcanize-postgraphile-server.js", "test": "rm -rf ./build/spec && tsc --build ./tsconfig.test.json && jasmine --config=./spec/support/jasmine.json", "test:ci": "npm run lint && npm run test" diff --git a/postgraphile/spec/config/parse.spec.ts b/postgraphile/spec/config/parse.spec.ts index 07b7cb8f..4756cb3c 100644 --- a/postgraphile/spec/config/parse.spec.ts +++ b/postgraphile/spec/config/parse.spec.ts @@ -16,7 +16,9 @@ describe('parseConfig', () => { database: { hostname: 'example.com', name: 'example_database', - port: '1234' + port: '1234', + user: 'user', + password: 'password' } }; @@ -31,7 +33,7 @@ describe('parseConfig', () => { const databaseConfig = parseConfig( readCallback, tomlParseCallback, configPath); - expect(databaseConfig.host).toEqual('postgres://example.com:1234'); + expect(databaseConfig.host).toEqual('postgres://user:password@example.com:1234'); }); it('provides the database name', () => { diff --git a/postgraphile/src/config/parse.ts b/postgraphile/src/config/parse.ts index b804bf2a..762ba18b 100644 --- a/postgraphile/src/config/parse.ts +++ b/postgraphile/src/config/parse.ts @@ -24,6 +24,8 @@ export function parseConfig( const host = parsedToml['database']['hostname']; const port = parsedToml['database']['port']; const database = parsedToml['database']['name']; + const user = parsedToml['database']['user'] || ''; + const password = parsedToml['database']['password'] || ''; if (!host || host.length < 1) { throw new Error(MISSING_HOST_MESSAGE); @@ -33,5 +35,5 @@ export function parseConfig( throw new Error(MISSING_DATABASE_MESSAGE); } - return { host: `postgres://${host}:${port}`, database }; + return { host: `postgres://${user}:${password}@${host}:${port}`, database }; }