-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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): Allow skipping multiple checks in a single line #6622
Changes from 6 commits
2ce5cef
cda4f42
aebaea6
cfdcc5f
43297bf
a55fb47
71e3c71
2ed8228
ea9da32
5e9c9e5
e1fe308
898f628
2d30cb8
2ec21b9
6bed1fa
ba4d28c
cc4b0bb
614a82c
6fe5c1f
ea8df14
a34645f
1f28ea3
d91dfd5
7b20856
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import re | ||
|
||
COMMENT_REGEX = re.compile(r'(checkov:skip=|bridgecrew:skip=) *([A-Za-z_\d]+)(:[^\n]+)?') | ||
COMMENT_REGEX = re.compile(r'(checkov:skip=|bridgecrew:skip=) *([A-Za-z_\d]+(?:,[A-Za-z_\d]+)*)*(:[^\n]+)?') |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
resource "azurerm_storage_account" "default" { | ||
#checkov:skip=CKV_AZURE_33 | ||
name = "storageaccountname" | ||
resource_group_name = "azurerm_resource_group.example.name" | ||
location = "azurerm_resource_group.example.location" | ||
account_tier = "Standard" | ||
account_replication_type = "GRS" | ||
} | ||
|
||
resource "azurerm_storage_account" "skip_more_than_one" { | ||
#checkov:skip=CKV_AZURE_33,CKV_AZURE_59: Skipped by user | ||
name = "storageaccountname" | ||
resource_group_name = "azurerm_resource_group.example.name" | ||
location = "azurerm_resource_group.example.location" | ||
account_tier = "Standard" | ||
account_replication_type = "GRS" | ||
} | ||
|
||
resource "azurerm_storage_account" "skip_invalid" { | ||
#checkov:skip=CKV_AZURE_33,bla bla bla: Skipped by user | ||
name = "storageaccountname" | ||
resource_group_name = "azurerm_resource_group.example.name" | ||
location = "azurerm_resource_group.example.location" | ||
account_tier = "Standard" | ||
account_replication_type = "GRS" | ||
} | ||
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,27 @@ | ||||||
import unittest | ||||||
from pathlib import Path | ||||||
|
||||||
from checkov.runner_filter import RunnerFilter | ||||||
from checkov.terraform.runner import Runner | ||||||
|
||||||
|
||||||
class TestMultipleSkips(unittest.TestCase): | ||||||
|
||||||
def test(self) -> None: | ||||||
# given | ||||||
test_files_dir = Path(__file__).parent / "a example skip" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Please use one word in the file names. |
||||||
|
||||||
# when | ||||||
report = Runner().run(root_folder=str(test_files_dir), runner_filter=RunnerFilter(checks=[])) | ||||||
|
||||||
# then | ||||||
summary = report.get_summary() | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please assert the skipped part in the reports by resource - |
||||||
|
||||||
self.assertEqual(summary["passed"], 12) | ||||||
self.assertEqual(summary["failed"], 26) | ||||||
self.assertEqual(summary["skipped"], 4) | ||||||
self.assertEqual(summary["parsing_errors"], 0) | ||||||
|
||||||
|
||||||
if __name__ == "__main__": | ||||||
unittest.main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be great if you could create another resource that we are skipping multiple checks (maybe all the checks that the resource should fail on).