Skip to content

Commit

Permalink
Merge pull request #535 from robpickerill/vpc-sgs
Browse files Browse the repository at this point in the history
only query sgs owned by the account
  • Loading branch information
jantman authored Jul 8, 2021
2 parents ce37447 + ed89958 commit 170b400
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 3 additions & 1 deletion awslimitchecker/services/ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,9 @@ def _find_usage_networking_sgs(self):
logger.debug("Getting usage for EC2 VPC resources")
sg_count = 0
rules_per_sg = defaultdict(int)
for sg in self.resource_conn.security_groups.all():
for sg in self.resource_conn.security_groups.filter(
owner_id=self.current_account_id
):
if sg.vpc_id is None:
continue
sg_count += 1
Expand Down
5 changes: 3 additions & 2 deletions awslimitchecker/tests/services/test_ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,9 +767,10 @@ def test_simple(self):
mocks = fixtures.test_find_usage_networking_sgs

mock_conn = Mock()
mock_conn.security_groups.all.return_value = mocks
mock_conn.security_groups.filter.return_value = mocks

cls = _Ec2Service(21, 43, {}, None)
cls._current_account_id = "1234567890"
cls.resource_conn = mock_conn

with patch('awslimitchecker.services.ec2.logger') as mock_logger:
Expand Down Expand Up @@ -802,7 +803,7 @@ def test_simple(self):
# egress: IPv4 = 22; IPv6 = 29
assert sorted_usage[2].get_value() == 29
assert mock_conn.mock_calls == [
call.security_groups.all()
call.security_groups.filter(owner_id='1234567890')
]


Expand Down

0 comments on commit 170b400

Please sign in to comment.