feat: implement logs tag_log_group
This commit is contained in:
parent
3cb7c3e568
commit
0561a0050f
@ -4090,7 +4090,7 @@
|
|||||||
- [ ] put_subscription_filter
|
- [ ] put_subscription_filter
|
||||||
- [ ] start_query
|
- [ ] start_query
|
||||||
- [ ] stop_query
|
- [ ] stop_query
|
||||||
- [ ] tag_log_group
|
- [X] tag_log_group
|
||||||
- [ ] test_metric_filter
|
- [ ] test_metric_filter
|
||||||
- [ ] untag_log_group
|
- [ ] untag_log_group
|
||||||
|
|
||||||
|
@ -234,6 +234,12 @@ class LogGroup:
|
|||||||
def list_tags(self):
|
def list_tags(self):
|
||||||
return self.tags if self.tags else {}
|
return self.tags if self.tags else {}
|
||||||
|
|
||||||
|
def tag(self, tags):
|
||||||
|
if self.tags:
|
||||||
|
self.tags.update(tags)
|
||||||
|
else:
|
||||||
|
self.tags = tags
|
||||||
|
|
||||||
|
|
||||||
class LogsBackend(BaseBackend):
|
class LogsBackend(BaseBackend):
|
||||||
def __init__(self, region_name):
|
def __init__(self, region_name):
|
||||||
@ -331,5 +337,11 @@ class LogsBackend(BaseBackend):
|
|||||||
log_group = self.groups[log_group_name]
|
log_group = self.groups[log_group_name]
|
||||||
return log_group.list_tags()
|
return log_group.list_tags()
|
||||||
|
|
||||||
|
def tag_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.tag(tags)
|
||||||
|
|
||||||
|
|
||||||
logs_backends = {region.name: LogsBackend(region.name) for region in boto.logs.regions()}
|
logs_backends = {region.name: LogsBackend(region.name) for region in boto.logs.regions()}
|
||||||
|
@ -142,3 +142,8 @@ class LogsResponse(BaseResponse):
|
|||||||
'tags': tags
|
'tags': tags
|
||||||
})
|
})
|
||||||
|
|
||||||
|
def tag_log_group(self):
|
||||||
|
log_group_name = self._get_param('logGroupName')
|
||||||
|
tags = self._get_param('tags')
|
||||||
|
self.logs_backend.tag_log_group(log_group_name, tags)
|
||||||
|
return ''
|
||||||
|
@ -243,3 +243,27 @@ def test_list_tags_log_group():
|
|||||||
assert response['tags'] == tags
|
assert response['tags'] == tags
|
||||||
|
|
||||||
response = conn.delete_log_group(logGroupName=log_group_name)
|
response = conn.delete_log_group(logGroupName=log_group_name)
|
||||||
|
|
||||||
|
|
||||||
|
@mock_logs
|
||||||
|
def test_tag_log_group():
|
||||||
|
conn = boto3.client('logs', 'us-west-2')
|
||||||
|
log_group_name = 'dummy'
|
||||||
|
tags = {'tag_key_1': 'tag_value_1'}
|
||||||
|
response = conn.create_log_group(logGroupName=log_group_name)
|
||||||
|
|
||||||
|
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_with_added_value = {'tag_key_1': 'tag_value_1', 'tag_key_2': 'tag_value_2'}
|
||||||
|
response = conn.tag_log_group(logGroupName=log_group_name, tags={'tag_key_2': 'tag_value_2'})
|
||||||
|
response = conn.list_tags_log_group(logGroupName=log_group_name)
|
||||||
|
assert response['tags'] == tags_with_added_value
|
||||||
|
|
||||||
|
tags_with_updated_value = {'tag_key_1': 'tag_value_XX', 'tag_key_2': 'tag_value_2'}
|
||||||
|
response = conn.tag_log_group(logGroupName=log_group_name, tags={'tag_key_1': 'tag_value_XX'})
|
||||||
|
response = conn.list_tags_log_group(logGroupName=log_group_name)
|
||||||
|
assert response['tags'] == tags_with_updated_value
|
||||||
|
|
||||||
|
response = conn.delete_log_group(logGroupName=log_group_name)
|
||||||
|
Loading…
Reference in New Issue
Block a user