-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved removed_integration_parameters to new validations (#4354)
* added removed_integration_parameters * added to toml * Update demisto_sdk/commands/validate/sdk_validation_config.toml Co-authored-by: Yuval Hayun <70104171+YuvHayun@users.noreply.github.com> * pre-commit issues fixed * pre-commit issues fixed * RN --------- Co-authored-by: Yuval Hayun <70104171+YuvHayun@users.noreply.github.com>
- Loading branch information
1 parent
11d1731
commit f232b29
Showing
4 changed files
with
103 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
changes: | ||
- description: Added the `removed_integration_parameter` validation to the new validate as `NoRemovedIntegrationParametersValidator`. | ||
type: internal | ||
pr_number: 4354 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...sdk/commands/validate/validators/BC_validators/BC112_no_removed_integration_parameters.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Iterable, List, cast | ||
|
||
from demisto_sdk.commands.common.constants import GitStatuses | ||
from demisto_sdk.commands.content_graph.objects.integration import Integration | ||
from demisto_sdk.commands.content_graph.parsers.related_files import RelatedFileType | ||
from demisto_sdk.commands.validate.validators.base_validator import ( | ||
BaseValidator, | ||
ValidationResult, | ||
) | ||
|
||
ContentTypes = Integration | ||
|
||
|
||
class NoRemovedIntegrationParametersValidator(BaseValidator[ContentTypes]): | ||
error_code = "BC112" | ||
description = "Ensure that no parameters are removed from an existing integration." | ||
rationale = "Removed parameters can cause errors if the parameter is needed by the server of integration code." | ||
error_message = "Parameters have been removed from the integration, the removed parameters are: {}." | ||
related_field = "configuration" | ||
is_auto_fixable = False | ||
expected_git_statuses = [GitStatuses.MODIFIED] | ||
related_file_type = [RelatedFileType.YML] | ||
|
||
def is_valid(self, content_items: Iterable[ContentTypes]) -> List[ValidationResult]: | ||
return [ | ||
ValidationResult( | ||
validator=self, | ||
message=self.error_message.format(", ".join(map(repr, difference))), | ||
content_object=content_item, | ||
) | ||
for content_item in content_items | ||
if ( | ||
difference := self.removed_parameters( | ||
cast(ContentTypes, content_item.old_base_content_object), | ||
content_item, | ||
) | ||
) | ||
] | ||
|
||
def removed_parameters(self, old_item: ContentTypes, new_item: ContentTypes) -> set: | ||
old_params = {param.name for param in old_item.params} | ||
new_params = {param.name for param in new_item.params} | ||
return old_params.difference(new_params) |