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(
|
||||
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)
|
||||
if not matches:
|
||||
raise InvalidSecurityGroupNotFoundError(
|
||||
"No security groups found matching the filters provided."
|
||||
)
|
||||
rules = []
|
||||
rules = {}
|
||||
for group in matches:
|
||||
rules.extend(group.ingress_rules)
|
||||
rules.extend(group.egress_rules)
|
||||
group_rules = []
|
||||
group_rules.extend(group.ingress_rules)
|
||||
group_rules.extend(group.egress_rules)
|
||||
if group_rules:
|
||||
rules[group.group_id] = group_rules
|
||||
|
||||
return rules
|
||||
|
||||
|
@ -254,22 +254,25 @@ DESCRIBE_SECURITY_GROUP_RULES_RESPONSE = """
|
||||
<DescribeSecurityGroupRulesResponse xmlns="http://ec2.amazonaws.com/doc/2016-11-15/">
|
||||
<requestId>{{ request_id }}</requestId>
|
||||
<securityGroupRuleSet>
|
||||
{% for rule in rules %}
|
||||
<item>
|
||||
{% if rule.from_port is not none %}
|
||||
<fromPort>{{ rule.from_port }}</fromPort>
|
||||
{% endif %}
|
||||
{% if rule.to_port is not none %}
|
||||
<toPort>{{ rule.to_port }}</toPort>
|
||||
{% endif %}
|
||||
{% if rule.ip_ranges %}
|
||||
<cidrIpv4>{{ rule.ip_ranges[0]['CidrIp'] }}</cidrIpv4>
|
||||
{% endif %}
|
||||
<ipProtocol>{{ rule.ip_protocol }}</ipProtocol>
|
||||
<groupOwnerId>{{ rule.owner_id }}</groupOwnerId>
|
||||
<isEgress>{{ 'true' if rule.is_egress else 'false' }}</isEgress>
|
||||
<securityGroupRuleId>{{ rule.id }}</securityGroupRuleId>
|
||||
</item>
|
||||
{% for group, rule_list in rules.items() %}
|
||||
{% for rule in rule_list %}
|
||||
<item>
|
||||
{% if rule.from_port is not none %}
|
||||
<fromPort>{{ rule.from_port }}</fromPort>
|
||||
{% endif %}
|
||||
{% if rule.to_port is not none %}
|
||||
<toPort>{{ rule.to_port }}</toPort>
|
||||
{% endif %}
|
||||
{% if rule.ip_ranges %}
|
||||
<cidrIpv4>{{ rule.ip_ranges[0]['CidrIp'] }}</cidrIpv4>
|
||||
{% endif %}
|
||||
<ipProtocol>{{ rule.ip_protocol }}</ipProtocol>
|
||||
<groupId>{{ group }}</groupId>
|
||||
<groupOwnerId>{{ rule.owner_id }}</groupOwnerId>
|
||||
<isEgress>{{ 'true' if rule.is_egress else 'false' }}</isEgress>
|
||||
<securityGroupRuleId>{{ rule.id }}</securityGroupRuleId>
|
||||
</item>
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
</securityGroupRuleSet>
|
||||
</DescribeSecurityGroupRulesResponse>"""
|
||||
|
@ -586,6 +586,7 @@ def test_create_and_describe_security_grp_rule():
|
||||
assert rules[0]["IsEgress"] is True
|
||||
assert rules[0]["IpProtocol"] == "-1"
|
||||
assert rules[0]["CidrIpv4"] == "0.0.0.0/0"
|
||||
assert "GroupId" in rules[0]
|
||||
|
||||
|
||||
@mock_ec2
|
||||
|
Loading…
x
Reference in New Issue
Block a user