feat: Add http basic auth for BullMQ dashboard

This commit is contained in:
Faruk AYDIN
2022-10-30 15:10:33 +01:00
parent 53bbde4314
commit cd5502fdde
7 changed files with 62 additions and 25 deletions

View File

@@ -41,6 +41,7 @@
"discord.js": "13.2.0",
"dotenv": "^10.0.0",
"express": "~4.16.1",
"express-basic-auth": "^1.2.1",
"express-graphql": "^0.12.0",
"fast-xml-parser": "^4.0.11",
"flickr-sdk": "3.10.0",

View File

@@ -1,4 +1,3 @@
import appConfig from './config/app';
import createError from 'http-errors';
import express, { Request, Response, NextFunction } from 'express';
import cors from 'cors';
@@ -15,15 +14,11 @@ import {
} from './helpers/create-bull-board-handler';
import injectBullBoardHandler from './helpers/inject-bull-board-handler';
if (appConfig.enableBullMQDashboard) {
createBullBoardHandler(serverAdapter);
}
createBullBoardHandler(serverAdapter);
const app = express();
if (appConfig.enableBullMQDashboard) {
injectBullBoardHandler(app, serverAdapter);
}
injectBullBoardHandler(app, serverAdapter);
appAssetsHandler(app);

View File

@@ -22,6 +22,8 @@ type AppConfig = {
redisHost: string;
redisPort: number;
enableBullMQDashboard: boolean;
bullMQDashboardUsername: string;
bullMQDashboardPassword: string;
telemetryEnabled: boolean;
};
@@ -61,6 +63,8 @@ const appConfig: AppConfig = {
redisPort: parseInt(process.env.REDIS_PORT || '6379'),
enableBullMQDashboard:
process.env.ENABLE_BULLMQ_DASHBOARD === 'true' ? true : false,
bullMQDashboardUsername: process.env.BULLMQ_DASHBOARD_USERNAME,
bullMQDashboardPassword: process.env.BULLMQ_DASHBOARD_PASSWORD,
baseUrl,
webAppUrl,
telemetryEnabled: process.env.TELEMETRY_ENABLED === 'false' ? false : true,

View File

@@ -4,10 +4,18 @@ import { BullMQAdapter } from '@bull-board/api/bullMQAdapter';
import flowQueue from '../queues/flow';
import triggerQueue from '../queues/trigger';
import actionQueue from '../queues/action';
import appConfig from '../config/app';
const serverAdapter = new ExpressAdapter();
const createBullBoardHandler = async (serverAdapter: ExpressAdapter) => {
if (
!appConfig.enableBullMQDashboard ||
!appConfig.bullMQDashboardUsername ||
!appConfig.bullMQDashboardPassword
)
return;
createBullBoard({
queues: [
new BullMQAdapter(flowQueue),

View File

@@ -1,13 +1,32 @@
import { Application } from 'express';
import { ExpressAdapter } from '@bull-board/express';
import basicAuth from 'express-basic-auth';
import appConfig from '../config/app';
const injectBullBoardHandler = async (
app: Application,
serverAdapter: ExpressAdapter
) => {
if (
!appConfig.enableBullMQDashboard ||
!appConfig.bullMQDashboardUsername ||
!appConfig.bullMQDashboardPassword
)
return;
const queueDashboardBasePath = '/admin/queues';
serverAdapter.setBasePath(queueDashboardBasePath);
app.use(queueDashboardBasePath, serverAdapter.getRouter());
app.use(
queueDashboardBasePath,
basicAuth({
users: {
[appConfig.bullMQDashboardUsername]: appConfig.bullMQDashboardPassword,
},
challenge: true,
}),
serverAdapter.getRouter()
);
};
export default injectBullBoardHandler;

View File

@@ -14,19 +14,22 @@ The default values for some environment variables might be different in our deve
Please be careful with the `ENCRYPTION_KEY` environment variable. It is used to encrypt your credentials from third-party services. If you change it, you will not be able to access your connections and thus, your existing flows and connections will be useless.
:::
| Variable Name | Type | Default Value | Description |
| ------------------- | ------- | ------------------ | ----------------------------------- |
| `HOST` | string | `localhost` | HTTP Host |
| `PROTOCOL` | string | `http` | HTTP Protocol |
| `PORT` | string | `3000` | HTTP Port |
| `APP_ENV` | string | `production` | Automatisch Environment |
| `POSTGRES_DATABASE` | string | `automatisch` | Database Name |
| `POSTGRES_PORT` | number | `5432` | Database Port |
| `POSTGRES_HOST` | string | `postgres` | Database Host |
| `POSTGRES_USERNAME` | string | `automatisch_user` | Database User |
| `POSTGRES_PASSWORD` | string | | Password of Database User |
| `ENCRYPTION_KEY` | string | | Encryption Key to store credentials |
| `APP_SECRET_KEY` | string | | Secret Key to authenticate the user |
| `REDIS_HOST` | string | `redis` | Redis Host |
| `REDIS_PORT` | number | `6379` | Redis Port |
| `TELEMETRY_ENABLED` | boolean | `true` | Enable/Disable Telemetry |
| Variable Name | Type | Default Value | Description |
| --------------------------- | ------- | ------------------ | ----------------------------------- |
| `HOST` | string | `localhost` | HTTP Host |
| `PROTOCOL` | string | `http` | HTTP Protocol |
| `PORT` | string | `3000` | HTTP Port |
| `APP_ENV` | string | `production` | Automatisch Environment |
| `POSTGRES_DATABASE` | string | `automatisch` | Database Name |
| `POSTGRES_PORT` | number | `5432` | Database Port |
| `POSTGRES_HOST` | string | `postgres` | Database Host |
| `POSTGRES_USERNAME` | string | `automatisch_user` | Database User |
| `POSTGRES_PASSWORD` | string | | Password of Database User |
| `ENCRYPTION_KEY` | string | | Encryption Key to store credentials |
| `APP_SECRET_KEY` | string | | Secret Key to authenticate the user |
| `REDIS_HOST` | string | `redis` | Redis Host |
| `REDIS_PORT` | number | `6379` | Redis Port |
| `TELEMETRY_ENABLED` | boolean | `true` | Enable/Disable Telemetry |
| `ENABLE_BULLMQ_DASHBOARD` | boolean | `false` | Enable BullMQ Dashboard |
| `BULLMQ_DASHBOARD_USERNAME` | string | | Username to login BullMQ Dashboard |
| `BULLMQ_DASHBOARD_PASSWORD` | string | | Password to login BullMQ Dashboard |

View File

@@ -5984,7 +5984,7 @@ base64-js@^1.0.2, base64-js@^1.3.0, base64-js@^1.3.1:
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.5.1.tgz#1b1b440160a5bf7ad40b650f095963481903930a"
integrity sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==
basic-auth@~2.0.1:
basic-auth@^2.0.1, basic-auth@~2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/basic-auth/-/basic-auth-2.0.1.tgz#b998279bf47ce38344b4f3cf916d4679bbf51e3a"
integrity sha512-NF+epuEdnUYVlGuhaxbbq+dvJttwLnGY+YixlXlME5KpQ5W3CnXA5cVTneY3SPbPDRkcjMbifrwmFYcClgOZeg==
@@ -9082,6 +9082,13 @@ expect@^27.4.6:
jest-matcher-utils "^27.4.6"
jest-message-util "^27.4.6"
express-basic-auth@^1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/express-basic-auth/-/express-basic-auth-1.2.1.tgz#d31241c03a915dd55db7e5285573049cfcc36381"
integrity sha512-L6YQ1wQ/mNjVLAmK3AG1RK6VkokA1BIY6wmiH304Xtt/cLTps40EusZsU1Uop+v9lTDPxdtzbFmdXfFO3KEnwA==
dependencies:
basic-auth "^2.0.1"
express-graphql@^0.12.0:
version "0.12.0"
resolved "https://registry.yarnpkg.com/express-graphql/-/express-graphql-0.12.0.tgz#58deabc309909ca2c9fe2f83f5fbe94429aa23df"