Add events.list_event_buses
This commit is contained in:
parent
f1dbdc9184
commit
831577350d
@ -2713,7 +2713,7 @@
|
|||||||
- [ ] upgrade_elasticsearch_domain
|
- [ ] upgrade_elasticsearch_domain
|
||||||
|
|
||||||
## events
|
## events
|
||||||
51% implemented
|
54% implemented
|
||||||
- [ ] activate_event_source
|
- [ ] activate_event_source
|
||||||
- [X] create_event_bus
|
- [X] create_event_bus
|
||||||
- [ ] create_partner_event_source
|
- [ ] create_partner_event_source
|
||||||
@ -2727,7 +2727,7 @@
|
|||||||
- [X] describe_rule
|
- [X] describe_rule
|
||||||
- [X] disable_rule
|
- [X] disable_rule
|
||||||
- [X] enable_rule
|
- [X] enable_rule
|
||||||
- [ ] list_event_buses
|
- [X] list_event_buses
|
||||||
- [ ] list_event_sources
|
- [ ] list_event_sources
|
||||||
- [ ] list_partner_event_source_accounts
|
- [ ] list_partner_event_source_accounts
|
||||||
- [ ] list_partner_event_sources
|
- [ ] list_partner_event_sources
|
||||||
|
@ -344,6 +344,16 @@ class EventsBackend(BaseBackend):
|
|||||||
|
|
||||||
return self.event_buses[name]
|
return self.event_buses[name]
|
||||||
|
|
||||||
|
def list_event_buses(self, name_prefix):
|
||||||
|
if name_prefix:
|
||||||
|
return [
|
||||||
|
event_bus
|
||||||
|
for event_bus in self.event_buses.values()
|
||||||
|
if event_bus.name.startswith(name_prefix)
|
||||||
|
]
|
||||||
|
|
||||||
|
return list(self.event_buses.values())
|
||||||
|
|
||||||
|
|
||||||
available_regions = boto3.session.Session().get_available_regions("events")
|
available_regions = boto3.session.Session().get_available_regions("events")
|
||||||
events_backends = {region: EventsBackend(region) for region in available_regions}
|
events_backends = {region: EventsBackend(region) for region in available_regions}
|
||||||
|
@ -278,3 +278,21 @@ class EventsHandler(BaseResponse):
|
|||||||
event_bus = self.events_backend.create_event_bus(name, event_source_name)
|
event_bus = self.events_backend.create_event_bus(name, event_source_name)
|
||||||
|
|
||||||
return json.dumps({"EventBusArn": event_bus.arn}), self.response_headers
|
return json.dumps({"EventBusArn": event_bus.arn}), self.response_headers
|
||||||
|
|
||||||
|
def list_event_buses(self):
|
||||||
|
name_prefix = self._get_param("NamePrefix")
|
||||||
|
# ToDo: add 'NextToken' & 'Limit' parameters
|
||||||
|
|
||||||
|
response = []
|
||||||
|
for event_bus in self.events_backend.list_event_buses(name_prefix):
|
||||||
|
event_bus_response = {
|
||||||
|
"Name": event_bus.name,
|
||||||
|
"Arn": event_bus.arn,
|
||||||
|
}
|
||||||
|
|
||||||
|
if event_bus.policy:
|
||||||
|
event_bus_response["Policy"] = event_bus.policy
|
||||||
|
|
||||||
|
response.append(event_bus_response)
|
||||||
|
|
||||||
|
return json.dumps({"EventBuses": response}), self.response_headers
|
||||||
|
@ -213,14 +213,14 @@ def test_put_permission_errors():
|
|||||||
client.put_permission.when.called_with(
|
client.put_permission.when.called_with(
|
||||||
EventBusName="non-existing",
|
EventBusName="non-existing",
|
||||||
Action="events:PutEvents",
|
Action="events:PutEvents",
|
||||||
Principal="762054135200",
|
Principal="111111111111",
|
||||||
StatementId="test",
|
StatementId="test",
|
||||||
).should.throw(ClientError, "Event bus non-existing does not exist.")
|
).should.throw(ClientError, "Event bus non-existing does not exist.")
|
||||||
|
|
||||||
client.put_permission.when.called_with(
|
client.put_permission.when.called_with(
|
||||||
EventBusName="test-bus",
|
EventBusName="test-bus",
|
||||||
Action="events:PutPermission",
|
Action="events:PutPermission",
|
||||||
Principal="762054135200",
|
Principal="111111111111",
|
||||||
StatementId="test",
|
StatementId="test",
|
||||||
).should.throw(
|
).should.throw(
|
||||||
ClientError, "Provided value in parameter 'action' is not supported."
|
ClientError, "Provided value in parameter 'action' is not supported."
|
||||||
@ -243,7 +243,7 @@ def test_remove_permission_errors():
|
|||||||
client.put_permission(
|
client.put_permission(
|
||||||
EventBusName="test-bus",
|
EventBusName="test-bus",
|
||||||
Action="events:PutEvents",
|
Action="events:PutEvents",
|
||||||
Principal="762054135200",
|
Principal="111111111111",
|
||||||
StatementId="test",
|
StatementId="test",
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -322,7 +322,7 @@ def test_describe_event_bus():
|
|||||||
client.put_permission(
|
client.put_permission(
|
||||||
EventBusName="test-bus",
|
EventBusName="test-bus",
|
||||||
Action="events:PutEvents",
|
Action="events:PutEvents",
|
||||||
Principal="762054135200",
|
Principal="111111111111",
|
||||||
StatementId="test",
|
StatementId="test",
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -339,7 +339,7 @@ def test_describe_event_bus():
|
|||||||
{
|
{
|
||||||
"Sid": "test",
|
"Sid": "test",
|
||||||
"Effect": "Allow",
|
"Effect": "Allow",
|
||||||
"Principal": {"AWS": "arn:aws:iam::762054135200:root"},
|
"Principal": {"AWS": "arn:aws:iam::111111111111:root"},
|
||||||
"Action": "events:PutEvents",
|
"Action": "events:PutEvents",
|
||||||
"Resource": "arn:aws:events:us-east-1:123456789012:event-bus/test-bus",
|
"Resource": "arn:aws:events:us-east-1:123456789012:event-bus/test-bus",
|
||||||
}
|
}
|
||||||
@ -355,3 +355,63 @@ def test_describe_event_bus_errors():
|
|||||||
client.describe_event_bus.when.called_with(Name="non-existing").should.throw(
|
client.describe_event_bus.when.called_with(Name="non-existing").should.throw(
|
||||||
ClientError, "Event bus non-existing does not exist."
|
ClientError, "Event bus non-existing does not exist."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@mock_events
|
||||||
|
def test_list_event_buses():
|
||||||
|
client = boto3.client("events", "us-east-1")
|
||||||
|
client.create_event_bus(Name="test-bus-1")
|
||||||
|
client.put_permission(
|
||||||
|
EventBusName="test-bus-1",
|
||||||
|
Action="events:PutEvents",
|
||||||
|
Principal="111111111111",
|
||||||
|
StatementId="test",
|
||||||
|
)
|
||||||
|
client.create_event_bus(Name="test-bus-2")
|
||||||
|
client.create_event_bus(Name="other-bus-1")
|
||||||
|
client.create_event_bus(Name="other-bus-2")
|
||||||
|
|
||||||
|
response = client.list_event_buses()
|
||||||
|
|
||||||
|
response["EventBuses"].should.have.length_of(5)
|
||||||
|
sorted(response["EventBuses"], key=lambda i: i["Name"]).should.equal(
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"Name": "default",
|
||||||
|
"Arn": "arn:aws:events:us-east-1:123456789012:event-bus/default",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "other-bus-1",
|
||||||
|
"Arn": "arn:aws:events:us-east-1:123456789012:event-bus/other-bus-1",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "other-bus-2",
|
||||||
|
"Arn": "arn:aws:events:us-east-1:123456789012:event-bus/other-bus-2",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "test-bus-1",
|
||||||
|
"Arn": "arn:aws:events:us-east-1:123456789012:event-bus/test-bus-1",
|
||||||
|
"Policy": '{"Version": "2012-10-17", "Statement": [{"Sid": "test", "Effect": "Allow", "Principal": {"AWS": "arn:aws:iam::111111111111:root"}, "Action": "events:PutEvents", "Resource": "arn:aws:events:us-east-1:123456789012:event-bus/test-bus-1"}]}',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "test-bus-2",
|
||||||
|
"Arn": "arn:aws:events:us-east-1:123456789012:event-bus/test-bus-2",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
response = client.list_event_buses(NamePrefix="other-bus")
|
||||||
|
|
||||||
|
response["EventBuses"].should.have.length_of(2)
|
||||||
|
response["EventBuses"].should.equal(
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"Name": "other-bus-1",
|
||||||
|
"Arn": "arn:aws:events:us-east-1:123456789012:event-bus/other-bus-1",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "other-bus-2",
|
||||||
|
"Arn": "arn:aws:events:us-east-1:123456789012:event-bus/other-bus-2",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user