From 27832453e292ab9f1c607d115939a9f35f3fb373 Mon Sep 17 00:00:00 2001 From: Manuel <5673677+mtrezza@users.noreply.github.com> Date: Fri, 3 Sep 2021 01:23:15 +0200 Subject: [PATCH] refactor: clean code (#7542) * add issue bot for prs * Update CHANGELOG.md * Update issue-bot.yml * reformat code --- src/Routers/SecurityRouter.js | 6 ++++-- src/Security/Check.js | 6 +++--- src/Security/CheckRunner.js | 28 ++++++++++++++++------------ 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/Routers/SecurityRouter.js b/src/Routers/SecurityRouter.js index a9c50ecb8e..c7c217a048 100644 --- a/src/Routers/SecurityRouter.js +++ b/src/Routers/SecurityRouter.js @@ -4,10 +4,12 @@ import CheckRunner from '../Security/CheckRunner'; export class SecurityRouter extends PromiseRouter { mountRoutes() { - this.route('GET', '/security', + this.route( + 'GET', + '/security', middleware.promiseEnforceMasterKeyAccess, this._enforceSecurityCheckEnabled, - async (req) => { + async req => { const report = await new CheckRunner(req.config.security).run(); return { status: 200, diff --git a/src/Security/Check.js b/src/Security/Check.js index 7853fe7cce..dc57d63088 100644 --- a/src/Security/Check.js +++ b/src/Security/Check.js @@ -73,9 +73,9 @@ class Check { * The check state. */ const CheckState = Object.freeze({ - none: "none", - fail: "fail", - success: "success", + none: 'none', + fail: 'fail', + success: 'success', }); export default Check; diff --git a/src/Security/CheckRunner.js b/src/Security/CheckRunner.js index 2e522fefcb..a662ffbad4 100644 --- a/src/Security/CheckRunner.js +++ b/src/Security/CheckRunner.js @@ -46,7 +46,7 @@ class CheckRunner { // If report should be written to logs if (this.enableCheckLog) { - this._logReport(report) + this._logReport(report); } return report; } @@ -85,8 +85,8 @@ class CheckRunner { report: { version, state: CheckState.success, - groups: [] - } + groups: [], + }, }; // Identify report version @@ -95,13 +95,12 @@ class CheckRunner { default: // For each check group for (const group of groups) { - // Create group report const groupReport = { name: group.name(), state: CheckState.success, checks: [], - } + }; // Create check reports groupReport.checks = group.checks().map(check => { @@ -129,9 +128,9 @@ class CheckRunner { * @param {Object} report The report to log. */ _logReport(report) { - // Determine log level depending on whether any check failed - const log = report.report.state == CheckState.success ? (s) => logger.info(s) : (s) => logger.warn(s); + const log = + report.report.state == CheckState.success ? s => logger.info(s) : s => logger.warn(s); // Declare output const indent = ' '; @@ -142,7 +141,7 @@ class CheckRunner { // Traverse all groups and checks for compose output for (const group of report.report.groups) { - output += `\n- ${group.name}` + output += `\n- ${group.name}`; for (const check of group.checks) { checksCount++; @@ -166,7 +165,9 @@ class CheckRunner { `\n# #` + `\n###################################` + `\n` + - `\n${failedChecksCount > 0 ? 'Warning: ' : ''}${failedChecksCount} weak security setting(s) found${failedChecksCount > 0 ? '!' : ''}` + + `\n${ + failedChecksCount > 0 ? 'Warning: ' : '' + }${failedChecksCount} weak security setting(s) found${failedChecksCount > 0 ? '!' : ''}` + `\n${checksCount} check(s) executed` + `\n${skippedCheckCount} check(s) skipped` + `\n` + @@ -183,9 +184,12 @@ class CheckRunner { */ _getLogIconForState(state) { switch (state) { - case CheckState.success: return '✅'; - case CheckState.fail: return '❌'; - default: return 'ℹ️'; + case CheckState.success: + return '✅'; + case CheckState.fail: + return '❌'; + default: + return 'ℹ️'; } }