How to use list_tags_log_group method in localstack

Best Python code snippet using localstack_python

test_log_groups.py

Source:test_log_groups.py Github

copy

Full Screen

...67 }68 ]69 })70 client = policy_executor.roleclient('logs')71 client.list_tags_log_group(72 logGroupName=log_group73 )74 client.get_log_events(75 logGroupName=log_group,76 logStreamName=log_stream77 )78def test_full_stream_arn(policy_executor, log_group, log_stream):79 """While access to a group arn can permit access to the streams therein, access to a stream does not permit access to the group"""80 policy_executor.set_role_policy({81 "Version": "2012-10-17",82 "Statement": [83 {84 "Sid": "statement1",85 "Effect": "Allow",86 "Action": [87 "logs:List*",88 "logs:GetLogEvents"89 ],90 "Resource": f"arn:aws:logs:us-east-1:{ACCOUNT_ID}:log-group:{log_group}:log-stream:{log_stream}",91 }92 ]93 })94 client = policy_executor.roleclient('logs')95 client.get_log_events(96 logGroupName=log_group,97 logStreamName=log_stream98 )99 with raises_boto_code('AccessDeniedException'):100 client.list_tags_log_group(101 logGroupName=log_group102 )103@pytest.mark.parametrize("incorrect_arn", [104 f"arn:aws:logs:us-east-1:{ACCOUNT_ID}:log-group::burrito:"105 ])106def test_arn_with_incorrect_stream(policy_executor, log_group, log_stream, incorrect_arn):107 """Test arn matching with log groups. This test has an incorrect word instead of log-stream"""108 policy_executor.set_role_policy({109 "Version": "2012-10-17",110 "Statement": [111 {112 "Sid": "statement1",113 "Effect": "Allow",114 "Action": [115 "logs:List*",116 "logs:GetLogEvents"117 ],118 "Resource": incorrect_arn,119 }120 ]121 })122 client = policy_executor.roleclient('logs')123 with raises_boto_code('AccessDeniedException'):124 client.get_log_events(125 logGroupName=log_group,126 logStreamName=log_stream127 )128 with raises_boto_code('AccessDeniedException'):129 client.list_tags_log_group(130 logGroupName=log_group131 )132# Matches log group but not stream133@pytest.mark.parametrize("pattern", [134 f"arn:aws:logs:us-east-1:{ACCOUNT_ID}:log-group:{LOG_GROUP_NAME}:log-stream:",135 f"arn:aws:logs:us-east-1:{ACCOUNT_ID}:log-group:{LOG_GROUP_NAME}:*:", # Note the ending colon136 ],137 # Matches ids in iam-rule-explorer138 ids=[139 "test_arn_with_partial_stream",140 "test_arn_star_end",141 ]142 )143def test_matches_log_group_but_not_stream(policy_executor, log_group, log_stream, pattern):144 """Test arn matching with log groups. The log group arn in question ends in log-stream (no star, see test above)"""145 policy_executor.set_role_policy({146 "Version": "2012-10-17",147 "Statement": [148 {149 "Sid": "statement1",150 "Effect": "Allow",151 "Action": [152 "logs:List*",153 "logs:GetLogEvents"154 ],155 "Resource": pattern,156 }157 ]158 })159 client = policy_executor.roleclient('logs')160 client.list_tags_log_group(161 logGroupName=log_group162 )163 with raises_boto_code('AccessDeniedException'):164 client.get_log_events(165 logGroupName=log_group,166 logStreamName=log_stream...

Full Screen

Full Screen

test_cloudwatch_log.py

Source:test_cloudwatch_log.py Github

copy

Full Screen

1# Copyright 2018 Capital One Services, LLC2#3# Licensed under the Apache License, Version 2.0 (the "License");4# you may not use this file except in compliance with the License.5# You may obtain a copy of the License at6#7# http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS,11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12# See the License for the specific language governing permissions and13# limitations under the License.14import moto15from pcf.particle.aws.cloudwatch.cloudwatch_log import CloudWatchLog16from unittest.mock import Mock17import pcf.core.aws_resource18from pytest import *19import boto320from pcf.core import State21particle_definition = {22 "pcf_name": "pcf_cloudwatch_log", #Required23 "flavor": "cloudwatch_logs", #Required24 "aws_resource": {25 # https://boto3.readthedocs.io/en/latest/reference/services/logs.html#id3926 "logGroupName": "Cloud Watch Log A", #Required27 "kmsKeyId": "keyA",28 "tags": {29 # key-value pairs for tags30 "tagA": "string",31 "removed": "bye",32 }33 }34}35particle_definition2 = {36 "pcf_name": "pcf_cloudwatch_log", #Required37 "flavor": "cloudwatch_logs", #Required38 "aws_resource": {39 # https://boto3.readthedocs.io/en/latest/reference/services/logs.html#id3940 "logGroupName": "Cloud Watch Log A", #Required41 "kmsKeyId": "keyB",42 "tags": {43 # key-value pairs for tags44 "tagA": "!string",45 "new": "hi",46 }47 }48}49nothing = {50 'logGroups': [],51 'nextToken': None52}53default = {54 'logGroups': [55 {56 'logGroupName': 'Cloud Watch Log A',57 'creationTime': 123,58 'retentionInDays': 123,59 'metricFilterCount': 123,60 'arn': 'string',61 'storedBytes': 123,62 'kmsKeyId': 'keyA'63 },64 ],65 'nextToken': 'string'66}67altered = {68 'logGroups': [69 {70 'logGroupName': 'Cloud Watch Log A',71 'creationTime': 123,72 'retentionInDays': 123,73 'metricFilterCount': 123,74 'arn': 'string',75 'storedBytes': 123,76 'kmsKeyId': 'keyB'77 },78 ],79 'nextToken': 'string'80}81no_exact_match = {82 'logGroups': [83 {84 'logGroupName': 'Cloud Watch Log A- not supposed to return this one',85 'creationTime': 123,86 'retentionInDays': 123,87 'metricFilterCount': 123,88 'arn': 'string',89 'storedBytes': 123,90 'kmsKeyId': 'keyA'91 },92 ],93 'nextToken': 'string'94}95default_tag = {96 "tags": {97 "tagA": "string",98 "removed": "bye",99 }100}101altered_tag = {102 "tags": {103 "tagA": "!string",104 "new": "hi",105 }106}107@moto.mock_logs108def test_start(monkeypatch):109 """110 monkey patching until newer moto release111 """112 # tests initialization113 mock_client = Mock(114 name='mock_client',115 describe_log_groups=Mock(116 side_effect=[nothing, default, default, default]117 ),118 list_tags_log_group=Mock(119 return_value=default_tag120 )121 )122 mock_boto3 = Mock(123 client=Mock(return_value=mock_client),124 )125 monkeypatch.setattr(pcf.core.aws_resource, 'boto3', mock_boto3)126 particle = CloudWatchLog(particle_definition)127 particle.set_desired_state(State.running)128 particle.apply()129 assert particle.get_state() == State.running130 assert particle.get_current_state_definition() == particle.get_desired_state_definition()131 assert "aws_resource.logGroupName" in particle.unique_keys132def test_update(monkeypatch):133 # Test update134 mock_client = Mock(135 name='mock_client',136 describe_log_groups=Mock(137 side_effect=[default, default, default, altered, altered, altered, altered]138 ),139 list_tags_log_group=Mock(140 side_effect=[default_tag, altered_tag, altered_tag]141 )142 )143 mock_boto3 = Mock(144 client=Mock(return_value=mock_client),145 )146 monkeypatch.setattr(pcf.core.aws_resource, 'boto3', mock_boto3)147 particle = CloudWatchLog(particle_definition2)148 particle.set_desired_state(State.running)149 particle.apply()150 assert particle.get_current_state_definition() == particle.get_desired_state_definition()151 assert particle.get_state() == State.running152def test_terminate(monkeypatch):153 mock_client = Mock(154 name='mock_client',155 describe_log_groups=Mock(156 side_effect=[default, default, nothing]157 ),158 list_tags_log_group=Mock(159 side_effect=[default_tag, {"tags": {}}]160 )161 )162 mock_boto3 = Mock(163 client=Mock(return_value=mock_client),164 )165 monkeypatch.setattr(pcf.core.aws_resource, 'boto3', mock_boto3)166 #Test terminate167 particle = CloudWatchLog(particle_definition)168 particle.set_desired_state(State.terminated)169 particle.apply()...

Full Screen

Full Screen

cloudwatchLog.py

Source:cloudwatchLog.py Github

copy

Full Screen

...5 def listLogGroup(self):6 logGroups = self.client.describe_log_groups()7 return logGroups8 def listTags(self,logGroupName):9 return self.client.list_tags_log_group(logGroupName=logGroupName)10 def createTag(self,logGroupName,environment):11 return self.client.tag_log_group(logGroupName=logGroupName,tags={'environment':environment})12cl = CloudwatchLogs()13response = cl.listLogGroup()14# print len(response['logGroups'])15for group in response["logGroups"]:16 logGroupName = group['logGroupName']17 print cl.listTags(logGroupName)['tags']18 # if len(cl.listTags(logGroupName)['tags']) == 0:19 # env = logGroupName.split('/')[3]20 # if "dev3" in env:21 # cl.createTag(logGroupName,'devbeta1')22 # elif "rc" in env:23 # cl.createTag(logGroupName,'stagingdelta1')24 # elif "research" in env:25 # cl.createTag(logGroupName,'prodgamma4')26 # else:27 # cl.createTag(logGroupName,env)28#29# client = boto3.client('logs')...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful