Added code to validate Azure Sentinel in PR file changes

This commit is contained in:
v-amolpatil 2022-12-16 11:11:48 +05:30
Родитель 8c16c9d3c7
Коммит 5d4706533d
3 изменённых файлов: 53 добавлений и 1 удалений

Просмотреть файл

@ -0,0 +1,13 @@
jobs:
- job: "ContentValidations"
pool:
vmImage: 'ubuntu-18.04'
steps:
- script: 'npm install -g npm@6.14.15;which npm;npm -v'
- task: Npm@1
displayName: 'npm install'
inputs:
verbose: false
command: 'install'
- script: 'npm run tsc && node .script/contentValidator.js'
displayName: 'File Content Validations'

Просмотреть файл

@ -0,0 +1,38 @@
import fs from "fs";
import { runCheckOverChangedFiles } from "./utils/changedFilesValidator";
import { ExitCode } from "./utils/exitCode";
import * as logger from "./utils/logger";
export async function ValidateFileContent(filePath: string): Promise<ExitCode>
{
// CHECK IF FILE CONTAINS "Azure Sentinel". IF YES THEN ERROR ELSE SUCCESS. THIS IS BECAUSE WE NOW WORK ON
if (!filePath.includes("azure-pipelines"))
{
const fileContent = fs.readFileSync(filePath, "utf8");
const searchText = "Azure Sentinel"
const replaceWithText = "Microsoft Sentinel"
const hasAzureSentinelText = fileContent.toLowerCase().includes(searchText.toLowerCase());
if (hasAzureSentinelText)
{
throw new Error(`'${searchText}' text is not allowed. Please replace '${searchText}' text with '${replaceWithText}' in file '${filePath}'`);
}
}
return ExitCode.SUCCESS;
}
let fileTypeSuffixes = ["json", "txt", "md", "yaml", "yml", "py"];
let fileKinds = ["Added", "Modified"];
let CheckOptions = {
onCheckFile: (filePath: string) => {
return ValidateFileContent(filePath)
},
onExecError: async (e: any) => {
logger.logError(`Content Validation check Failed: ${e.message}`);
},
onFinalFailed: async () => {
logger.logError("An error occurred, please open an issue");
},
};
runCheckOverChangedFiles(CheckOptions, fileKinds, fileTypeSuffixes);

Просмотреть файл

@ -22,4 +22,5 @@ jobs:
- template: .azure-pipelines/logoValidator.yaml
- template: .azure-pipelines/dataConnectorValidations.yaml
- template: .azure-pipelines/playbooksValidations.yaml
- template: .azure-pipelines/sampleDataValidator.yaml
- template: .azure-pipelines/sampleDataValidator.yaml
- template: .azure-pipelines/contentValidations.yaml