From 8718488aeef908385a312d1d0bd227cbc8fc4397 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Mon, 16 Aug 2021 15:58:04 +0100 Subject: [PATCH] couchdb direct auth --- packages/auth/src/db/utils.js | 8 +++++++- packages/server/scripts/dev/manage.js | 2 +- packages/server/src/db/client.js | 4 ++++ packages/server/src/environment.js | 2 ++ packages/worker/scripts/dev/manage.js | 2 +- packages/worker/src/db/index.js | 4 ++++ packages/worker/src/environment.js | 3 +-- 7 files changed, 20 insertions(+), 5 deletions(-) diff --git a/packages/auth/src/db/utils.js b/packages/auth/src/db/utils.js index 1fc78f4182..e3a86f8ae8 100644 --- a/packages/auth/src/db/utils.js +++ b/packages/auth/src/db/utils.js @@ -168,7 +168,13 @@ exports.getAllDbs = async () => { if (env.isTest()) { return getCouch().allDbs() } - const response = await fetch(`${env.COUCH_DB_URL}/_all_dbs`) + const response = await fetch(`${env.COUCH_DB_URL}/_all_dbs`, { + method: "POST", + body: JSON.stringify({ + name: env.COUCH_DB_USERNAME, + password: env.COUCH_DB_PASSWORD, + }), + }) if (response.status === 200) { return response.json() } else { diff --git a/packages/server/scripts/dev/manage.js b/packages/server/scripts/dev/manage.js index ffd8c6b9e3..7e9d7f6a07 100644 --- a/packages/server/scripts/dev/manage.js +++ b/packages/server/scripts/dev/manage.js @@ -36,7 +36,7 @@ async function init() { const envFileJson = { PORT: 4001, MINIO_URL: "http://localhost:10000/", - COUCH_DB_URL: "http://budibase:budibase@localhost:10000/db/", + COUCH_DB_URL: "http://localhost:10000/db/", REDIS_URL: "localhost:6379", WORKER_URL: "http://localhost:4002", INTERNAL_API_KEY: "budibase", diff --git a/packages/server/src/db/client.js b/packages/server/src/db/client.js index d50d72b18d..887b287c84 100644 --- a/packages/server/src/db/client.js +++ b/packages/server/src/db/client.js @@ -12,6 +12,10 @@ PouchDB.adapter("writableStream", replicationStream.adapters.writableStream) let POUCH_DB_DEFAULTS = { prefix: COUCH_DB_URL, + auth: { + username: env.COUCH_DB_USERNAME, + password: env.COUCH_DB_PASSWORD, + } } if (env.isTest()) { diff --git a/packages/server/src/environment.js b/packages/server/src/environment.js index 52c680f65a..45c7673851 100644 --- a/packages/server/src/environment.js +++ b/packages/server/src/environment.js @@ -23,6 +23,8 @@ module.exports = { // important PORT: process.env.PORT, JWT_SECRET: process.env.JWT_SECRET, + COUCH_DB_USERNAME: process.env.COUCH_DB_USER, + COUCH_DB_PASSWORD: process.env.COUCH_DB_PASSWORD, COUCH_DB_URL: process.env.COUCH_DB_URL, MINIO_URL: process.env.MINIO_URL, WORKER_URL: process.env.WORKER_URL, diff --git a/packages/worker/scripts/dev/manage.js b/packages/worker/scripts/dev/manage.js index b9d28b6278..d7eb76fc74 100644 --- a/packages/worker/scripts/dev/manage.js +++ b/packages/worker/scripts/dev/manage.js @@ -17,7 +17,7 @@ async function init() { REDIS_URL: "localhost:6379", REDIS_PASSWORD: "budibase", MINIO_URL: "http://localhost:10000/", - COUCH_DB_URL: "http://budibase:budibase@localhost:10000/db/", + COUCH_DB_URL: "http://localhost:10000/db/", } let envFile = "" Object.keys(envFileJson).forEach(key => { diff --git a/packages/worker/src/db/index.js b/packages/worker/src/db/index.js index d6d035cff1..d09ddf0652 100644 --- a/packages/worker/src/db/index.js +++ b/packages/worker/src/db/index.js @@ -7,6 +7,10 @@ const COUCH_DB_URL = env.COUCH_DB_URL || "http://localhost:10000/db/" let POUCH_DB_DEFAULTS = { prefix: COUCH_DB_URL, + auth: { + username: env.COUCH_DB_USERNAME, + password: env.COUCH_DB_PASSWORD, + } } if (env.isTest()) { diff --git a/packages/worker/src/environment.js b/packages/worker/src/environment.js index 384230b9b3..e8666e6b87 100644 --- a/packages/worker/src/environment.js +++ b/packages/worker/src/environment.js @@ -23,7 +23,6 @@ module.exports = { MINIO_ACCESS_KEY: process.env.MINIO_ACCESS_KEY, MINIO_SECRET_KEY: process.env.MINIO_SECRET_KEY, MINIO_URL: process.env.MINIO_URL, - COUCH_DB_URL: process.env.COUCH_DB_URL, LOG_LEVEL: process.env.LOG_LEVEL, JWT_SECRET: process.env.JWT_SECRET, SALT_ROUNDS: process.env.SALT_ROUNDS, @@ -31,7 +30,7 @@ module.exports = { REDIS_PASSWORD: process.env.REDIS_PASSWORD, INTERNAL_API_KEY: process.env.INTERNAL_API_KEY, /* TODO: to remove - once deployment removed */ - COUCH_DB_USERNAME: process.env.COUCH_DB_USERNAME, + COUCH_DB_USERNAME: process.env.COUCH_DB_USER, COUCH_DB_PASSWORD: process.env.COUCH_DB_PASSWORD, _set(key, value) { process.env[key] = value