refactor: clean code (#7542)
* add issue bot for prs * Update CHANGELOG.md * Update issue-bot.yml * reformat code
This commit is contained in:
@@ -4,10 +4,12 @@ import CheckRunner from '../Security/CheckRunner';
|
|||||||
|
|
||||||
export class SecurityRouter extends PromiseRouter {
|
export class SecurityRouter extends PromiseRouter {
|
||||||
mountRoutes() {
|
mountRoutes() {
|
||||||
this.route('GET', '/security',
|
this.route(
|
||||||
|
'GET',
|
||||||
|
'/security',
|
||||||
middleware.promiseEnforceMasterKeyAccess,
|
middleware.promiseEnforceMasterKeyAccess,
|
||||||
this._enforceSecurityCheckEnabled,
|
this._enforceSecurityCheckEnabled,
|
||||||
async (req) => {
|
async req => {
|
||||||
const report = await new CheckRunner(req.config.security).run();
|
const report = await new CheckRunner(req.config.security).run();
|
||||||
return {
|
return {
|
||||||
status: 200,
|
status: 200,
|
||||||
|
|||||||
@@ -73,9 +73,9 @@ class Check {
|
|||||||
* The check state.
|
* The check state.
|
||||||
*/
|
*/
|
||||||
const CheckState = Object.freeze({
|
const CheckState = Object.freeze({
|
||||||
none: "none",
|
none: 'none',
|
||||||
fail: "fail",
|
fail: 'fail',
|
||||||
success: "success",
|
success: 'success',
|
||||||
});
|
});
|
||||||
|
|
||||||
export default Check;
|
export default Check;
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ class CheckRunner {
|
|||||||
|
|
||||||
// If report should be written to logs
|
// If report should be written to logs
|
||||||
if (this.enableCheckLog) {
|
if (this.enableCheckLog) {
|
||||||
this._logReport(report)
|
this._logReport(report);
|
||||||
}
|
}
|
||||||
return report;
|
return report;
|
||||||
}
|
}
|
||||||
@@ -85,8 +85,8 @@ class CheckRunner {
|
|||||||
report: {
|
report: {
|
||||||
version,
|
version,
|
||||||
state: CheckState.success,
|
state: CheckState.success,
|
||||||
groups: []
|
groups: [],
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// Identify report version
|
// Identify report version
|
||||||
@@ -95,13 +95,12 @@ class CheckRunner {
|
|||||||
default:
|
default:
|
||||||
// For each check group
|
// For each check group
|
||||||
for (const group of groups) {
|
for (const group of groups) {
|
||||||
|
|
||||||
// Create group report
|
// Create group report
|
||||||
const groupReport = {
|
const groupReport = {
|
||||||
name: group.name(),
|
name: group.name(),
|
||||||
state: CheckState.success,
|
state: CheckState.success,
|
||||||
checks: [],
|
checks: [],
|
||||||
}
|
};
|
||||||
|
|
||||||
// Create check reports
|
// Create check reports
|
||||||
groupReport.checks = group.checks().map(check => {
|
groupReport.checks = group.checks().map(check => {
|
||||||
@@ -129,9 +128,9 @@ class CheckRunner {
|
|||||||
* @param {Object} report The report to log.
|
* @param {Object} report The report to log.
|
||||||
*/
|
*/
|
||||||
_logReport(report) {
|
_logReport(report) {
|
||||||
|
|
||||||
// Determine log level depending on whether any check failed
|
// 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
|
// Declare output
|
||||||
const indent = ' ';
|
const indent = ' ';
|
||||||
@@ -142,7 +141,7 @@ class CheckRunner {
|
|||||||
|
|
||||||
// Traverse all groups and checks for compose output
|
// Traverse all groups and checks for compose output
|
||||||
for (const group of report.report.groups) {
|
for (const group of report.report.groups) {
|
||||||
output += `\n- ${group.name}`
|
output += `\n- ${group.name}`;
|
||||||
|
|
||||||
for (const check of group.checks) {
|
for (const check of group.checks) {
|
||||||
checksCount++;
|
checksCount++;
|
||||||
@@ -166,7 +165,9 @@ class CheckRunner {
|
|||||||
`\n# #` +
|
`\n# #` +
|
||||||
`\n###################################` +
|
`\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${checksCount} check(s) executed` +
|
||||||
`\n${skippedCheckCount} check(s) skipped` +
|
`\n${skippedCheckCount} check(s) skipped` +
|
||||||
`\n` +
|
`\n` +
|
||||||
@@ -183,9 +184,12 @@ class CheckRunner {
|
|||||||
*/
|
*/
|
||||||
_getLogIconForState(state) {
|
_getLogIconForState(state) {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case CheckState.success: return '✅';
|
case CheckState.success:
|
||||||
case CheckState.fail: return '❌';
|
return '✅';
|
||||||
default: return 'ℹ️';
|
case CheckState.fail:
|
||||||
|
return '❌';
|
||||||
|
default:
|
||||||
|
return 'ℹ️';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user