Skip to content

Commit 25fa8a8

Browse files
mgrandisvalerena
andauthored
Release/v1.37.0 (#2079)
* Release/v1.37.0 (#2069) * chore: bump version to 1.37.0 (#2068) * fix: Increase PageSize of ListPolicies Paginator (#2033) Co-authored-by: Jacob Fuss <[email protected]> Co-authored-by: Jacob Fuss <[email protected]> * feat: Support VIRTUAL_HOST as Type for SourceAccessConfiguration for MQ events (#76) (#2078) Co-authored-by: Renato Valenzuela <[email protected]>
1 parent a3a99d3 commit 25fa8a8

23 files changed

+529
-21
lines changed

samtranslator/__init__.py

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

samtranslator/model/eventsources/pull.py

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
class PullEventSource(ResourceMacro):
1111
"""Base class for pull event sources for SAM Functions.
1212
13-
The pull events are Kinesis Streams, DynamoDB Streams, Kafka Topics, ActiveMQ Queues and SQS Queues. All of these correspond to an
13+
The pull events are Kinesis Streams, DynamoDB Streams, Kafka Topics, Amazon MQ Queues and SQS Queues. All of these correspond to an
1414
EventSourceMapping in Lambda, and require that the execution role be given to Kinesis Streams, DynamoDB
1515
Streams, or SQS Queues, respectively.
1616
@@ -74,7 +74,7 @@ def to_cloudformation(self, **kwargs):
7474
if not self.Stream and not self.Queue and not self.Broker:
7575
raise InvalidEventException(
7676
self.relative_id,
77-
"No Queue (for SQS) or Stream (for Kinesis, DynamoDB or MSK) or Broker (for ActiveMQ) provided.",
77+
"No Queue (for SQS) or Stream (for Kinesis, DynamoDB or MSK) or Broker (for Amazon MQ) provided.",
7878
)
7979

8080
if self.Stream and not self.StartingPosition:
@@ -218,23 +218,38 @@ def get_policy_statements(self):
218218
if not self.SourceAccessConfigurations:
219219
raise InvalidEventException(
220220
self.relative_id,
221-
"No SourceAccessConfigurations for ActiveMQ provided.",
221+
"No SourceAccessConfigurations for Amazon MQ event provided.",
222222
)
223223
if not type(self.SourceAccessConfigurations) is list:
224224
raise InvalidEventException(
225225
self.relative_id,
226226
"Provided SourceAccessConfigurations cannot be parsed into a list.",
227227
)
228-
# MQ only supports SourceAccessConfigurations with list size of 1
229-
if not (len(self.SourceAccessConfigurations) == 1):
230-
raise InvalidEventException(
231-
self.relative_id,
232-
"SourceAccessConfigurations for ActiveMQ only supports single configuration entry.",
233-
)
234-
if not self.SourceAccessConfigurations[0].get("URI"):
228+
basic_auth_uri = None
229+
for conf in self.SourceAccessConfigurations:
230+
event_type = conf.get("Type")
231+
if event_type not in ("BASIC_AUTH", "VIRTUAL_HOST"):
232+
raise InvalidEventException(
233+
self.relative_id,
234+
"Invalid property specified in SourceAccessConfigurations for Amazon MQ event.",
235+
)
236+
if event_type == "BASIC_AUTH":
237+
if basic_auth_uri:
238+
raise InvalidEventException(
239+
self.relative_id,
240+
"Multiple BASIC_AUTH properties specified in SourceAccessConfigurations for Amazon MQ event.",
241+
)
242+
basic_auth_uri = conf.get("URI")
243+
if not basic_auth_uri:
244+
raise InvalidEventException(
245+
self.relative_id,
246+
"No BASIC_AUTH URI property specified in SourceAccessConfigurations for Amazon MQ event.",
247+
)
248+
249+
if not basic_auth_uri:
235250
raise InvalidEventException(
236251
self.relative_id,
237-
"No URI property specified in SourceAccessConfigurations for ActiveMQ.",
252+
"No BASIC_AUTH property specified in SourceAccessConfigurations for Amazon MQ event.",
238253
)
239254
document = {
240255
"PolicyName": "SamAutoGeneratedAMQPolicy",
@@ -245,7 +260,7 @@ def get_policy_statements(self):
245260
"secretsmanager:GetSecretValue",
246261
],
247262
"Effect": "Allow",
248-
"Resource": self.SourceAccessConfigurations[0].get("URI"),
263+
"Resource": basic_auth_uri,
249264
},
250265
{
251266
"Action": [

samtranslator/translator/managed_policy_translator.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,19 @@ class ManagedPolicyLoader(object):
77
def __init__(self, iam_client):
88
self._iam_client = iam_client
99
self._policy_map = None
10+
self.max_items = 1000
1011

1112
def load(self):
1213
if self._policy_map is None:
1314
LOG.info("Loading policies from IAM...")
15+
1416
paginator = self._iam_client.get_paginator("list_policies")
1517
# Setting the scope to AWS limits the returned values to only AWS Managed Policies and will
1618
# not returned policies owned by any specific account.
1719
# http://docs.aws.amazon.com/IAM/latest/APIReference/API_ListPolicies.html#API_ListPolicies_RequestParameters
18-
page_iterator = paginator.paginate(Scope="AWS")
20+
# Note(jfuss): boto3 PaginationConfig MaxItems does not control the number of items returned from the API
21+
# call. This is actually controlled by PageSize.
22+
page_iterator = paginator.paginate(Scope="AWS", PaginationConfig={"PageSize": self.max_items})
1923
name_to_arn_map = {}
2024

2125
for page in page_iterator:
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from unittest import TestCase
2+
from samtranslator.model.eventsources.pull import MQ
3+
4+
5+
class MQEventSource(TestCase):
6+
def setUp(self):
7+
self.logical_id = "MQEvent"
8+
self.mq_event_source = MQ(self.logical_id)
9+
10+
def test_get_policy_arn(self):
11+
source_arn = self.mq_event_source.get_policy_arn()
12+
expected_source_arn = None
13+
self.assertEqual(source_arn, expected_source_arn)
14+
15+
def test_get_policy_statements(self):
16+
self.mq_event_source.SourceAccessConfigurations = [{"Type": "BASIC_AUTH", "URI": "SECRET_URI"}]
17+
self.mq_event_source.Broker = "BROKER_ARN"
18+
policy_statements = self.mq_event_source.get_policy_statements()
19+
expected_policy_document = [
20+
{
21+
"PolicyName": "SamAutoGeneratedAMQPolicy",
22+
"PolicyDocument": {
23+
"Statement": [
24+
{
25+
"Action": [
26+
"secretsmanager:GetSecretValue",
27+
],
28+
"Effect": "Allow",
29+
"Resource": "SECRET_URI",
30+
},
31+
{
32+
"Action": [
33+
"mq:DescribeBroker",
34+
],
35+
"Effect": "Allow",
36+
"Resource": "BROKER_ARN",
37+
},
38+
]
39+
},
40+
}
41+
]
42+
self.assertEqual(policy_statements, expected_policy_document)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Resources:
2+
MQFunction:
3+
Type: 'AWS::Serverless::Function'
4+
Properties:
5+
CodeUri: s3://sam-demo-bucket/queues.zip
6+
Handler: queue.mq_handler
7+
Runtime: python2.7
8+
Events:
9+
MyMQQueue:
10+
Type: MQ
11+
Properties:
12+
Broker: arn:aws:mq:us-east-2:123456789012:broker:MyBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9
13+
Queues:
14+
- "Queue1"
15+
SourceAccessConfigurations:
16+
- Type: BASIC_AUTH
17+
URI: arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c
18+
- Type: VPC_SUBNET
19+
URI: invalidforMQtriggers
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Resources:
2+
MQFunction:
3+
Type: 'AWS::Serverless::Function'
4+
Properties:
5+
CodeUri: s3://sam-demo-bucket/queues.zip
6+
Handler: queue.mq_handler
7+
Runtime: python2.7
8+
Events:
9+
MyMQQueue:
10+
Type: MQ
11+
Properties:
12+
Broker: arn:aws:mq:us-east-2:123456789012:broker:MyBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9
13+
Queues:
14+
- "Queue1"
15+
SourceAccessConfigurations:
16+
- Type: VIRTUAL_HOST
17+
URI: vhost_name
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Resources:
2+
MQFunction:
3+
Type: 'AWS::Serverless::Function'
4+
Properties:
5+
CodeUri: s3://sam-demo-bucket/queues.zip
6+
Handler: queue.mq_handler
7+
Runtime: python2.7
8+
Events:
9+
MyMQQueue:
10+
Type: MQ
11+
Properties:
12+
Broker: arn:aws:mq:us-east-2:123456789012:broker:MyBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9
13+
Queues:
14+
- "Queue1"
15+
SourceAccessConfigurations:
16+
- Type: BASIC_AUTH
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Resources:
2+
MQFunction:
3+
Type: 'AWS::Serverless::Function'
4+
Properties:
5+
CodeUri: s3://sam-demo-bucket/queues.zip
6+
Handler: queue.mq_handler
7+
Runtime: python2.7
8+
Events:
9+
MyMQQueue:
10+
Type: MQ
11+
Properties:
12+
Broker: arn:aws:mq:us-east-2:123456789012:broker:MyBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9
13+
Queues:
14+
- "Queue1"
15+
SourceAccessConfigurations: []
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Resources:
2+
MQFunction:
3+
Type: 'AWS::Serverless::Function'
4+
Properties:
5+
CodeUri: s3://sam-demo-bucket/queues.zip
6+
Handler: queue.mq_handler
7+
Runtime: python2.7
8+
Events:
9+
MyMQQueue:
10+
Type: MQ
11+
Properties:
12+
Broker: arn:aws:mq:us-east-2:123456789012:broker:MyBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9
13+
Queues:
14+
- "Queue1"
15+
SourceAccessConfigurations:
16+
- Type: BASIC_AUTH
17+
URI: arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c
18+
- Type: BASIC_AUTH
19+
URI: arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-second-secret-1a2b3c
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Resources:
2+
MQFunction:
3+
Type: 'AWS::Serverless::Function'
4+
Properties:
5+
CodeUri: s3://sam-demo-bucket/queues.zip
6+
Handler: queue.mq_handler
7+
Runtime: python2.7
8+
Events:
9+
MyMQQueue:
10+
Type: MQ
11+
Properties:
12+
Broker: arn:aws:mq:us-east-2:123456789012:broker:MyBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9
13+
Queues:
14+
- "Queue1"
15+
SourceAccessConfigurations:
16+
- Type: BASIC_AUTH
17+
URI: arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c
18+
- Type: VIRTUAL_HOST
19+
URI: vhost_name

0 commit comments

Comments
 (0)