EC2: add GroupId to SecurityGroupRules (#6437)
This commit is contained in:
parent
8ba1a61424
commit
3f528f5428
@ -550,16 +550,19 @@ class SecurityGroupBackend:
|
|||||||
|
|
||||||
def describe_security_group_rules(
|
def describe_security_group_rules(
|
||||||
self, group_ids: Optional[List[str]] = None, filters: Any = None
|
self, group_ids: Optional[List[str]] = None, filters: Any = None
|
||||||
) -> List[SecurityRule]:
|
) -> Dict[str, List[SecurityRule]]:
|
||||||
matches = self.describe_security_groups(group_ids=group_ids, filters=filters)
|
matches = self.describe_security_groups(group_ids=group_ids, 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."
|
||||||
)
|
)
|
||||||
rules = []
|
rules = {}
|
||||||
for group in matches:
|
for group in matches:
|
||||||
rules.extend(group.ingress_rules)
|
group_rules = []
|
||||||
rules.extend(group.egress_rules)
|
group_rules.extend(group.ingress_rules)
|
||||||
|
group_rules.extend(group.egress_rules)
|
||||||
|
if group_rules:
|
||||||
|
rules[group.group_id] = group_rules
|
||||||
|
|
||||||
return rules
|
return rules
|
||||||
|
|
||||||
|
@ -254,22 +254,25 @@ DESCRIBE_SECURITY_GROUP_RULES_RESPONSE = """
|
|||||||
<DescribeSecurityGroupRulesResponse xmlns="http://ec2.amazonaws.com/doc/2016-11-15/">
|
<DescribeSecurityGroupRulesResponse xmlns="http://ec2.amazonaws.com/doc/2016-11-15/">
|
||||||
<requestId>{{ request_id }}</requestId>
|
<requestId>{{ request_id }}</requestId>
|
||||||
<securityGroupRuleSet>
|
<securityGroupRuleSet>
|
||||||
{% for rule in rules %}
|
{% for group, rule_list in rules.items() %}
|
||||||
<item>
|
{% for rule in rule_list %}
|
||||||
{% if rule.from_port is not none %}
|
<item>
|
||||||
<fromPort>{{ rule.from_port }}</fromPort>
|
{% if rule.from_port is not none %}
|
||||||
{% endif %}
|
<fromPort>{{ rule.from_port }}</fromPort>
|
||||||
{% if rule.to_port is not none %}
|
{% endif %}
|
||||||
<toPort>{{ rule.to_port }}</toPort>
|
{% if rule.to_port is not none %}
|
||||||
{% endif %}
|
<toPort>{{ rule.to_port }}</toPort>
|
||||||
{% if rule.ip_ranges %}
|
{% endif %}
|
||||||
<cidrIpv4>{{ rule.ip_ranges[0]['CidrIp'] }}</cidrIpv4>
|
{% if rule.ip_ranges %}
|
||||||
{% endif %}
|
<cidrIpv4>{{ rule.ip_ranges[0]['CidrIp'] }}</cidrIpv4>
|
||||||
<ipProtocol>{{ rule.ip_protocol }}</ipProtocol>
|
{% endif %}
|
||||||
<groupOwnerId>{{ rule.owner_id }}</groupOwnerId>
|
<ipProtocol>{{ rule.ip_protocol }}</ipProtocol>
|
||||||
<isEgress>{{ 'true' if rule.is_egress else 'false' }}</isEgress>
|
<groupId>{{ group }}</groupId>
|
||||||
<securityGroupRuleId>{{ rule.id }}</securityGroupRuleId>
|
<groupOwnerId>{{ rule.owner_id }}</groupOwnerId>
|
||||||
</item>
|
<isEgress>{{ 'true' if rule.is_egress else 'false' }}</isEgress>
|
||||||
|
<securityGroupRuleId>{{ rule.id }}</securityGroupRuleId>
|
||||||
|
</item>
|
||||||
|
{% endfor %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</securityGroupRuleSet>
|
</securityGroupRuleSet>
|
||||||
</DescribeSecurityGroupRulesResponse>"""
|
</DescribeSecurityGroupRulesResponse>"""
|
||||||
|
@ -586,6 +586,7 @@ def test_create_and_describe_security_grp_rule():
|
|||||||
assert rules[0]["IsEgress"] is True
|
assert rules[0]["IsEgress"] is True
|
||||||
assert rules[0]["IpProtocol"] == "-1"
|
assert rules[0]["IpProtocol"] == "-1"
|
||||||
assert rules[0]["CidrIpv4"] == "0.0.0.0/0"
|
assert rules[0]["CidrIpv4"] == "0.0.0.0/0"
|
||||||
|
assert "GroupId" in rules[0]
|
||||||
|
|
||||||
|
|
||||||
@mock_ec2
|
@mock_ec2
|
||||||
|
Loading…
x
Reference in New Issue
Block a user