Skip to content

Commit cb19434

Browse files
committed
add Filter to S3 bucket notif. conf. output
1 parent a21ce5e commit cb19434

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

localstack/services/s3/s3_listener.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def event_type_matches(events, action, api_method):
4545
def filter_rules_match(filters, object_path):
4646
""" check whether the given object path matches all of the given filters """
4747
filters = filters or {}
48-
key_filter = filters.get('S3Key', {})
48+
key_filter = filters.get('S3Key', filters.get('Key', {}))
4949
for rule in key_filter.get('FilterRule', []):
5050
if rule['Name'] == 'prefix':
5151
if not prefix_with_slash(object_path).startswith(prefix_with_slash(rule['Value'])):
@@ -366,17 +366,17 @@ def forward_request(self, method, path, data, headers):
366366
result = '<NotificationConfiguration xmlns="%s">' % XMLNS_S3
367367
if bucket in S3_NOTIFICATIONS:
368368
notif = S3_NOTIFICATIONS[bucket]
369-
events_string = '\n'.join(['<Event>%s</Event>' % e for e in notif['Event']])
370369
for dest in ['Queue', 'Topic', 'CloudFunction']:
371370
if dest in notif:
372-
result += ("""<{dest}Configuration>
373-
<Id>{uid}</Id>
374-
<{dest}>{endpoint}</{dest}>
375-
{events}
376-
</{dest}Configuration>""").format(
377-
dest=dest, uid=uuid.uuid4(),
378-
endpoint=notif[dest],
379-
events=events_string)
371+
dest_dict = {
372+
'%sConfiguration' % dest: {
373+
'Id': uuid.uuid4(),
374+
dest: notif[dest],
375+
'Event': notif['Event'],
376+
'Filter': notif['Filter']
377+
}
378+
}
379+
result += xmltodict.unparse(dest_dict, full_document=False)
380380
result += '</NotificationConfiguration>'
381381
response._content = result
382382

@@ -394,7 +394,7 @@ def forward_request(self, method, path, data, headers):
394394
'Id': config.get('Id'),
395395
'Event': events,
396396
dest: config.get(dest),
397-
'Filter': config.get('Filter')
397+
'Filter': config.get('Filter', {})
398398
}
399399
# TODO: what if we have multiple destinations - would we overwrite the config?
400400
S3_NOTIFICATIONS[bucket] = clone(notification_details)

0 commit comments

Comments
 (0)