forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathsecret-scanning.js
29 lines (23 loc) · 1.17 KB
/
secret-scanning.js
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
import fs from 'fs'
import path from 'path'
import yaml from 'js-yaml'
import getApplicableVersions from '../../lib/get-applicable-versions.js'
const secretScanningPath = path.join('data/secret-scanning.yml')
export default async function secretScanning(req, res, next) {
if (!req.pagePath.endsWith('code-security/secret-scanning/secret-scanning-patterns'))
return next()
const secretScanningData = yaml.load(fs.readFileSync(secretScanningPath, 'utf-8'))
const { currentVersion } = req.context
// Create separate properties for each table for now - this keeps things simpler in the Markdown.
// In the future if we combine the tables into a single table or some other format, we
// can just add the entire secretScanning array to the context here.
const currentVersionData = secretScanningData.filter((entry) =>
getApplicableVersions(entry.versions).includes(currentVersion)
)
req.context.secretScanning = {
isPublic: currentVersionData.filter((entry) => entry.isPublic),
isPrivateWithGhas: currentVersionData.filter((entry) => entry.isPrivateWithGhas),
hasPushProtection: currentVersionData.filter((entry) => entry.hasPushProtection),
}
return next()
}