Azure-Sentinel/.script
v-atulyadav 88f3bc4ff5
Merge pull request #10911 from niralishah-crest/VectraXDRPhase2
Added Playbooks, Analytic Rules and updated Data Connector and Workbook for Vectra XDR
2024-08-27 14:15:49 +05:30
..
SecretScanning adding new workflow for scanning secrets in commit 2024-06-13 14:39:01 +05:30
SolutionValidations Merged master into TrendMicroVisionResgistry 2023-11-23 17:53:05 +05:30
package-automation pipeline change 2024-06-19 12:20:27 +05:30
tests Merge pull request #10911 from niralishah-crest/VectraXDRPhase2 2024-08-27 14:15:49 +05:30
utils Merge branch 'master' into pr/10828 2024-08-08 14:30:36 +05:30
ReadMe.md Revert "Updated Gigamon DataConnector" 2023-10-05 17:05:37 +05:30
checkThatTemplatesVersionWasChanged.sh Revert "Updated Gigamon DataConnector" 2023-10-05 17:05:37 +05:30
contentValidator.ts Revert "Updated Gigamon DataConnector" 2023-10-05 17:05:37 +05:30
dataConnectorValidator.ts Merge branch 'master' into pr/10672 2024-07-15 13:53:01 +05:30
documentsLinkValidator.ts Revert "Updated Gigamon DataConnector" 2023-10-05 17:05:37 +05:30
getModifiedASimSchemas.ps1 including Dhcp in ARM template generation automation 2024-03-12 14:54:50 +05:30
idChangeValidator.ts 🐛 Make sure IDs actually differ before throwing an error 2024-06-14 14:41:09 +01:00
jsonFileValidator.ts Revert "Updated Gigamon DataConnector" 2023-10-05 17:05:37 +05:30
kqlFuncYaml2Arm.ps1 Revert "Updated Gigamon DataConnector" 2023-10-05 17:05:37 +05:30
logoValidator.ts Revert "Updated Gigamon DataConnector" 2023-10-05 17:05:37 +05:30
playbooksValidator.ts Revert "Updated Gigamon DataConnector" 2023-10-05 17:05:37 +05:30
sampleDataValidator.ts Revert "Updated Gigamon DataConnector" 2023-10-05 17:05:37 +05:30
validate-tag.json Revert "Updated Gigamon DataConnector" 2023-10-05 17:05:37 +05:30
workbooksMetadataValidator.ts Revert "Updated Gigamon DataConnector" 2023-10-05 17:05:37 +05:30
workbooksTemplateValidator.ts Revert "Updated Gigamon DataConnector" 2023-10-05 17:05:37 +05:30
yamlFileValidator.ts Revert "Updated Gigamon DataConnector" 2023-10-05 17:05:37 +05:30

ReadMe.md

How to add new PR validation

At the time of submitting your Pull Request, automatic GitHub validations using Azure Pipelines is enabled on this repository for basic syntactical checks of the contributions. You can add custom tests as needed based on your scenario following this guidance.

What is Azure Pipelines

Azure Pipelines is a cloud service that you can use to automatically build and test your code project and make it available to other users. It works with just about any language or project type.

How to add new PR validation:

  1. Install the following extensions, if you use VS Code editor:

  2. Run "npm install" cmd, in order to install the libraries used in this project.
    The libraries are defined in package.json

  3. Create an Azure Pipeline job for the new validation.
    Add new yaml file under .azure-pipelines folder, see example in yamlFileValidator.yaml file (note - the script code should be added on another file for clearer code, see in step #5).

    • Add scripts those are relevant to the specific folder under one yaml file in the same job. The validation infrastructure and the examples are in TypeScript, but you can use other languages if you prefer
    • Azure Pipelines work with many languages such as Python, Java,JavaScript, PHP, Ruby, C#, C++, and Go. Refer to Azure Pipelines documentation for further information on this.
  4. Add the new job to azure-pipelines.yml file as a new template under jobs property

  5. Create script file for the new validation. The job from step #3 has reference to this file. See instructions in How to add script validation section.
    A step is a failure if it either explicitly reports failure (using a ##vso command) or ends the script with a non-zero exit code

  6. Test the new validation. See instruction in How to test the new validation section

How to add script validation

Note: All script logs are public and display in DevOps pipeline.
By default, the logs color is white. In case you want another color you can use logging commands

  1. Create script file under .script folder

  2. In case you use TypeScript language, you can use the infrastructure script. See example in yamlFileValidator.ts:

    • Create an async validation function that gets the file path.
      In case the validation pass the function returns success, otherwise throws an exception (don't return an error, this will handle by the infrastructure).
    • Create CheckOptions object with 3 properties:
      • onCheckFile: the validation validation function that will run on each file (from step one)
      • onExecError: error behavior in case that the file validation failed
      • onFinalFailed: error behavior at the end of the validation, execute in case one of the validation failed
    • Call runCheckOverChangedFiles with properties:
      • checkOptions: the object you create in the earlier step 2
      • fileKinds: file kind filter, there are 3 kinds- "Added", "Modified", "Deleted"
      • fileTypeSuffixes : file type filter, example: ["yaml", "yml"]
      • filePathFolderPreffixes: folder path filter, example: ["Detections"]
    • Run prettier command to fix type script files format.
      • install "npm install -g prettier" if needed
      • Run cmd: prettier --write --print-width 200 ".script/**/*.ts"

How to test the new validation

  1. In case the language script is TypeScript, check the new validation function by local tests. Since most of the code are the same, these tests will help you validate your changes before it gets merged to master.
    See example in yamlFileValidatorTest folder.

    • Create new folder under .script/test. folder name format: TestedFileName+Test
    • Create tests file. File name format: TestedFileName.test.ts
    • Run the test by execute from cmd "npm test".
      Since it is run locally you will see "Azure DevOps CI for a Pull Request wasn't found. If issue persists - please open an issue" message. You can ignore it.
    • In order to debug the test file, select "Mocha Current File" option in VSCode
  2. After the code is merged to master, create a Draft PR to test the new validation. Check both options, pass and failed.

    • (Draft PR marked as "Work in Progress" and cannot be merged, more info here).
    • Remember to delete the draft PR.