Skip to content

Commit bed46f6

Browse files
maxamelMax Amelchenko
and
Max Amelchenko
authored
feat(serverless): add check for empty resource attributes (#7074)
* add check for empty resource attributes * add test --------- Co-authored-by: Max Amelchenko <[email protected]>
1 parent f22147c commit bed46f6

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

checkov/serverless/graph_builder/definition_context.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,18 @@ def add_resource_to_definitions_context(definitions_context: dict[str, dict[str,
3939
if resource_key in LINE_FIELD_NAMES:
4040
return
4141

42-
if isinstance(resource_attributes, dict):
43-
start_line = resource_attributes[START_LINE] - 1
44-
end_line = resource_attributes[END_LINE] - 1
45-
46-
elif isinstance(resource_attributes, ListNode):
47-
start_line = resource_attributes.start_mark.line
48-
end_line = resource_attributes.end_mark.line
49-
50-
elif isinstance(resource_attributes, StrNode):
51-
start_line = resource_attributes.start_mark.line + 1
52-
end_line = resource_attributes.end_mark.line + 1
53-
42+
if resource_attributes:
43+
if isinstance(resource_attributes, dict):
44+
start_line = resource_attributes[START_LINE] - 1
45+
end_line = resource_attributes[END_LINE] - 1
46+
elif isinstance(resource_attributes, ListNode):
47+
start_line = resource_attributes.start_mark.line
48+
end_line = resource_attributes.end_mark.line
49+
elif isinstance(resource_attributes, StrNode):
50+
start_line = resource_attributes.start_mark.line + 1
51+
end_line = resource_attributes.end_mark.line + 1
52+
else:
53+
return
5454
else:
5555
return
5656

tests/serverless/checks/aws/example_AWSCredentials/AWSCredentials-FAILED-provider_level/serverless.yml

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ provider:
55
runtime: python3.7
66
stackName: lambda-${self:service.name}
77
tag: ${opt:tag}
8+
stackTags: ${file(${env:STACK_TAGS_FILE, 'dummy.yaml'}), null}
89
environment:
910
TABLE_NAME: "mytable"
1011
BUCKET_NAME: "mybucket"

0 commit comments

Comments
 (0)