From b90634c8d2944410a3c3aa8e01d9972aa6b90188 Mon Sep 17 00:00:00 2001 From: John Rassa Date: Thu, 8 Feb 2024 15:21:11 -0500 Subject: [PATCH] feat: updates to default config --- config/default.js | 59 +++++++------- config/production.js | 80 +------------------ src/app/common/express/error-handlers.ts | 5 +- src/app/common/mongoose/paginate.plugin.ts | 7 +- .../common/sockets/base-socket.provider.ts | 5 +- src/app/common/util.service.spec.ts | 2 +- src/app/common/util.service.ts | 2 +- src/app/core/audit/audit.model.ts | 6 +- src/app/core/audit/audit.service.ts | 19 ++--- src/lib/express.spec.ts | 16 ++-- src/lib/strategies/proxy-pki.ts | 6 +- 11 files changed, 61 insertions(+), 146 deletions(-) diff --git a/config/default.js b/config/default.js index c72337c3..1da853af 100644 --- a/config/default.js +++ b/config/default.js @@ -1,15 +1,11 @@ 'use strict'; -const contactEmail = - process.env.CONTACT_EMAIL || - process.env.MAILER_ADMIN || - 'noreply@asymmetrik.com'; +const contactEmail = process.env.CONTACT_EMAIL || 'noreply@bluehalo.com'; module.exports = { mode: 'production', - // The port to use for the application (defaults to the environment variable if present) - port: process.env.PORT || 3001, + port: 3000, // Basic title and instance name app: { @@ -18,7 +14,7 @@ module.exports = { description: 'Node REST app', clientUrl: 'http://localhost/#', helpUrl: 'http://localhost/#/help', - contactEmail: contactEmail + contactEmail: 'noreply@bluehalo.com' }, /** @@ -43,6 +39,17 @@ module.exports = { socketio: { ignoreOlderThan: 600 }, + // Use the following for local eventEmitter + publishProvider: './src/app/common/event/event-publish.provider', + socketProvider: './src/app/common/sockets/event-socket.provider', + + messages: { + topic: 'message.posted' + }, + + pages: { + topic: 'page.updated' + }, cors: { enabled: false, @@ -126,7 +133,7 @@ module.exports = { autoLogin: false, autoCreateAccounts: false, defaultRoles: {}, - // requiredRoles: ['ROLE'], + requiredRoles: [], roles: ['user', 'editor', 'auditor', 'admin'], roleStrategy: 'local', // 'local' || 'external' || 'hybrid' @@ -210,21 +217,26 @@ module.exports = { */ maxCountTimeMS: 5000, + // configures mongo TTL index. Overriding these may require dropping existing index + notificationExpires: 15552000, // 180 days + auditExpires: 15552000, //180 days + feedbackExpires: 15552000, // 180 days + /** * Environment Settings */ // Configuration for outgoing mail server / service mailer: { - from: process.env.MAILER_FROM || 'USERNAME@GMAIL.COM', + from: 'USERNAME@GMAIL.COM', provider: './src/app/core/email/providers/smtp-email.provider', options: { - host: process.env.MAILER_SERVICE_PROVIDER || 'gmail', + host: 'gmail', port: 587, secure: false, // true for 465, false for other ports auth: { - user: process.env.MAILER_EMAIL_ID || 'USERNAME@GMAIL.COM', - pass: process.env.MAILER_PASSWORD || 'PASSWORD' + user: 'USERNAME@GMAIL.COM', + pass: 'PASSWORD' } } /* @@ -321,23 +333,6 @@ module.exports = { siteEmails: {}, - // Use the following for local eventEmitter - publishProvider: './src/app/common/event/event-publish.provider', - socketProvider: './src/app/common/sockets/event-socket.provider', - - messages: { - topic: 'message.posted' - }, - - pages: { - topic: 'page.updated' - }, - - // configures mongo TTL index. Overriding these may require dropping existing index - notificationExpires: 15552000, // 180 days - auditExpires: 15552000, //180 days - feedbackExpires: 15552000, // 180 days - teams: { implicitMembers: { /** @@ -365,7 +360,7 @@ module.exports = { */ // Expose server errors to the client (500 errors) - exposeServerErrors: true, + exposeServerErrors: false, // Mongoose query logging mongooseLogging: false, @@ -383,7 +378,7 @@ module.exports = { // Console logger { stream: 'process.stdout', - level: 'info' + level: 'warn' } //, // Rotating file logger //{ @@ -448,7 +443,7 @@ module.exports = { // Copyright footer (shown above the system footer) copyright: { // HTML-enabled contents of the banner - html: 'Copyright © 2018 Asymmetrik, Ltd. All Rights Reserved.' + html: '© 2024 BLUEHALO' }, feedback: { diff --git a/config/production.js b/config/production.js index 8653a977..8b46fbba 100644 --- a/config/production.js +++ b/config/production.js @@ -1,81 +1,3 @@ 'use strict'; -module.exports = { - - /** - * System Settings - */ - - - /** - * Environment Settings - */ - - - /** - * Development/debugging settings - */ - - // Expose server errors to the client (500 errors) - exposeServerErrors: false, - - // Mongoose query logging - mongooseLogging: false, - - // Express route logging - expressLogging: false, - - - /** - * Logging Settings - */ - - // Application logging and logstash - logger: { - application: [ - // Console logger - { - stream: process.stdout, - level: 'warn' - }, - // Rotating file logger - { - type: 'rotating-file', - level: 'warn', - path: '/var/log/mean2/application.log', - period: '1d', - count: 1 - } - // Logstash logger - // { - // type: 'raw', - // level: 'info', - // stream: logstash.createStream({ - // host: 'localhost', - // port: 4561 - // }) - // } - ], - audit: [ - // Console logger (audit logger must be 'info' level) - { - stream: process.stdout, - level: 'info' - }, - // Rotating file logger - { - type: 'rotating-file', - level: 'info', - path: '/usr/local/var/log/mean2/audit.log', - period: '1d', - count: 7 - } - ] - } - - - /** - * Not So Environment-Specific Settings - */ - -}; +module.exports = {}; diff --git a/src/app/common/express/error-handlers.ts b/src/app/common/express/error-handlers.ts index 7646ba8b..e92c1f92 100644 --- a/src/app/common/express/error-handlers.ts +++ b/src/app/common/express/error-handlers.ts @@ -1,7 +1,8 @@ +import config from 'config'; import { ValidationError } from 'express-json-validator-middleware'; import _ from 'lodash'; -import { config, logger } from '../../../dependencies'; +import { logger } from '../../../dependencies'; const getStatus = (err) => { logger.error(err.status < 400); @@ -84,7 +85,7 @@ export const defaultErrorHandler = (err, req, res, next) => { if (errorResponse.status >= 500 && errorResponse.status < 600) { // Swap the error message if `exposeServerErrors` is disabled - if (!config.exposeServerErrors) { + if (!config.get('exposeServerErrors')) { errorResponse.message = 'A server error has occurred.'; delete errorResponse.stack; } diff --git a/src/app/common/mongoose/paginate.plugin.ts b/src/app/common/mongoose/paginate.plugin.ts index 1f8836ff..0e16dc63 100644 --- a/src/app/common/mongoose/paginate.plugin.ts +++ b/src/app/common/mongoose/paginate.plugin.ts @@ -1,7 +1,6 @@ +import config from 'config'; import { HydratedDocument, Query, Schema } from 'mongoose'; -import { config } from '../../../dependencies'; - const MONGO_TIMEOUT_ERROR_CODE = 50; export interface PagingResults { @@ -27,7 +26,7 @@ export function paginatePlugin(schema: Schema) { pageSize: number, pageNumber: number, runCount = true, - countTimeout = config.maxCountTimeMS + countTimeout = config.get('maxCountTimeMS') ): Promise> { const countPromise = runCount ? this.model @@ -46,7 +45,7 @@ export function paginatePlugin(schema: Schema) { const resultsPromise = this.skip(pageNumber * pageSize) .limit(pageSize) - .maxTimeMS(config.maxTimeMS) + .maxTimeMS(config.get('maxTimeMS')) .exec(); const [totalSize, elements] = await Promise.all([ diff --git a/src/app/common/sockets/base-socket.provider.ts b/src/app/common/sockets/base-socket.provider.ts index 8982cd84..9897fd3d 100644 --- a/src/app/common/sockets/base-socket.provider.ts +++ b/src/app/common/sockets/base-socket.provider.ts @@ -1,11 +1,12 @@ import * as async from 'async'; +import config from 'config'; import { Request, RequestHandler, Response } from 'express'; import { Socket } from 'socket.io'; -import { config, logger } from '../../../dependencies'; +import { logger } from '../../../dependencies'; // If this is not null, ignore any messages that are older than this number of seconds. -const ignoreOlderThan = config.socketio.ignoreOlderThan; +const ignoreOlderThan = config.get('socketio.ignoreOlderThan'); export type SocketConfig = { emitName?: string; diff --git a/src/app/common/util.service.spec.ts b/src/app/common/util.service.spec.ts index 1d637faa..68c2879b 100644 --- a/src/app/common/util.service.spec.ts +++ b/src/app/common/util.service.spec.ts @@ -544,7 +544,7 @@ describe('Utils:', () => { let originalExposeServerErrors; before(() => { - originalExposeServerErrors = config.exposeServerErrors; + originalExposeServerErrors = config.get('exposeServerErrors'); }); after(() => { diff --git a/src/app/common/util.service.ts b/src/app/common/util.service.ts index ab74ae33..58fda460 100644 --- a/src/app/common/util.service.ts +++ b/src/app/common/util.service.ts @@ -52,7 +52,7 @@ export const getErrorMessage = function (err) { * @deprecated */ export const getClientErrorMessage = function (err) { - if (config.exposeServerErrors) { + if (config.get('exposeServerErrors')) { return getErrorMessage(err); } else { return 'A server error has occurred.'; diff --git a/src/app/core/audit/audit.model.ts b/src/app/core/audit/audit.model.ts index 24144b4d..aae8c261 100644 --- a/src/app/core/audit/audit.model.ts +++ b/src/app/core/audit/audit.model.ts @@ -1,6 +1,6 @@ +import config from 'config'; import { HydratedDocument, Model, model, Schema } from 'mongoose'; -import { config } from '../../../dependencies'; import { ContainsSearchable, containsSearchPlugin @@ -71,12 +71,12 @@ AuditSchema.plugin(containsSearchPlugin, { */ // created datetime index, expires after configured time (false to disable TTL) -if (config.auditExpires === false) { +if (config.get('auditExpires') === false) { AuditSchema.index({ created: -1 }); } else { AuditSchema.index( { created: -1 }, - { expireAfterSeconds: config.auditExpires ?? 15552000 } + { expireAfterSeconds: config.get('auditExpires') } ); } diff --git a/src/app/core/audit/audit.service.ts b/src/app/core/audit/audit.service.ts index 0e3f7748..b76441e9 100644 --- a/src/app/core/audit/audit.service.ts +++ b/src/app/core/audit/audit.service.ts @@ -1,12 +1,8 @@ +import config from 'config'; import { Request } from 'express'; import { Audit, AuditDocument } from './audit.model'; -import { - config, - logger, - auditLogger, - utilService -} from '../../../dependencies'; +import { logger, auditLogger, utilService } from '../../../dependencies'; import { IUser, UserDocument } from '../user/user.model'; class AuditService { @@ -90,13 +86,14 @@ class AuditService { * Creates an audit entry persisted to Mongo and the bunyan logger */ private getMasqueradingUserDn(eventActor, headers) { - if (config.auth.strategy === 'proxy-pki' && config.auth.masquerade) { + if ( + config.get('auth.strategy') === 'proxy-pki' && + config.get('auth.masquerade') + ) { const masqueradeUserDn = - headers?.[config.masqueradeUserHeader ?? 'x-masquerade-user-dn']; + headers?.[config.get('masqueradeUserHeader')]; if (eventActor.dn && eventActor.dn === masqueradeUserDn) { - return headers?.[ - config.proxyPkiPrimaryUserHeader ?? 'x-ssl-client-s-dn' - ]; + return headers?.[config.get('proxyPkiPrimaryUserHeader')]; } } return undefined; diff --git a/src/lib/express.spec.ts b/src/lib/express.spec.ts index fb7b80c7..9e0eab81 100644 --- a/src/lib/express.spec.ts +++ b/src/lib/express.spec.ts @@ -16,8 +16,8 @@ describe('Init Swagger API:', () => { swaggerDefinition: { openapi: '3.0.2', info: { - title: config.app.title, - description: config.app.description, + title: config.get('app.title'), + description: config.get('app.description'), version: 'test' }, servers: [ @@ -28,19 +28,19 @@ describe('Init Swagger API:', () => { components: {} }, apis: [ - ...globSync(config.assets.docs).map((doc: string) => + ...globSync(config.get('assets.docs')).map((doc: string) => path.posix.resolve(doc) ), - ...globSync(config.assets.routes).map((route: string) => - path.posix.resolve(route) + ...globSync(config.get('assets.routes')).map( + (route: string) => path.posix.resolve(route) ), - ...globSync(config.assets.models).map((model: string) => - path.posix.resolve(model) + ...globSync(config.get('assets.models')).map( + (model: string) => path.posix.resolve(model) ) ] }; - if (config.auth.strategy === 'local') { + if (config.get('auth.strategy') === 'local') { swaggerOptions.swaggerDefinition.components.securitySchemes = { basicAuth: { type: 'http', diff --git a/src/lib/strategies/proxy-pki.ts b/src/lib/strategies/proxy-pki.ts index 32daed3b..c5f1b0b3 100644 --- a/src/lib/strategies/proxy-pki.ts +++ b/src/lib/strategies/proxy-pki.ts @@ -8,9 +8,9 @@ import { config } from '../../dependencies'; class ProxyPkiStrategy extends TrustedHeadersStrategy { constructor() { super([ - config.proxyPkiPrimaryUserHeader ?? 'x-ssl-client-s-dn', - config.proxyPkiProxiedUserHeader ?? 'x-proxied-user-dn', - config.masqueradeUserHeader ?? 'x-masquerade-user-dn' + config.get('proxyPkiPrimaryUserHeader'), + config.get('proxyPkiProxiedUserHeader'), + config.get('masqueradeUserHeader') ]); this.name = 'proxy-pki'; }