Skip to content

Commit 2bbb998

Browse files
authored
Merge pull request #39 from secure-dashboards/feat/add-compliance-checks
2 parents 5bf36e1 + b758b15 commit 2bbb998

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

__tests__/cli/__snapshots__/workflows.test.js.snap

+5
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,10 @@ exports[`list - Non-Interactive Mode Should provide a list of available workflow
1212
"name": "upsert-github-repositories",
1313
"workflow": [Function],
1414
},
15+
{
16+
"description": "Run all the compliance checks for the stored data.",
17+
"name": "run-all-checks",
18+
"workflow": [Function],
19+
},
1520
]
1621
`;

__tests__/cli/workflows.test.js

+4
Original file line numberDiff line numberDiff line change
@@ -136,3 +136,7 @@ describe('run upsert-github-repositories', () => {
136136
})
137137
test.todo('Should throw an error when the Github API is not available')
138138
})
139+
140+
describe('run run-all-checks', () => {
141+
test.todo('Should run all the compliance checks for the stored data')
142+
})

src/cli/workflows.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const inquirer = require('inquirer').default
22
const debug = require('debug')('cli:workflows')
3-
const { updateGithubOrgs, upsertGithubRepositories } = require('../workflows')
3+
const { updateGithubOrgs, upsertGithubRepositories, runAllTheComplianceChecks } = require('../workflows')
44
const { logger } = require('../utils')
55

66
const commandList = [{
@@ -11,6 +11,10 @@ const commandList = [{
1111
name: 'upsert-github-repositories',
1212
description: 'Check the organizations stored and update/create the information related to the repositories with the GitHub API.',
1313
workflow: upsertGithubRepositories
14+
}, {
15+
name: 'run-all-checks',
16+
description: 'Run all the compliance checks for the stored data.',
17+
workflow: runAllTheComplianceChecks
1418
}]
1519

1620
const validCommandNames = commandList.map(({ name }) => name)

src/workflows/index.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const { github } = require('../providers')
33
const { initializeStore } = require('../store')
44
const { logger } = require('../utils')
55
const { validateGithubOrg, validateGithubListOrgRepos, validateGithubRepository } = require('../schemas')
6+
const checks = require('../checks')
67

78
const updateGithubOrgs = async (knex) => {
89
const { getAllGithubOrganizations, updateGithubOrganization } = initializeStore(knex)
@@ -57,7 +58,21 @@ const upsertGithubRepositories = async (knex) => {
5758
}))
5859
}
5960

61+
const runAllTheComplianceChecks = async (knex) => {
62+
const { getAllComplianceChecks } = initializeStore(knex)
63+
debug('Fetching all compliance checks')
64+
const complianceChecks = await getAllComplianceChecks()
65+
const implementedChecks = complianceChecks.filter(check => check.implementation_status === 'completed')
66+
logger.log('Running all implemented checks sequentially')
67+
for (const check of implementedChecks) {
68+
logger.log(`Running check (${check.code_name})`)
69+
await checks[check.code_name](knex)
70+
}
71+
logger.log('All checks ran successfully')
72+
}
73+
6074
module.exports = {
6175
updateGithubOrgs,
62-
upsertGithubRepositories
76+
upsertGithubRepositories,
77+
runAllTheComplianceChecks
6378
}

0 commit comments

Comments
 (0)