Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(general): Update range includes to handle range values #6867

Merged
merged 6 commits into from
Nov 27, 2024

Conversation

tsmithv11
Copy link
Collaborator

@tsmithv11 tsmithv11 commented Nov 22, 2024

User description

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Description

range_includes can handle ranges in the value like [4,10-20]

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my feature, policy, or fix is effective and works
  • New and existing tests pass locally with my changes

Generated description

Below is a concise technical summary of the changes proposed in this PR:

Enhance the RangeIncludesAttributeSolver class to support range values in the value parameter, allowing for more flexible attribute checks. This update processes range strings (e.g., "10-20") by converting them into a list of integers, thus enabling the solver to handle both single values and ranges effectively. Additionally, new test cases have been added to validate this functionality, ensuring that both range_includes and range_not_includes operations work correctly with the updated logic.

TopicDetails
Testing Enhancements Add test cases to validate the new range handling logic in RangeIncludesAttributeSolver, ensuring both range_includes and range_not_includes operations work correctly.
Modified files (6)
  • tests/terraform/graph/checks_infra/attribute_solvers/range_not_includes_solver/test_solver.py
  • tests/terraform/graph/checks_infra/attribute_solvers/range_includes_solver/test_solver.py
  • tests/terraform/graph/checks_infra/attribute_solvers/range_includes_solver/JsonPathRangeIncludesListWRange.yaml
  • tests/terraform/graph/checks_infra/attribute_solvers/range_not_includes_solver/RangeNotIncludesListWRange.yaml
  • tests/terraform/graph/checks_infra/attribute_solvers/range_includes_solver/RangeIncludesListWRange.yaml
  • tests/terraform/graph/checks_infra/attribute_solvers/range_not_includes_solver/JsonPathRangeNotIncludesListWRange.yaml
Latest Contributors(2)
UserCommitDate
tsmithv11feat-general-Update-ra...April 22, 2024
lirshindalmanfeat-general-Add-image...September 28, 2023
Range Handling Enhance the RangeIncludesAttributeSolver to support range values in the value parameter, allowing for more flexible attribute checks.
Modified files (1)
  • checkov/common/checks_infra/solvers/attribute_solvers/range_includes_attribute_solver.py
Latest Contributors(2)
UserCommitDate
tsmithv11feat-general-Update-ra...April 22, 2024
[email protected]...feat-general-igraph-li...January 25, 2023
This pull request is reviewed by Baz. Join @tsmithv11 and the rest of your team on (Baz).

value = value if isinstance(value, list) else [value]

# Process each item in the value list
processed_value: List[Any] = []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

few things here:

  1. Running code inside constructors is not ideal, is there any reason not to put this block of code inside get_operation?
  2. Please extract this part to a new function like _handle_range_values for readability of the code
  3. Update the relevant Readme to mention we support ranges

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1-2 - good callout. Moved.
3 - updated the docs for operators

@tsmithv11 tsmithv11 merged commit 7da9582 into main Nov 27, 2024
41 checks passed
@tsmithv11 tsmithv11 deleted the range-includes-range branch November 27, 2024 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants