Skip to content

Commit 358a19c

Browse files
xazhaohoffa
andauthored
Fail connector when Permissions is an empty list (#261)
* Fail connector when Permissions is an empty list * Update samtranslator/model/sam_resources.py Co-authored-by: Chris Rehn <[email protected]> Co-authored-by: Chris Rehn <[email protected]>
1 parent d2d0655 commit 358a19c

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

samtranslator/model/sam_resources.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1653,9 +1653,16 @@ def to_cloudformation(self, **kwargs) -> List:
16531653
profile_permissions = profile_properties["AccessCategories"]
16541654
valid_permissions_combinations = profile_properties.get("ValidAccessCategories")
16551655

1656+
valid_permissions_str = ", ".join(profile_permissions)
1657+
1658+
if not self.Permissions:
1659+
raise InvalidResourceException(
1660+
self.logical_id,
1661+
f"'Permissions' cannot be empty; valid values are: {valid_permissions_str}.",
1662+
)
1663+
16561664
for permission in self.Permissions:
16571665
if permission not in profile_permissions:
1658-
valid_permissions_str = ", ".join(profile_permissions)
16591666
raise InvalidResourceException(
16601667
self.logical_id,
16611668
f"Unsupported 'Permissions' provided; valid values are: {valid_permissions_str}.",

tests/translator/input/error_connector.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,13 @@ Resources:
171171
Id: MyFunction
172172
Destination:
173173
Id: MyQueue
174-
Permission:
174+
Permissions:
175+
176+
EmptyListPermissionConnector:
177+
Type: AWS::Serverless::Connector
178+
Properties:
179+
Source:
180+
Id: MyFunction
181+
Destination:
182+
Id: MyQueue
183+
Permissions: []

tests/translator/output/error_connector.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@
4444
},
4545
{
4646
"errorMessage": "Resource with id [EmptyPermissionConnector] is invalid. property Permission not defined for resource of type AWS::Serverless::Connector"
47+
},
48+
{
49+
"errorMessage": "Resource with id [EmptyListPermissionConnector] is invalid. property Permission not defined for resource of type AWS::Serverless::Connector"
4750
}
4851
],
49-
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 15. Resource with id [BothIdAndOtherProps] is invalid. Must provide either 'Id' or a combination of the other properties, not both. Resource with id [EmptyPermissionConnector] is invalid. property Permission not defined for resource of type AWS::Serverless::Connector Resource with id [MissingLambdaFunctionArn] is invalid. Source.Arn is missing. Resource with id [MissingRole] is invalid. Unable to get IAM role name from 'Source' resource. Resource with id [MissingRoleDestination] is invalid. Unable to get IAM role name from 'Destination' resource. Resource with id [MissingSnsTopicArn] is invalid. Destination.Arn is missing. Resource with id [MissingSqsQueueUrl] is invalid. Destination.Arn is missing. Resource with id [NoIdMissingType] is invalid. 'Type' is missing or not a string. Resource with id [NoPermissionConnector] is invalid. Missing required property 'Permissions'. Resource with id [NonExistentLogicalId] is invalid. Unable to find resource with logical ID 'ThisDoesntExist'. Resource with id [NonStrId] is invalid. 'Id' is missing or not a string. Resource with id [ResourceWithoutType] is invalid. 'Type' is missing or not a string. Resource with id [UnsupportedAccessCategory] is invalid. Unsupported 'Permissions' provided; valid values are: Read, Write. Resource with id [UnsupportedAccessCategoryCombination] is invalid. Unsupported 'Permissions' provided; valid combinations are: Read + Write. Resource with id [UnsupportedType] is invalid. Unable to create connector from AWS::Fancy::CoolType to AWS::Lambda::Function; it's not supported or the template is invalid."
52+
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 16. Resource with id [BothIdAndOtherProps] is invalid. Must provide either 'Id' or a combination of the other properties, not both. Resource with id [EmptyListPermissionConnector] is invalid. 'Permissions' can not be empty; valid values are: Read, Write. Resource with id [EmptyPermissionConnector] is invalid. Missing required property 'Permissions'. Resource with id [MissingLambdaFunctionArn] is invalid. Source.Arn is missing. Resource with id [MissingRole] is invalid. Unable to get IAM role name from 'Source' resource. Resource with id [MissingRoleDestination] is invalid. Unable to get IAM role name from 'Destination' resource. Resource with id [MissingSnsTopicArn] is invalid. Destination.Arn is missing. Resource with id [MissingSqsQueueUrl] is invalid. Destination.Arn is missing. Resource with id [NoIdMissingType] is invalid. 'Type' is missing or not a string. Resource with id [NoPermissionConnector] is invalid. Missing required property 'Permissions'. Resource with id [NonExistentLogicalId] is invalid. Unable to find resource with logical ID 'ThisDoesntExist'. Resource with id [NonStrId] is invalid. 'Id' is missing or not a string. Resource with id [ResourceWithoutType] is invalid. 'Type' is missing or not a string. Resource with id [UnsupportedAccessCategory] is invalid. Unsupported 'Permissions' provided; valid values are: Read, Write. Resource with id [UnsupportedAccessCategoryCombination] is invalid. Unsupported 'Permissions' provided; valid combinations are: Read + Write. Resource with id [UnsupportedType] is invalid. Unable to create connector from AWS::Fancy::CoolType to AWS::Lambda::Function; it's not supported or the template is invalid."
5053
}

0 commit comments

Comments
 (0)