-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathScan.ts
More file actions
97 lines (81 loc) · 2.58 KB
/
Copy pathScan.ts
File metadata and controls
97 lines (81 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import { HydratedDocument, model, Schema, Types } from 'mongoose'
import type { ModelScanResponse, TrivyScanResultResponse } from '../clients/artefactScan.js'
import { ArtefactScanState, type ArtefactScanStateKeys } from '../connectors/artefactScanning/Base.js'
import { type SoftDeleteDocument, softDeletionPlugin } from './plugins/softDeletePlugin.js'
export type ScanInterface = {
_id: Types.ObjectId
toolName: string
scannerVersion?: string
state: ArtefactScanStateKeys
summary?: ScanSummary
additionalInfo?: TrivyScanResultResponse | ModelScanResponse
lastRunAt: Date
createdAt: Date
updatedAt: Date
} & (
| {
artefactKind: typeof ArtefactKind.FILE
fileId: string
}
| {
artefactKind: typeof ArtefactKind.IMAGE
layerDigest: string
}
)
export type ScanSummary = (ArtefactScanSummary | ClamAVSummary | string)[]
export type ArtefactScanSummary = {
severity: SeverityLevelKeys
vulnerabilityDescription: string
}
export type ClamAVSummary = {
virus: string
}
export const SeverityLevel = {
UNKNOWN: 'unknown',
LOW: 'low',
MEDIUM: 'medium',
HIGH: 'high',
CRITICAL: 'critical',
} as const
export type SeverityLevelKeys = (typeof SeverityLevel)[keyof typeof SeverityLevel]
export const ArtefactKind = {
FILE: 'file',
IMAGE: 'image',
} as const
export type ArtefactKindKeys = (typeof ArtefactKind)[keyof typeof ArtefactKind]
export type ScanInterfaceDoc = HydratedDocument<ScanInterface> & SoftDeleteDocument
const ScanSchema = new Schema<ScanInterfaceDoc>(
{
artefactKind: { type: String, enum: Object.values(ArtefactKind), required: true },
fileId: { type: String, index: true },
layerDigest: { type: String },
toolName: { type: String, required: true },
scannerVersion: { type: String },
state: { type: String, enum: Object.values(ArtefactScanState), required: true },
summary: [
{
type: Schema.Types.Mixed,
},
],
additionalInfo: { type: Schema.Types.Mixed },
lastRunAt: { type: Schema.Types.Date, required: true },
},
{
timestamps: true,
collection: 'v2_scans',
toJSON: { getters: true },
},
)
ScanSchema.plugin(softDeletionPlugin)
// Image index
ScanSchema.index(
{ artefactKind: 1, layerDigest: 1, toolName: 1 },
{ unique: true, partialFilterExpression: { artefactKind: 'image', state: 'InProgress' } },
)
// File index
ScanSchema.index(
{ artefactKind: 1, fileId: 1, toolName: 1 },
{ unique: true, partialFilterExpression: { artefactKind: 'file', state: 'InProgress' } },
)
const ScanModel = model<ScanInterfaceDoc>('v2_Scan', ScanSchema)
export default ScanModel