feat: add call checks

This commit is contained in:
2024-12-26 13:06:44 +09:00
parent eb30242fe1
commit abacea4f71
10 changed files with 247 additions and 64 deletions

View File

@ -11,7 +11,7 @@ export class BPManager {
// ---
private readonly bpSets:
Record<string, BPSet | undefined> = {}
Record<string, BPSet> = {}
private readonly bpSetMetadatas:
Record<string, BPSetMetadata> = {}
@ -32,10 +32,10 @@ export class BPManager {
continue
const bpSetPath = path.join(bpSetFile.parentPath, bpSetFile.name)
const bpSetClasses = await import('../' + bpSetPath) as Record<string, BPSet>
const bpSetClasses = await import('../' + bpSetPath) as Record<string, new () => BPSet>
for (const bpSetClass of Object.keys(bpSetClasses))
this.bpSets[bpSetClass] = bpSetClasses[bpSetClass]
this.bpSets[bpSetClass] = new bpSetClasses[bpSetClass]()
}
}
@ -49,11 +49,36 @@ export class BPManager {
nonCompliantResources: [],
compliantResources: [],
status:'LOADED',
errorMessage: [],
idx
}
}
}
public async runCheck() {
for (const name in this.bpSets) {
this.bpSetMetadatas[name].status = 'CHECKING'
const result = await this.bpSets[name].check()
.catch((err) => {
this.bpSetMetadatas[name].status = 'ERROR'
this.bpSetMetadatas[name].errorMessage.push({
date: new Date(),
message: err
})
return undefined
})
if (result === undefined)
continue
this.bpSetMetadatas[name].compliantResources = result.compliantResources
this.bpSetMetadatas[name].nonCompliantResources = result.nonCompliantResources
this.bpSetMetadatas[name].status = 'FINISHED'
}
}
public readonly getBPSet = (name: string) =>
this.bpSets[name]

View File

@ -15,6 +15,7 @@ export class WebServer {
this.app.use(express.static('./public'))
this.app.get('/', this.getMainPage.bind(this))
this.app.get('/check_all', this.runCheck.bind(this))
this.app.use(this.error404)
this.app.listen(this.port, this.showBanner.bind(this))
@ -41,6 +42,12 @@ export class WebServer {
})
}
private runCheck(_: Request, res: Response) {
void this.bpManager.runCheck()
res.redirect('/')
}
private error404 (_: Request, res: Response) {
res.status(404).send({ success: false, message: 'Page not found' })
}

4
src/types.d.ts vendored
View File

@ -51,4 +51,8 @@ export interface BPSetMetadata {
compliantResources: string[]
status: 'LOADED' | 'CHECKING' | 'ERROR' | 'FINISHED'
idx: number
errorMessage: {
date: Date,
message: string
}[]
}