Skip to content

Commit

Permalink
refactor: clean code (#7542)
Browse files Browse the repository at this point in the history
* add issue bot for prs

* Update CHANGELOG.md

* Update issue-bot.yml

* reformat code
  • Loading branch information
mtrezza authored Sep 2, 2021
1 parent 6ad3e6f commit 2783245
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
6 changes: 4 additions & 2 deletions src/Routers/SecurityRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions src/Security/Check.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
28 changes: 16 additions & 12 deletions src/Security/CheckRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class CheckRunner {

// If report should be written to logs
if (this.enableCheckLog) {
this._logReport(report)
this._logReport(report);
}
return report;
}
Expand Down Expand Up @@ -85,8 +85,8 @@ class CheckRunner {
report: {
version,
state: CheckState.success,
groups: []
}
groups: [],
},
};

// Identify report version
Expand All @@ -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 => {
Expand Down Expand Up @@ -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 = ' ';
Expand All @@ -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++;
Expand All @@ -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` +
Expand All @@ -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 'ℹ️';
}
}

Expand Down

0 comments on commit 2783245

Please sign in to comment.