@@ -45,7 +45,7 @@ def event_type_matches(events, action, api_method):
45
45
def filter_rules_match (filters , object_path ):
46
46
""" check whether the given object path matches all of the given filters """
47
47
filters = filters or {}
48
- key_filter = filters .get ('S3Key' , {} )
48
+ key_filter = filters .get ('S3Key' , filters . get ( 'Key' , {}) )
49
49
for rule in key_filter .get ('FilterRule' , []):
50
50
if rule ['Name' ] == 'prefix' :
51
51
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):
366
366
result = '<NotificationConfiguration xmlns="%s">' % XMLNS_S3
367
367
if bucket in S3_NOTIFICATIONS :
368
368
notif = S3_NOTIFICATIONS [bucket ]
369
- events_string = '\n ' .join (['<Event>%s</Event>' % e for e in notif ['Event' ]])
370
369
for dest in ['Queue' , 'Topic' , 'CloudFunction' ]:
371
370
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 )
380
380
result += '</NotificationConfiguration>'
381
381
response ._content = result
382
382
@@ -394,7 +394,7 @@ def forward_request(self, method, path, data, headers):
394
394
'Id' : config .get ('Id' ),
395
395
'Event' : events ,
396
396
dest : config .get (dest ),
397
- 'Filter' : config .get ('Filter' )
397
+ 'Filter' : config .get ('Filter' , {} )
398
398
}
399
399
# TODO: what if we have multiple destinations - would we overwrite the config?
400
400
S3_NOTIFICATIONS [bucket ] = clone (notification_details )
0 commit comments