Skip to content

refactor: clean code #7542

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Sep 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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