Skip to content

Commit 31cec02

Browse files
author
Sid Madipalli
committed
Ignore PLR0912 too many branches
1 parent 026679c commit 31cec02

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

samtranslator/model/sam_resources.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ def resources_to_link(self, resources: Dict[str, Any]) -> Dict[str, Any]:
293293
raise InvalidResourceException(self.logical_id, e.message) from e
294294

295295
@cw_timer
296-
def to_cloudformation(self, **kwargs): # type: ignore[no-untyped-def] # noqa: PLR0915
296+
def to_cloudformation(self, **kwargs): # type: ignore[no-untyped-def] # noqa: PLR0915, PLR0912
297297
"""Returns the Lambda function, role, and event resources to which this SAM Function corresponds.
298298
299299
:param dict kwargs: already-converted resources that may need to be modified when converting this \
@@ -448,7 +448,7 @@ def _make_lambda_role(
448448
lambda_role = lambda_function.Role
449449
execution_role_arn = execution_role.get_runtime_attr("arn")
450450

451-
result = {
451+
result: Dict[str, Any] = {
452452
"should_append_role": False,
453453
"lambda_role_value": None,
454454
"execution_role_condition": None,
@@ -459,9 +459,13 @@ def _make_lambda_role(
459459
role_resolved_value = intrinsics_resolver.resolve_parameter_refs(lambda_role)
460460
role_condition, role_if, role_else = role_resolved_value.get("Fn::If")
461461

462+
if is_intrinsic_no_value(role_if) and is_intrinsic_no_value(role_else):
463+
result["lambda_role_value"] = execution_role_arn
464+
result["should_append_role"] = True
465+
462466
# first value is none so we should create condition ? create : [2]
463467
# create a condition for IAM role to only create on if case
464-
if is_intrinsic_no_value(role_if):
468+
elif is_intrinsic_no_value(role_if):
465469
result["lambda_role_value"] = make_conditional(role_condition, execution_role_arn, role_else)
466470
result["execution_role_condition"] = f"{role_condition}"
467471
result["should_append_role"] = True

0 commit comments

Comments
 (0)