Skip to content

Commit

Permalink
add event bus to resourcegrouptaggingapi (#8628)
Browse files Browse the repository at this point in the history
  • Loading branch information
zkarpinski authored Feb 26, 2025
1 parent b7c89b0 commit 694ce1f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
21 changes: 21 additions & 0 deletions moto/resourcegroupstaggingapi/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from moto.elb.models import ELBBackend, elb_backends
from moto.elbv2.models import ELBv2Backend, elbv2_backends
from moto.emr.models import ElasticMapReduceBackend, emr_backends
from moto.events.models import EventsBackend, events_backends
from moto.glacier.models import GlacierBackend, glacier_backends
from moto.glue.models import GlueBackend, glue_backends
from moto.kafka.models import KafkaBackend, kafka_backends
Expand Down Expand Up @@ -70,6 +71,10 @@ def elb_backend(self) -> ELBBackend:
def elbv2_backend(self) -> ELBv2Backend:
return elbv2_backends[self.account_id][self.region_name]

@property
def events_backend(self) -> EventsBackend:
return events_backends[self.account_id][self.region_name]

@property
def glue_backend(self) -> GlueBackend:
return glue_backends[self.account_id][self.region_name]
Expand Down Expand Up @@ -423,6 +428,22 @@ def format_tag_keys(

# EMR Cluster

# Events
if (
not resource_type_filters
or "events" in resource_type_filters
or "events:event-bus" in resource_type_filters
):
for bus in self.events_backend.event_buses.values():
tags = self.events_backend.tagger.list_tags_for_resource(bus.arn)[
"Tags"
]
if (
not tag_filter(tags) or len(tags) == 0
): # Skip if no tags, or invalid filter
continue
yield {"ResourceARN": f"{bus.arn}", "Tags": tags}

# Glacier Vault

# Glue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,29 @@ def test_get_tag_values_ec2():
assert "MY_VALUE4" in resp["TagValues"]


@mock_aws
def test_get_tag_values_event_bus():
client = boto3.client("events")
client.create_event_bus(Name="test-bus1")
event_bus_2 = client.create_event_bus(
Name="test-bus2", Tags=[{"Key": "Test", "Value": "Test2"}]
)
event_bus_3 = client.create_event_bus(Name="test-bus3")
client.tag_resource(
ResourceARN=event_bus_3["EventBusArn"], Tags=[{"Key": "Test", "Value": "Added"}]
)

rtapi = boto3.client("resourcegroupstaggingapi")
resp = rtapi.get_resources(ResourceTypeFilters=["events:event-bus"])
assert len(resp["ResourceTagMappingList"]) == 2
assert event_bus_2["EventBusArn"] in [
x["ResourceARN"] for x in resp["ResourceTagMappingList"]
]
assert event_bus_3["EventBusArn"] in [
x["ResourceARN"] for x in resp["ResourceTagMappingList"]
]


@mock_aws
def test_get_many_resources():
elbv2 = boto3.client("elbv2", region_name="us-east-1")
Expand Down

0 comments on commit 694ce1f

Please sign in to comment.