Skip to content

Commit 68596b6

Browse files
committed
Merge branch 'release/v1.27.0'
2 parents c96cda1 + 847cf92 commit 68596b6

20 files changed

+450
-36
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ Read the [SAM Documentation Contribution Guide](https://github.com/awsdocs/aws-s
8787
started.
8888

8989
### Join the SAM Community on Slack
90-
[Join the SAM developers channel (#samdev)](https://join.slack.com/t/awsdevelopers/shared_invite/enQtMzg3NTc5OTM2MzcxLTIxNjc0ZTJkNmYyNWY3OWE4NTFiNzU1ZTM2Y2VkNmFlNjQ2YjI3YTE1ZDA5YjE5NDE2MjVmYWFlYWIxNjE2NjU) on Slack to collaborate with fellow community members and the AWS SAM team.
90+
[Join the SAM developers channel (#samdev)](https://join.slack.com/t/awsdevelopers/shared_invite/zt-h82odes6-qYN2Cxit7hBGIvC6oMjGpg) on Slack to collaborate with fellow community members and the AWS SAM team.
9191

9292

9393

docs/policy_templates.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,4 @@ folder.
7474
- CloudWatchPutMetricPolicy: {}
7575
7676
.. _policy_templates.json: https://github.com/awslabs/serverless-application-model/blob/develop/samtranslator/policy_templates_data/policy_templates.json
77-
.. _all_policy_templates.yaml: https://github.com/awslabs/serverless-application-model/blob/develop/examples/2016-10-31/policy_templates/all_policy_templates.yaml
77+
.. _all_policy_templates.yaml: https://github.com/awslabs/serverless-application-model/blob/develop/tests/translator/input/all_policy_templates.yaml

requirements/base.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
pyrsistent~=0.16.0; python_version<"3"
12
boto3~=1.5
23
enum34~=1.1; python_version<"3.4"
34
jsonschema~=3.0

samtranslator/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.26.0"
1+
__version__ = "1.27.0"

samtranslator/model/lambda_.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class LambdaLayerVersion(Resource):
107107
"Content": PropertyType(True, is_type(dict)),
108108
"Description": PropertyType(False, is_str()),
109109
"LayerName": PropertyType(False, is_str()),
110-
"CompatibleRuntimes": PropertyType(False, list_of(is_str())),
110+
"CompatibleRuntimes": PropertyType(False, list_of(one_of(is_str(), is_type(dict)))),
111111
"LicenseInfo": PropertyType(False, is_str()),
112112
}
113113

samtranslator/model/sam_resources.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class SamFunction(SamResourceMacro):
6666
"VpcConfig": PropertyType(False, is_type(dict)),
6767
"Role": PropertyType(False, is_str()),
6868
"AssumeRolePolicyDocument": PropertyType(False, is_type(dict)),
69-
"Policies": PropertyType(False, one_of(is_str(), list_of(one_of(is_str(), is_type(dict), is_type(dict))))),
69+
"Policies": PropertyType(False, one_of(is_str(), is_type(dict), list_of(one_of(is_str(), is_type(dict))))),
7070
"PermissionsBoundary": PropertyType(False, is_str()),
7171
"Environment": PropertyType(False, dict_of(is_str(), is_type(dict))),
7272
"Events": PropertyType(False, dict_of(is_str(), is_type(dict))),
@@ -1015,7 +1015,7 @@ class SamLayerVersion(SamResourceMacro):
10151015
"LayerName": PropertyType(False, one_of(is_str(), is_type(dict))),
10161016
"Description": PropertyType(False, is_str()),
10171017
"ContentUri": PropertyType(True, one_of(is_str(), is_type(dict))),
1018-
"CompatibleRuntimes": PropertyType(False, list_of(is_str())),
1018+
"CompatibleRuntimes": PropertyType(False, list_of(one_of(is_str(), is_type(dict)))),
10191019
"LicenseInfo": PropertyType(False, is_str()),
10201020
"RetentionPolicy": PropertyType(False, is_str()),
10211021
}
@@ -1121,6 +1121,7 @@ class SamStateMachine(SamResourceMacro):
11211121
"Type": PropertyType(False, is_str()),
11221122
"Tags": PropertyType(False, is_type(dict)),
11231123
"Policies": PropertyType(False, one_of(is_str(), list_of(one_of(is_str(), is_type(dict), is_type(dict))))),
1124+
"Tracing": PropertyType(False, is_type(dict)),
11241125
}
11251126
event_resolver = ResourceTypeResolver(samtranslator.model.stepfunctions.events,)
11261127

@@ -1142,6 +1143,7 @@ def to_cloudformation(self, **kwargs):
11421143
definition_substitutions=self.DefinitionSubstitutions,
11431144
role=self.Role,
11441145
state_machine_type=self.Type,
1146+
tracing=self.Tracing,
11451147
events=self.Events,
11461148
event_resources=event_resources,
11471149
event_resolver=self.event_resolver,

samtranslator/model/stepfunctions/generators.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def __init__(
4040
definition_substitutions,
4141
role,
4242
state_machine_type,
43+
tracing,
4344
events,
4445
event_resources,
4546
event_resolver,
@@ -62,6 +63,7 @@ def __init__(
6263
:param definition_substitutions: Variable-to-value mappings to be replaced in the State Machine definition
6364
:param role: Role ARN to use for the execution role
6465
:param state_machine_type: Type of the State Machine
66+
:param tracing: Tracing configuration for the State Machine
6567
:param events: List of event sources for the State Machine
6668
:param event_resources: Event resources to link
6769
:param event_resolver: Resolver that maps Event types to Event classes
@@ -83,6 +85,7 @@ def __init__(
8385
self.definition_substitutions = definition_substitutions
8486
self.role = role
8587
self.type = state_machine_type
88+
self.tracing = tracing
8689
self.events = events
8790
self.event_resources = event_resources
8891
self.event_resolver = event_resolver
@@ -144,6 +147,7 @@ def to_cloudformation(self):
144147
self.state_machine.StateMachineName = self.name
145148
self.state_machine.StateMachineType = self.type
146149
self.state_machine.LoggingConfiguration = self.logging
150+
self.state_machine.TracingConfiguration = self.tracing
147151
self.state_machine.Tags = self._construct_tag_list()
148152

149153
event_resources = self._generate_event_resources()

samtranslator/model/stepfunctions/resources.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class StepFunctionsStateMachine(Resource):
1515
"StateMachineType": PropertyType(False, is_str()),
1616
"Tags": PropertyType(False, list_of(is_type(dict))),
1717
"DefinitionSubstitutions": PropertyType(False, is_type(dict)),
18+
"TracingConfiguration": PropertyType(False, is_type(dict)),
1819
}
1920

2021
runtime_attrs = {

samtranslator/swagger/swagger.py

Lines changed: 56 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import re
44
from six import string_types
55

6-
from samtranslator.model.intrinsics import ref, is_intrinsic_no_value
7-
from samtranslator.model.intrinsics import make_conditional, fnSub, is_intrinsic_if
6+
from samtranslator.model.intrinsics import ref
7+
from samtranslator.model.intrinsics import make_conditional, fnSub
88
from samtranslator.model.exceptions import InvalidDocumentException, InvalidTemplateException
99

1010

@@ -853,6 +853,10 @@ def add_resource_policy(self, resource_policy, path, api_id, stage):
853853
ip_range_blacklist = resource_policy.get("IpRangeBlacklist")
854854
source_vpc_whitelist = resource_policy.get("SourceVpcWhitelist")
855855
source_vpc_blacklist = resource_policy.get("SourceVpcBlacklist")
856+
source_vpc_intrinsic_whitelist = resource_policy.get("IntrinsicVpcWhitelist")
857+
source_vpce_intrinsic_whitelist = resource_policy.get("IntrinsicVpceWhitelist")
858+
source_vpc_intrinsic_blacklist = resource_policy.get("IntrinsicVpcBlacklist")
859+
source_vpce_intrinsic_blacklist = resource_policy.get("IntrinsicVpceBlacklist")
856860

857861
if aws_account_whitelist is not None:
858862
resource_list = self._get_method_path_uri_list(path, api_id, stage)
@@ -870,13 +874,31 @@ def add_resource_policy(self, resource_policy, path, api_id, stage):
870874
resource_list = self._get_method_path_uri_list(path, api_id, stage)
871875
self._add_ip_resource_policy_for_method(ip_range_blacklist, "IpAddress", resource_list)
872876

873-
if source_vpc_whitelist is not None:
877+
if (
878+
(source_vpc_blacklist is not None)
879+
or (source_vpc_intrinsic_blacklist is not None)
880+
or (source_vpce_intrinsic_blacklist is not None)
881+
):
882+
blacklist_dict = {
883+
"StringEndpointList": source_vpc_blacklist,
884+
"IntrinsicVpcList": source_vpc_intrinsic_blacklist,
885+
"IntrinsicVpceList": source_vpce_intrinsic_blacklist,
886+
}
874887
resource_list = self._get_method_path_uri_list(path, api_id, stage)
875-
self._add_vpc_resource_policy_for_method(source_vpc_whitelist, "StringNotEquals", resource_list)
888+
self._add_vpc_resource_policy_for_method(blacklist_dict, "StringEquals", resource_list)
876889

877-
if source_vpc_blacklist is not None:
890+
if (
891+
(source_vpc_whitelist is not None)
892+
or (source_vpc_intrinsic_whitelist is not None)
893+
or (source_vpce_intrinsic_whitelist is not None)
894+
):
895+
whitelist_dict = {
896+
"StringEndpointList": source_vpc_whitelist,
897+
"IntrinsicVpcList": source_vpc_intrinsic_whitelist,
898+
"IntrinsicVpceList": source_vpce_intrinsic_whitelist,
899+
}
878900
resource_list = self._get_method_path_uri_list(path, api_id, stage)
879-
self._add_vpc_resource_policy_for_method(source_vpc_blacklist, "StringEquals", resource_list)
901+
self._add_vpc_resource_policy_for_method(whitelist_dict, "StringNotEquals", resource_list)
880902

881903
self._doc[self._X_APIGW_POLICY] = self.resource_policy
882904

@@ -980,33 +1002,44 @@ def _add_ip_resource_policy_for_method(self, ip_list, conditional, resource_list
9801002
statement.extend([deny_statement])
9811003
self.resource_policy["Statement"] = statement
9821004

983-
def _add_vpc_resource_policy_for_method(self, endpoint_list, conditional, resource_list):
1005+
def _add_vpc_resource_policy_for_method(self, endpoint_dict, conditional, resource_list):
9841006
"""
9851007
This method generates a policy statement to grant/deny specific VPC/VPCE access to the API method and
9861008
appends it to the swagger under `x-amazon-apigateway-policy`
9871009
:raises ValueError: If the conditional passed in does not match the allowed values.
9881010
"""
989-
if not endpoint_list:
990-
return
9911011

9921012
if conditional not in ["StringNotEquals", "StringEquals"]:
9931013
raise ValueError("Conditional must be one of {}".format(["StringNotEquals", "StringEquals"]))
9941014

995-
vpce_regex = r"^vpce-"
996-
vpc_regex = r"^vpc-"
997-
vpc_list = []
998-
vpce_list = []
999-
for endpoint in endpoint_list:
1000-
if re.match(vpce_regex, endpoint):
1001-
vpce_list.append(endpoint)
1002-
if re.match(vpc_regex, endpoint):
1003-
vpc_list.append(endpoint)
1004-
10051015
condition = {}
1006-
if vpc_list:
1007-
condition["aws:SourceVpc"] = vpc_list
1008-
if vpce_list:
1009-
condition["aws:SourceVpce"] = vpce_list
1016+
string_endpoint_list = endpoint_dict.get("StringEndpointList")
1017+
intrinsic_vpc_endpoint_list = endpoint_dict.get("IntrinsicVpcList")
1018+
intrinsic_vpce_endpoint_list = endpoint_dict.get("IntrinsicVpceList")
1019+
1020+
if string_endpoint_list is not None:
1021+
vpce_regex = r"^vpce-"
1022+
vpc_regex = r"^vpc-"
1023+
vpc_list = []
1024+
vpce_list = []
1025+
for endpoint in string_endpoint_list:
1026+
if re.match(vpce_regex, endpoint):
1027+
vpce_list.append(endpoint)
1028+
if re.match(vpc_regex, endpoint):
1029+
vpc_list.append(endpoint)
1030+
if vpc_list:
1031+
condition.setdefault("aws:SourceVpc", []).extend(vpc_list)
1032+
if vpce_list:
1033+
condition.setdefault("aws:SourceVpce", []).extend(vpce_list)
1034+
if intrinsic_vpc_endpoint_list is not None:
1035+
condition.setdefault("aws:SourceVpc", []).extend(intrinsic_vpc_endpoint_list)
1036+
if intrinsic_vpce_endpoint_list is not None:
1037+
condition.setdefault("aws:SourceVpce", []).extend(intrinsic_vpce_endpoint_list)
1038+
1039+
# Skip writing to transformed template if both vpc and vpce endpoint lists are empty
1040+
if (not condition.get("aws:SourceVpc", [])) and (not condition.get("aws:SourceVpce", [])):
1041+
return
1042+
10101043
self.resource_policy["Version"] = "2012-10-17"
10111044
allow_statement = {}
10121045
allow_statement["Effect"] = "Allow"

tests/model/stepfunctions/test_state_machine_generator.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def setUp(self):
2222
"definition_substitutions": None,
2323
"role": None,
2424
"state_machine_type": None,
25+
"tracing": None,
2526
"events": None,
2627
"event_resources": None,
2728
"event_resolver": None,

0 commit comments

Comments
 (0)