Skip to content

Commit

Permalink
Merge pull request #164 from rapid7/SOAR-14231-Custom_Types_HelpMD
Browse files Browse the repository at this point in the history
[SOAR-14231] Add new help validator for custom types
  • Loading branch information
cmcnally-r7 committed Jun 8, 2023
2 parents 7d290f5 + 97e2d16 commit 168d35b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ be on your way to contributing!

## Changelog

* 2.47.4 - New help validator to handle `Custom Types` title
* 2.47.3 - Fix HelpInputOutputValidator when output in plugin.spec.yaml not contain an example field | Fix validation when example contains list in object in HelpExampleValidator
* 2.47.2 - Allow hyphens in WorkflowTitleValidator
* 2.47.1 - Fix plugin spec properties validator for tasks
Expand Down
39 changes: 34 additions & 5 deletions icon_validator/rules/plugin_validators/help_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ class HelpValidator(KomandPluginValidator):
"## Technical Details",
"### Actions",
"### Triggers",
"### Custom Output Types",
"## Troubleshooting",
"# Version History",
"# Links",
"## References"
"## References",
]

CUSTOM_TYPES_HEADERS_LIST = [
"### Custom Output Types",
"### Custom Types"
]

@staticmethod
Expand Down Expand Up @@ -52,7 +56,7 @@ def validate_same_actions_title(spec, help_):
HelpValidator.validate_same_actions_loop(spec["tasks"], help_)

@staticmethod
def validate_same_actions_loop(section, help_str):
def validate_same_actions_loop(section, help_str: str):
for i in section:
if "title" in section[i]:
if f"#### {section[i]['title']}" not in help_str:
Expand All @@ -79,7 +83,7 @@ def validate_required_content(help_raw: str):
raise ValidationException(f"Help section is missing list of Links, must include at least a link to vendor")

@staticmethod
def validate_title_spelling(spec, help_):
def validate_title_spelling(spec: dict, help_):
if "title" in spec:
title = spec["title"]
lower_title = title.lower()
Expand All @@ -98,7 +102,7 @@ def validate_title_spelling(spec, help_):
"Help section contains non-matching title in line: {}".format(line))

@staticmethod
def validate_help_headers(help_str):
def validate_help_headers(help_str: str):
# if plugin without tasks needs not to be regenerated, help.md won't be having Tasks section
# Only raise exception if plugin.spec.yaml contains task and help.md does not
if HelpValidator.taskExist and "### Tasks" not in help_str:
Expand All @@ -112,6 +116,30 @@ def validate_help_headers(help_str):
if help_headers_errors:
raise ValidationException("\n".join(help_headers_errors))

@staticmethod
def validate_custom_types(help_str: str):
"""
Essentially this just checks if either 'Custom Types' or 'Custom Output Types' exists.
We handle this separately since `icon-plugin` generates the title as Custom Output Types
and `insight-plugin` generates it as `Custom Types`.
As we gradually move away from icon-plugin, we can remove this function and add 'Custom Types'
into HELP_HEADERS_LIST
:param help_str: The help.md as a raw string
"""
missing_header = []
help_headers_errors = []
for header in HelpValidator.CUSTOM_TYPES_HEADERS_LIST:
if header not in help_str:
missing_header.append(header)
if len(missing_header) == 2:
help_headers_errors.append(
f"Help section is missing either header: {[header for header in missing_header]}"
)

if help_headers_errors:
raise ValidationException("\n".join(help_headers_errors))

@staticmethod
def validate_duplicate_headings(help_raw: str):
header_errors = []
Expand All @@ -128,6 +156,7 @@ def validate_duplicate_headings(help_raw: str):
def validate(self, spec):
HelpValidator.validate_help_exists(spec.spec_dictionary())
HelpValidator.validate_help_headers(spec.raw_help())
HelpValidator.validate_custom_types(spec.raw_help())
if spec.spec_dictionary().get("tasks"):
HelpValidator.taskExist = True
HelpValidator.validate_version_history(spec.raw_help())
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setup(
name="insightconnect_integrations_validators",
version="2.47.3",
version="2.47.4",
description="Validator tooling for InsightConnect integrations",
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down

0 comments on commit 168d35b

Please sign in to comment.