Skip to content

Commit

Permalink
Parser guideline updates (#9271)
Browse files Browse the repository at this point in the history
* Create parser-documentation-template.md

* add additional line to how-to-write-a-parser.md

* Update how-to-write-a-parser.md

* add to unittests for parser

* correct linting error

---------

Co-authored-by: Paul Osinski <paul.m.osinski@gmail.com>
  • Loading branch information
paulOsinski and Paul Osinski committed Jan 10, 2024
1 parent c8d6aed commit 462c9a3
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
10 changes: 9 additions & 1 deletion docs/content/en/contributing/how-to-write-a-parser.md
Expand Up @@ -325,4 +325,12 @@ If you want to take a look at previous parsers that are now part of DefectDojo,

## Update the import page documentation

Please update [`docs/content/en/integrations/parsers.md`] with the details of your new parser.
Please add a new .md file in [`docs/content/en/integrations/parsers`] with the details of your new parser. Include the following content headings:

* Acceptable File Type(s) - please include how to generate this type of file from the related tool, as some tools have multiple methods or require specific commands.
* An example unit test block, if applicable.
* A link to the relevant unit tests folder so that users can quickly navigate there from Documentation.
* A link to the scanner itself - (e.g. GitHub or vendor link)

Here is an example of a completed Parser documentation page: https://defectdojo.github.io/django-DefectDojo/integrations/parsers/file/awssecurityhub/

20 changes: 20 additions & 0 deletions docs/content/en/contributing/parser-documentation-template.md
@@ -0,0 +1,20 @@
---
title: "Parser Documentation Template"
toc_hide: true
weight: 1
---

Use this template as part of writing a new parser.

* Copy this .md file and add it to docs/integrations/parsers/file in the GitHub repository
* Update the title to match the name of your new parser
* Fill out all sections listed below

### File Types
Specify all file types accepted by your parser. Include a process for creating the acceptable file from the related security tool.

### Sample Scan Data / Unit Tests
Add a link to the relevant unit tests or sample scan data folder in the GitHub repository.

### Link To Tool
A link to the scanner itself - (e.g. GitHub or appropriate vendor link)
11 changes: 10 additions & 1 deletion unittests/test_parsers.py
@@ -1,5 +1,6 @@
from .dojo_test_case import DojoTestCase, get_unit_tests_path
import os
import re

basedir = os.path.join(get_unit_tests_path(), '..')

Expand All @@ -26,7 +27,15 @@ def test_file_existence(self):
self.assertTrue(
os.path.isfile(doc_file),
f"Documentation file '{doc_file}' is missing or using different name"
)
)

content = open(doc_file).read()
self.assertTrue(re.search("title:", content),
f"Documentation file '{doc_file}' does not contain a title"
)
self.assertTrue(re.search("toc_hide: true", content),
f"Documentation file '{doc_file}' does not contain toc_hide: true"
)

if parser_dir.name not in [
# there is not exception for now
Expand Down

0 comments on commit 462c9a3

Please sign in to comment.