feat: implement logs untag_log_group

This commit is contained in:
Wayne Metcalfe 2019-09-26 20:20:53 +01:00
parent 0561a0050f
commit 9c66839f85
4 changed files with 37 additions and 1 deletions

View File

@ -4092,7 +4092,7 @@
- [ ] stop_query
- [X] tag_log_group
- [ ] test_metric_filter
- [ ] untag_log_group
- [X] untag_log_group
## machinelearning
0% implemented

View File

@ -240,6 +240,10 @@ class LogGroup:
else:
self.tags = tags
def untag(self, tags_to_remove):
if self.tags:
self.tags = {k: v for (k, v) in self.tags.items() if k not in tags_to_remove}
class LogsBackend(BaseBackend):
def __init__(self, region_name):
@ -343,5 +347,11 @@ class LogsBackend(BaseBackend):
log_group = self.groups[log_group_name]
log_group.tag(tags)
def untag_log_group(self, log_group_name, tags):
if log_group_name not in self.groups:
raise ResourceNotFoundException()
log_group = self.groups[log_group_name]
log_group.untag(tags)
logs_backends = {region.name: LogsBackend(region.name) for region in boto.logs.regions()}

View File

@ -147,3 +147,9 @@ class LogsResponse(BaseResponse):
tags = self._get_param('tags')
self.logs_backend.tag_log_group(log_group_name, tags)
return ''
def untag_log_group(self):
log_group_name = self._get_param('logGroupName')
tags = self._get_param('tags')
self.logs_backend.untag_log_group(log_group_name, tags)
return ''

View File

@ -267,3 +267,23 @@ def test_tag_log_group():
assert response['tags'] == tags_with_updated_value
response = conn.delete_log_group(logGroupName=log_group_name)
@mock_logs
def test_untag_log_group():
conn = boto3.client('logs', 'us-west-2')
log_group_name = 'dummy'
response = conn.create_log_group(logGroupName=log_group_name)
tags = {'tag_key_1': 'tag_value_1', 'tag_key_2': 'tag_value_2'}
response = conn.tag_log_group(logGroupName=log_group_name, tags=tags)
response = conn.list_tags_log_group(logGroupName=log_group_name)
assert response['tags'] == tags
tags_to_remove = ['tag_key_1']
remaining_tags = {'tag_key_2': 'tag_value_2'}
response = conn.untag_log_group(logGroupName=log_group_name, tags=tags_to_remove)
response = conn.list_tags_log_group(logGroupName=log_group_name)
assert response['tags'] == remaining_tags
response = conn.delete_log_group(logGroupName=log_group_name)