EC2: Simplify describe_sg_rules() logic (#5875)
This commit is contained in:
parent
4700c3efea
commit
6d41ad72e0
@ -521,14 +521,7 @@ class SecurityGroupBackend:
|
|||||||
return matches
|
return matches
|
||||||
|
|
||||||
def describe_security_group_rules(self, group_ids=None, filters=None):
|
def describe_security_group_rules(self, group_ids=None, filters=None):
|
||||||
matches = itertools.chain(*[x.copy().values() for x in self.groups.values()])
|
matches = self.describe_security_groups(group_ids=group_ids, filters=filters)
|
||||||
if group_ids:
|
|
||||||
matches = [grp for grp in matches if grp.id in group_ids]
|
|
||||||
if len(group_ids) > len(matches):
|
|
||||||
unknown_ids = set(group_ids) - set(matches)
|
|
||||||
raise InvalidSecurityGroupNotFoundError(unknown_ids)
|
|
||||||
if filters:
|
|
||||||
matches = [grp for grp in matches if grp.matches_filters(filters)]
|
|
||||||
if not matches:
|
if not matches:
|
||||||
raise InvalidSecurityGroupNotFoundError(
|
raise InvalidSecurityGroupNotFoundError(
|
||||||
"No security groups found matching the filters provided."
|
"No security groups found matching the filters provided."
|
||||||
|
@ -259,7 +259,9 @@ DESCRIBE_SECURITY_GROUP_RULES_RESPONSE = """
|
|||||||
{% if rule.to_port is not none %}
|
{% if rule.to_port is not none %}
|
||||||
<toPort>{{ rule.to_port }}</toPort>
|
<toPort>{{ rule.to_port }}</toPort>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if rule.ip_ranges %}
|
||||||
<cidrIpv4>{{ rule.ip_ranges[0]['CidrIp'] }}</cidrIpv4>
|
<cidrIpv4>{{ rule.ip_ranges[0]['CidrIp'] }}</cidrIpv4>
|
||||||
|
{% endif %}
|
||||||
<ipProtocol>{{ rule.ip_protocol }}</ipProtocol>
|
<ipProtocol>{{ rule.ip_protocol }}</ipProtocol>
|
||||||
<groupOwnerId>{{ rule.owner_id }}</groupOwnerId>
|
<groupOwnerId>{{ rule.owner_id }}</groupOwnerId>
|
||||||
<isEgress>true</isEgress>
|
<isEgress>true</isEgress>
|
||||||
|
Loading…
Reference in New Issue
Block a user