Skip to content

Commit

Permalink
Validate Contribution Certification in pack_metadata (#787)
Browse files Browse the repository at this point in the history
* Validate Contribution Certification in pack_metadata

* updated certification options

* fixed pre-commit

* updated function names

* added changes after CR
  • Loading branch information
darkushin authored Sep 30, 2020
1 parent 6f64d7e commit eccb64a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
* Added support for *prev-ver* flag in **lint** and **secrets** commands.
* Added support for *text* flag to **update-release-notes** command to add the same text to all release notes.
* Fixed an issue where **validate** did not recognize added files if they were modified locally.
* Added a validation to the **validate** command that checks that the certification field in the pack_metadata file is valid.

# 1.2.1
* Added an additional linter `XSOAR-linter` to the **lint** command which custom validates py files. currently checks for:
Expand Down
6 changes: 6 additions & 0 deletions demisto_sdk/commands/common/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
"pack_timestamp_field_not_in_iso_format": 'PA115',
"invalid_package_dependencies": "PA116",
"pack_readme_file_missing": "PA117",
"pack_metadata_certification_is_invalid": "PA118",
"readme_error": "RM100",
"image_path_error": "RM101",
"wrong_version_reputations": "RP100",
Expand Down Expand Up @@ -869,6 +870,11 @@ def pack_metadata_empty():
def pack_metadata_should_be_dict(pack_meta_file):
return f'Pack metadata {pack_meta_file} should be a dictionary.'

@staticmethod
@error_code_decorator
def pack_metadata_certification_is_invalid(pack_meta_file):
return f'Pack metadata {pack_meta_file} - certification field should be \'certified\' or \'verified\'.'

@staticmethod
@error_code_decorator
def missing_field_iin_pack_metadata(pack_meta_file, missing_fields):
Expand Down
18 changes: 13 additions & 5 deletions demisto_sdk/commands/common/hook_validations/pack_unique_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
from dateutil import parser
from demisto_sdk.commands.common import tools
from demisto_sdk.commands.common.constants import ( # PACK_METADATA_PRICE,
API_MODULES_PACK, PACK_METADATA_CATEGORIES, PACK_METADATA_CREATED,
PACK_METADATA_DEPENDENCIES, PACK_METADATA_DESC, PACK_METADATA_EMAIL,
PACK_METADATA_FIELDS, PACK_METADATA_KEYWORDS, PACK_METADATA_NAME,
PACK_METADATA_SUPPORT, PACK_METADATA_TAGS, PACK_METADATA_URL,
PACK_METADATA_USE_CASES, PACKS_PACK_IGNORE_FILE_NAME,
API_MODULES_PACK, PACK_METADATA_CATEGORIES, PACK_METADATA_CERTIFICATION,
PACK_METADATA_CREATED, PACK_METADATA_DEPENDENCIES, PACK_METADATA_DESC,
PACK_METADATA_EMAIL, PACK_METADATA_FIELDS, PACK_METADATA_KEYWORDS,
PACK_METADATA_NAME, PACK_METADATA_SUPPORT, PACK_METADATA_TAGS,
PACK_METADATA_URL, PACK_METADATA_USE_CASES, PACKS_PACK_IGNORE_FILE_NAME,
PACKS_PACK_META_FILE_NAME, PACKS_README_FILE_NAME,
PACKS_WHITELIST_FILE_NAME)
from demisto_sdk.commands.common.errors import Errors
Expand All @@ -30,6 +30,7 @@
CONTRIBUTORS_LIST = ['partner', 'developer', 'community']
SUPPORTED_CONTRIBUTORS_LIST = ['partner', 'developer']
ISO_TIMESTAMP_FORMAT = '%Y-%m-%dT%H:%M:%SZ'
ALLOWED_CERTIFICATION_VALUES = ['certified', 'verified']


class PackUniqueFilesValidator(BaseValidator):
Expand Down Expand Up @@ -247,6 +248,13 @@ def _is_pack_meta_file_structure_valid(self):
self.pack_meta_file):
return False

# if the field 'certification' exists, check that its value is set to 'certified' or 'verified'
certification = metadata.get(PACK_METADATA_CERTIFICATION)
if certification and certification not in ALLOWED_CERTIFICATION_VALUES:
if self._add_error(Errors.pack_metadata_certification_is_invalid(self.pack_meta_file),
self.pack_meta_file):
return False

except (ValueError, TypeError):
if self._add_error(Errors.pack_metadata_isnt_json(self.pack_meta_file), self.pack_meta_file):
return False
Expand Down

0 comments on commit eccb64a

Please sign in to comment.