Skip to content

Commit

Permalink
IT-3686: cleaned up code
Browse files Browse the repository at this point in the history
  • Loading branch information
brucehoff committed Jul 3, 2024
1 parent 2f0e4ce commit c6774ae
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 8 deletions.
4 changes: 2 additions & 2 deletions set_tags/set_bucket_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ def create_or_update(event, context):
synapse_tags = utils.get_synapse_tags(synapse_owner_id)
# put_bucket_tagging is a replace operation. need to give it all
# tags otherwise it will remove existing tags not in the list
#
#
# In case of duplication, Synapse tags should replace existing
# bucket tags.
all_tags = utils.merge_tags(bucket_tags, synapse_tags)

log.debug(f'Apply tags: {all_tags} to bucket {bucket_name}')
apply_tags(bucket_name, all_tags)

Expand Down
4 changes: 2 additions & 2 deletions set_tags/set_instance_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ def create_or_update(event, context):
extra_tags.append(provisioned_product_name_tag)
access_approved_role_tag = utils.get_access_approved_role_tag(instance_tags)
extra_tags.append(access_approved_role_tag)
#
#
# In case of duplication, Synapse tags should replace existing
# bucket tags.
#
all_tags = utils.merge_tags(extra_tags, synapse_tags)


volume_ids = get_volume_ids(instance_id)
log.debug(f'Apply tags: {all_tags} to volume {volume_ids}')
Expand Down
4 changes: 1 addition & 3 deletions set_tags/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,5 @@ def merge_tags(list1, list2):
unique_tags = format_tags_kv_kp(list1) | format_tags_kv_kp(list2)
result=[]
for entry in unique_tags:
result.append({'Key':entry,'Value':unique_tags[entry]})
result.append({'Key':entry,'Value':unique_tags[entry]})
return result


2 changes: 1 addition & 1 deletion tests/unit/utils/test_merge_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ def test_happy_case(self):
def test_collision(self):
tags = []
result = utils.merge_tags([{'Key':'foo','Value':'bar'}],[{'Key':'foo','Value':'bar2'}])
self.assertEqual(result, [{'Key':'foo','Value':'bar2'}])
self.assertEqual(result, [{'Key':'foo','Value':'bar2'}])

0 comments on commit c6774ae

Please sign in to comment.