cloudflare/Azure-Sentinel
Publicmirrored fromhttps://github.com/cloudflare/Azure-Sentinel
.script/yamlFileValidator.ts
26lines · modecode
6 years ago
| 1 | import { runCheckOverChangedFiles } from "./utils/changedFilesValidator"; |
| 2 | import { ExitCode } from "./utils/exitCode"; |
| 3 | import yaml from "js-yaml"; |
| 4 | import fs from "fs"; |
| 5 | import * as logger from "./utils/logger"; |
| 6 | |
| 7 | export async function IsValidYamlFile(filePath: string): Promise<ExitCode> { |
| 8 | yaml.safeLoad(fs.readFileSync(filePath, "utf8")); |
| 9 | return ExitCode.SUCCESS; |
| 10 | } |
| 11 | |
| 12 | let fileTypeSuffixes = ["yaml", "yml"]; |
| 13 | let fileKinds = ["Added", "Modified"]; |
| 14 | let CheckOptions = { |
| 15 | onCheckFile: (filePath: string) => { |
| 16 | return IsValidYamlFile(filePath); |
| 17 | }, |
| 18 | onExecError: async (e: any, filePath: string) => { |
| 19 | console.log(`Incorrect yaml file. File path: ${filePath}. Error message: ${e.message}`); |
| 20 | }, |
| 21 | onFinalFailed: async () => { |
| 22 | logger.logError("An error occurred, please open an issue"); |
| 23 | } |
| 24 | }; |
| 25 | |
| 26 | runCheckOverChangedFiles(CheckOptions, fileKinds, fileTypeSuffixes); |