Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(s3-notifications): unable to delete the existing S3 event notifications #29022

Closed
wants to merge 6 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,13 @@ def handle_managed(request_type, notification_configuration):
return notification_configuration

def handle_unmanaged(bucket, stack_id, request_type, notification_configuration, old):
def get_id(n):
n['Id'] = ''
strToHash=json.dumps(n, sort_keys=True).replace("'Name:' 'prefix'", "'Name:' 'Prefix'").replace("'Name:' 'suffix'", "'Name:' 'Suffix'").
return f"{stack_id}-{hash(strToHash)}"

def with_id(n):
n['Id'] = f"{stack_id}-{hash(json.dumps(n, sort_keys=True))}"
n['Id'] = get_id(n)
return n

# find external notifications
Expand All @@ -45,9 +50,9 @@ def with_id(n):
for t in CONFIGURATION_TYPES:
if request_type == 'Update':
ids = [with_id(n) for n in old.get(t, [])]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line can be removed

old_incoming_ids = [n['Id'] for n in ids]
old_incoming_ids = [get_id(n) for n in old.get(t, [])]
# if the notification was created by us, we know what id to expect so we can filter by it.
external_notifications[t] = [n for n in existing_notifications.get(t, []) if not n['Id'] in old_incoming_ids]
external_notifications[t] = [n for n in existing_notifications.get(t, []) if not get_id(n) in old_incoming_ids]
elif request_type == 'Create':
# if this is a create event then all existing notifications are external
external_notifications[t] = [n for n in existing_notifications.get(t, [])]
Expand Down
Loading